1c5c2eed7Sopenharmony_ci/* 2c5c2eed7Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3c5c2eed7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c5c2eed7Sopenharmony_ci * you may not use this file except in compliance with the License. 5c5c2eed7Sopenharmony_ci * You may obtain a copy of the License at 6c5c2eed7Sopenharmony_ci * 7c5c2eed7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c5c2eed7Sopenharmony_ci * 9c5c2eed7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c5c2eed7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c5c2eed7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c5c2eed7Sopenharmony_ci * See the License for the specific language governing permissions and 13c5c2eed7Sopenharmony_ci * limitations under the License. 14c5c2eed7Sopenharmony_ci */ 15c5c2eed7Sopenharmony_ci 16c5c2eed7Sopenharmony_ciimport extension from '@ohos.app.ability.ServiceExtensionAbility'; 17c5c2eed7Sopenharmony_ciimport window from '@ohos.window'; 18c5c2eed7Sopenharmony_ciimport display from '@ohos.display'; 19c5c2eed7Sopenharmony_ciimport { GlobalContext } from '../common/utils/globalContext'; 20c5c2eed7Sopenharmony_ci 21c5c2eed7Sopenharmony_ciconst TAG = 'PermissionManager_Log:'; 22c5c2eed7Sopenharmony_ciconst BG_COLOR = '#00000000'; 23c5c2eed7Sopenharmony_ci 24c5c2eed7Sopenharmony_ciexport default class GlobalExtensionAbility extends extension { 25c5c2eed7Sopenharmony_ci /** 26c5c2eed7Sopenharmony_ci * Lifecycle function, called back when a service extension is started for initialization. 27c5c2eed7Sopenharmony_ci */ 28c5c2eed7Sopenharmony_ci onCreate(want): void { 29c5c2eed7Sopenharmony_ci console.info(TAG + 'ServiceExtensionAbility onCreate, ability name is ' + want.abilityName); 30c5c2eed7Sopenharmony_ci console.info(TAG + 'want: ' + JSON.stringify(want)); 31c5c2eed7Sopenharmony_ci 32c5c2eed7Sopenharmony_ci GlobalContext.store('globalState', want.parameters['ohos.sensitive.resource']); 33c5c2eed7Sopenharmony_ci GlobalContext.store('context', this.context); 34c5c2eed7Sopenharmony_ci 35c5c2eed7Sopenharmony_ci try { 36c5c2eed7Sopenharmony_ci let dis = display.getDefaultDisplaySync(); 37c5c2eed7Sopenharmony_ci let navigationBarRect = { 38c5c2eed7Sopenharmony_ci left: 0, 39c5c2eed7Sopenharmony_ci top: 0, 40c5c2eed7Sopenharmony_ci width: dis.width, 41c5c2eed7Sopenharmony_ci height: dis.height 42c5c2eed7Sopenharmony_ci }; 43c5c2eed7Sopenharmony_ci this.createWindow('globalDialog', window.WindowType.TYPE_VOICE_INTERACTION, navigationBarRect); 44c5c2eed7Sopenharmony_ci } catch (exception) { 45c5c2eed7Sopenharmony_ci console.error(TAG + 'Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); 46c5c2eed7Sopenharmony_ci }; 47c5c2eed7Sopenharmony_ci } 48c5c2eed7Sopenharmony_ci 49c5c2eed7Sopenharmony_ci /** 50c5c2eed7Sopenharmony_ci * Lifecycle function, called back when a service extension is started or recall. 51c5c2eed7Sopenharmony_ci */ 52c5c2eed7Sopenharmony_ci onRequest(want, startId): void { 53c5c2eed7Sopenharmony_ci console.info(TAG + 'ServiceExtensionAbility onRequest. start id is ' + startId); 54c5c2eed7Sopenharmony_ci } 55c5c2eed7Sopenharmony_ci 56c5c2eed7Sopenharmony_ci /** 57c5c2eed7Sopenharmony_ci * Lifecycle function, called back before a service extension is destroyed. 58c5c2eed7Sopenharmony_ci */ 59c5c2eed7Sopenharmony_ci onDestroy(): void { 60c5c2eed7Sopenharmony_ci console.info(TAG + 'ServiceExtensionAbility onDestroy.'); 61c5c2eed7Sopenharmony_ci let win = GlobalContext.load('globalWin'); 62c5c2eed7Sopenharmony_ci win.destroyWindow(); 63c5c2eed7Sopenharmony_ci } 64c5c2eed7Sopenharmony_ci 65c5c2eed7Sopenharmony_ci private async createWindow(name: string, windowType: number, rect): Promise<void> { 66c5c2eed7Sopenharmony_ci console.info(TAG + 'create window'); 67c5c2eed7Sopenharmony_ci try { 68c5c2eed7Sopenharmony_ci const win = await window.createWindow({ ctx: this.context, name, windowType }); 69c5c2eed7Sopenharmony_ci GlobalContext.store('globalWin', win); 70c5c2eed7Sopenharmony_ci await win.moveWindowTo(rect.left, rect.top); 71c5c2eed7Sopenharmony_ci await win.resize(rect.width, rect.height); 72c5c2eed7Sopenharmony_ci await win.setUIContent('pages/globalSwitch'); 73c5c2eed7Sopenharmony_ci win.setWindowBackgroundColor(BG_COLOR); 74c5c2eed7Sopenharmony_ci await win.showWindow(); 75c5c2eed7Sopenharmony_ci } catch { 76c5c2eed7Sopenharmony_ci console.info(TAG + 'window create failed!'); 77c5c2eed7Sopenharmony_ci } 78c5c2eed7Sopenharmony_ci } 79c5c2eed7Sopenharmony_ci};