1/* 2 * Copyright (c) 2024 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 */ 15import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility' 16import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession' 17import Want from '@ohos.app.ability.Want'; 18import deviceInfo from '@ohos.deviceInfo'; 19import { Configuration } from '@ohos.app.ability.Configuration'; 20const TAG: string = '[DeviceManagerUI:Confirm]==>' 21 22export default class ConfirmUIExtAbility extends UIExtensionAbility { 23 onSessionCreate(want: Want, session: UIExtensionContentSession) { 24 console.log(TAG, `UIExtAbility onSessionCreate`) 25 if (want.parameters == undefined) { 26 return; 27 } 28 if (want.parameters.deviceName) { 29 AppStorage.setOrCreate('deviceName', want.parameters.deviceName); 30 } 31 if (want.parameters.appOperationStr) { 32 AppStorage.setOrCreate('appOperationStr', want.parameters.appOperationStr); 33 } 34 if (want.parameters.customDescriptionStr) { 35 AppStorage.setOrCreate('customDescriptionStr', want.parameters.customDescriptionStr); 36 } 37 if (want.parameters.deviceType) { 38 AppStorage.setOrCreate('deviceType', want.parameters.deviceType); 39 } 40 if (want.parameters.hostPkgLabel) { 41 AppStorage.setOrCreate('hostPkgLabel', want.parameters.hostPkgLabel); 42 } 43 if (want.parameters.isProxyBind) { 44 AppStorage.setOrCreate('isProxyBind', want.parameters.isProxyBind); 45 } 46 if (want.parameters.appUserData) { 47 AppStorage.setOrCreate('appUserData', want.parameters.appUserData); 48 } 49 if (want.parameters.title) { 50 AppStorage.setOrCreate('title', want.parameters.title); 51 } 52 53 let param: Record<string, UIExtensionContentSession> = { 54 'session': session 55 } 56 let storage: LocalStorage = new LocalStorage(param); 57 if (deviceInfo.deviceType === 'wearable') { 58 session.loadContent('pages/ConfirmDialogWearable', storage); 59 } else if (deviceInfo.deviceType === 'tv') { 60 session.loadContent('pages/ConfirmDialogTv', storage); 61 } else { 62 session.loadContent('pages/ConfirmDialog', storage); 63 } 64 session.setWindowBackgroundColor('#00000000'); 65 let extensionHostWindow = session.getUIExtensionHostWindowProxy(); 66 extensionHostWindow.hideNonSecureWindows(true); 67 session.setWindowPrivacyMode(true); 68 AppStorage.setOrCreate('ConfirmSession', session); 69 } 70 71 onSessionDestroy(session: UIExtensionContentSession) { 72 let extensionHostWindow = session.getUIExtensionHostWindowProxy(); 73 extensionHostWindow.hideNonSecureWindows(false); 74 console.log(TAG, `UIExtAbility onSessionDestroy`) 75 } 76 77 onConfigurationUpdate(newConfig: Configuration): void { 78 AppStorage.setOrCreate('fontSizeScale', newConfig.fontSizeScale); 79 console.info('test_log', `onConfigurationUpdate fontSizeScale: ${newConfig.fontSizeScale}`); 80 } 81} 82