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'; 19const TAG: string = '[DeviceManagerUI:Confirm]==>' 20 21export default class ConfirmUIExtAbility extends UIExtensionAbility { 22 onSessionCreate(want: Want, session: UIExtensionContentSession) { 23 console.log(TAG, `UIExtAbility onSessionCreate`) 24 if (want.parameters == undefined) { 25 return; 26 } 27 if (want.parameters.deviceName) { 28 AppStorage.setOrCreate('deviceName', want.parameters.deviceName); 29 } 30 if (want.parameters.appOperationStr) { 31 AppStorage.setOrCreate('appOperationStr', want.parameters.appOperationStr); 32 } 33 if (want.parameters.customDescriptionStr) { 34 AppStorage.setOrCreate('customDescriptionStr', want.parameters.customDescriptionStr); 35 } 36 if (want.parameters.deviceType) { 37 AppStorage.setOrCreate('deviceType', want.parameters.deviceType); 38 } 39 if (want.parameters.hostPkgLabel) { 40 AppStorage.setOrCreate('hostPkgLabel', want.parameters.hostPkgLabel); 41 } 42 43 let param: Record<string, UIExtensionContentSession> = { 44 'session': session 45 } 46 let storage: LocalStorage = new LocalStorage(param); 47 if (deviceInfo.deviceType === 'wearable') { 48 session.loadContent('pages/ConfirmDialogWearable', storage); 49 } else { 50 session.loadContent('pages/ConfirmDialog', storage); 51 } 52 session.setWindowBackgroundColor('#00000000'); 53 let extensionHostWindow = session.getUIExtensionHostWindowProxy(); 54 extensionHostWindow.hideNonSecureWindows(true); 55 AppStorage.setOrCreate('ConfirmSession', session); 56 } 57 58 onSessionDestroy(session: UIExtensionContentSession) { 59 let extensionHostWindow = session.getUIExtensionHostWindowProxy(); 60 extensionHostWindow.hideNonSecureWindows(false); 61 console.log(TAG, `UIExtAbility onSessionDestroy`) 62 } 63} 64