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