1/* 2 * Copyright (c) 2025 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; 17import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 18import Want from '@ohos.app.ability.Want'; 19import type { BusinessError } from '@ohos.base'; 20 21const TAG: string = '[BT_PC_RECEIVE_UI]==>' 22 23export default class BluetoothReceiveServiceUIAbility extends UIExtensionAbility { 24 onSessionCreate(want: Want, session: UIExtensionContentSession) { 25 if (want.parameters == undefined) { 26 return; 27 } 28 29 let fileUri:string = want.parameters?.['fileUri'] as string; 30 if (fileUri != undefined && fileUri != '') { 31 this.startAbility(fileUri, want); 32 return; 33 } 34 35 let fileName:string = want.parameters?.['fileName'] as string; 36 if (fileName != undefined && fileName != '') { 37 AppStorage.setOrCreate('fileName', fileName); 38 } 39 40 let param: Record<string, UIExtensionContentSession> = { 41 'session': session 42 } 43 let storage: LocalStorage = new LocalStorage(param); 44 session.loadContent('pages/BluetoothPcReceive', storage); 45 session.setWindowBackgroundColor('#00000000'); 46 AppStorage.setOrCreate('ConfirmSession', session); 47 } 48 49 onSessionDestroy(session: UIExtensionContentSession) { 50 console.info(TAG, `BluetoothReceiveServiceUIAbility onSessionDestroy`); 51 } 52 53 startAbility(fileUri: string, want: Want) { 54 console.info(TAG, `startAbility begin.`); 55 let bundleName : string = want.parameters?.['bundleName'] as string; 56 let abilityName : string = want.parameters?.['abilityName'] as string; 57 if (bundleName == undefined || abilityName == undefined) { 58 console.error(TAG, `undefined params`); 59 return; 60 } 61 this.startFileManagerAbility(fileUri, bundleName, abilityName); 62 return; 63 } 64 65 startFileManagerAbility(fileUri: string, bundleName: string, abilityName: string) { 66 console.info(TAG, `startFileManagerAbility bundleName ` + bundleName + ` abilityName ` + abilityName); 67 let want: Want = { 68 bundleName: bundleName, 69 abilityName: abilityName, 70 parameters: { 71 'fileUri': fileUri 72 } 73 }; 74 this.context.startAbility(want).then(() => { 75 console.info(TAG, `startFileManagerAbility successfully and terminateSelf`); 76 this.context.terminateSelf(); 77 }).catch((err: BusinessError) => { 78 console.error(TAG, `startFileManagerAbility failed, code is ${err.code}, message is ${err.message}`); 79 this.context.terminateSelf(); 80 }); 81 } 82}