1/* 2 * Copyright (c) 2024-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 fs from '@ohos.file.fs'; 17import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility'; 18import keyboardController1 from './model/KeyboardController1'; 19import Want from '@ohos.app.ability.Want'; 20import { logger } from '../utils/Logger'; 21 22export default class InputDemo2Service extends InputMethodExtensionAbility { 23 onCreate(want: Want): void { 24 keyboardController1.onCreate(this.context); // 初始化窗口并注册对输入法框架的事件监听 25 let filesDir = this.context.filesDir; 26 let filesDir2 = this.context.getApplicationContext().filesDir; 27 let file3 = fs.openSync(filesDir + '/inputtest3.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); 28 let file4 = fs.openSync(filesDir2 + '/inputtest4.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); 29 30 //预期结果,无法读写 31 try { 32 fs.openSync(filesDir + '/inputtest1.txt', fs.OpenMode.READ_WRITE); 33 } catch (e) { 34 logger.error(`input openSync module err: ${JSON.stringify(e)}`); 35 } 36 37 //预期结果,无法读写 38 try { 39 fs.openSync(filesDir2 + '/inputtest2.txt', fs.OpenMode.READ_WRITE); 40 } catch (e) { 41 logger.error(`input openSync app err: ${JSON.stringify(e)}`); 42 } 43 } 44 45 onDestroy(): void { 46 keyboardController1.onDestroy(); // 销毁窗口并去注册事件监听 47 } 48}