[sample]Extension&DataGroup的Sample
Signed-off-by: zhu-bingwei123 <zhubingwei@huawei.com>
8
OAT.xml
@ -264,6 +264,14 @@ Note:If the text contains special characters, please escape them according to th
|
||||
<filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/screenshots/device/main.jpeg" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/screenshots/device/showhighQoScomputingTime.jpeg" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Native/NdkQoS/entry/src/main/resources/base/media/icon.png" desc="Provided by code/BasicFeature/Native/NdkNativeQoS"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Extension/Contexttest/entry/src/main/resources/base/media/icon.png" desc="Provided by code/BasicFeature/Extension/Contexttest"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Extension/Contexttest/entry/src/main/resources/base/media/startIcon.png" desc="Provided by code/BasicFeature/Extension/Contexttest"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Extension/Contexttest/screenshots/extension1.jpeg" desc="Provided by code/BasicFeature/Extension/Contexttest"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Extension/Contexttest/screenshots/extension2.jpeg" desc="Provided by code/BasicFeature/Extension/Contexttest"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Extension/Contexttest/screenshots/extension3.jpeg" desc="Provided by code/BasicFeature/Extension/Contexttest"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Extension/Contexttest/entry/src/ohosTest/resources/base/media/icon.png" desc="Provided by code/BasicFeature/Extension/Contexttest"/>
|
||||
<filteritem type="filepath" name="code/BasicFeature/Extension/Contexttest/AppScope/resources/base/media/app_icon.png" desc="Provided by code/BasicFeature/Extension/Contexttest"/>
|
||||
|
||||
<filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/resources/base/media/icon.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/>
|
||||
<filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/media/startIcon.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/>
|
||||
<filteritem type="filepath" name="code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/media/background.png" desc="Provided by code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo"/>
|
||||
|
25
code/BasicFeature/Extension/Contexttest/AppScope/app.json5
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.example.contexttest",
|
||||
"vendor": "example",
|
||||
"versionCode": 1000000,
|
||||
"versionName": "1.0.0",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:app_name"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "contexttest"
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 2.0 KiB |
96
code/BasicFeature/Extension/Contexttest/README_zh.md
Normal file
@ -0,0 +1,96 @@
|
||||
# extension示例
|
||||
|
||||
## 介绍
|
||||
|
||||
本示例实现了一个inputMethod独立extension,并验证独立extension与UIExtension之间的文件共享,实现了以下几点功能:
|
||||
|
||||
1.实现一个inputMethod独立extension:[InputMethodService.ts](./entry/src/main/ets/inputmethodextability1/InputMethodService.ts)。
|
||||
|
||||
2.UIExtension与inputMethod独立extension实现文件共享。
|
||||
|
||||
## 效果预览
|
||||
|
||||
| 首页 | 访问模块级别独立沙箱文件 | 访问应用级别独立沙箱文件 |
|
||||
|--------------------------------------|----------------------------------------|---------------------------------------|
|
||||
| ![Home](screenshots/extension1.jpeg) | ![Module](screenshots/extension2.jpeg) | ![Apply](screenshots/extension3.jpeg) |
|
||||
|
||||
## 使用说明
|
||||
|
||||
1. 启动一个主应用 "hdc shell aa start -a EntryAbility -b
|
||||
com.example.contexttest"。点击前两个按钮,uiAbility分别以dataGroupId为"
|
||||
test1"、"test2"产生的共享目录下创建共享文件,创建成功后会有创建成功弹框提示,创建失败会有创建失败弹框提示;
|
||||
|
||||
2. 启动一个inputMethod独立extension应用: "hdc shell aa start -a
|
||||
inputMethod -b com.example.contexttest",inputMethod可在dataGroupId为"test1"
|
||||
产生的共享目录下修改共享文件,修改成功查看打印相关日志:1:the content of file:1:inputMethod Try to write str.,修改失败查看相关打印日志:1:fs.openSync err: {"code":13900002};在dataGroupId为"
|
||||
test2"产生的共享目录下修改共享文件,修改成功查看打印相关日志:2:the content of file:2:inputMethod Try to write str.,修改失败查看相关打印日志:2:fs.openSync err: {"code":13900002};
|
||||
|
||||
3. 点击第三个按钮,UIAbility访问inputMethod module级别的独立extension的沙箱文件,访问成功会有访问成功弹框提示;访问失败会有访问失败弹框提示且页面的message更新为moduleFailed;预期结果访问失败,证明inputMethod是独立沙箱;
|
||||
|
||||
4. 点击第四个按钮,UIAbility访问inputMethod应用级别的独立extension的沙箱文件,访问成功会有访问成功弹框提示;访问失败会有访问失败弹框提示且页面的message更新为appFailed;预期结果访问失败,证明inputMethod是独立沙箱;
|
||||
|
||||
## 工程目录
|
||||
|
||||
```
|
||||
entry/src/main/ets/
|
||||
|---entryability
|
||||
|---inputMethodextability
|
||||
|---pages
|
||||
|---inputMethodService.ts //input独立extension
|
||||
|---pages
|
||||
| |---Index.ets // 首页
|
||||
entry/src/ohosTest/ets/
|
||||
|---test
|
||||
| |---Ability.test.ets // xts用例
|
||||
|
||||
```
|
||||
|
||||
## 具体实现
|
||||
|
||||
* 示例分为两个方面
|
||||
|
||||
* inputMethod独立extension与UIExtension实现共享目录下文件共享:
|
||||
* 使用getGroupDir接口,创建共享目录下的共享文件,dataGroupId相同的共享目录下的共享文件可以实现文件共享,反之不能实现共享。
|
||||
* 源码参考:[Index.ets](./entry/src/main/ets/pages/Index.ets),[InputMethodService.ts](./entry/src/main/ets/inputmethodextability1/InputMethodService.ts)
|
||||
* 接口参考:[context.d](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-context.md)
|
||||
|
||||
* inputMethod独立extension访问其独立沙箱文件且能正常操作文件,另外的应用不能访问其沙箱文件:
|
||||
* 使用openSync、writeSync、closeSync等接口实现对沙箱文件的创建、读、写等操作。
|
||||
* 源码参考:[Index.ets](./entry/src/main/ets/pages/Index.ets),[InputMethodService.ts](./entry/src/main/ets/inputmethodextability1/InputMethodService.ts)
|
||||
* 接口参考:[@ohos.file.fs.d](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-fileio.md)
|
||||
|
||||
## 相关权限
|
||||
|
||||
不涉及。
|
||||
|
||||
## 依赖
|
||||
|
||||
不涉及。
|
||||
|
||||
## 约束与限制
|
||||
|
||||
1.本示例仅支持标准系统上运行,支持设备:RK3568。
|
||||
|
||||
2.本示例为Stage模型,支持API12版本SDK,SDK版本号(API Version 12 Release),镜像版本号(5.0.0.20)。
|
||||
|
||||
3.本示例需要使用DevEco Studio 版本号(4.1.0.400)及以上版本才可编译运行。
|
||||
|
||||
4.本示例需要使用Full SDK编译。使用Full SDK时需要手动从镜像站点获取,并在DevEco
|
||||
Studio中替换,具体操作可参考[替换指南](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/faqs/full-sdk-switch-guide.md)。
|
||||
|
||||
5.本实例需要用到相同dataGroupId实现共享文件,所以需要在签名证书UnsgnedReleasedProfileTemplate.json中添加配置如"
|
||||
data-group-ids":["test1","test2","test3"],同时需要在module.json5中的extensionAbilities中添加配置如:"
|
||||
dataGroupIds": ["test1"]
|
||||
,只有当前extension和应用配置相同dataGroupId,才可以和应用共享这一个dataGroupId生成的目录。具体操作指南可参考[HarmonyAppProvision配置文件说明](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/app-provision-structure.md#bundle-info%E5%AF%B9%E8%B1%A1%E5%86%85%E9%83%A8%E7%BB%93%E6%9E%84)。
|
||||
|
||||
## 下载
|
||||
|
||||
如需单独下载本工程,执行如下命令:
|
||||
|
||||
```
|
||||
git init
|
||||
git config core.sparsecheckout true
|
||||
echo code/BasicFeature/Extension/Contexttest/ > .git/info/sparse-checkout
|
||||
git remote add origin https://gitee.com/openharmony/applications_app_samples.git
|
||||
git pull origin master
|
||||
```
|
50
code/BasicFeature/Extension/Contexttest/build-profile.json5
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{
|
||||
"app": {
|
||||
"signingConfigs": [],
|
||||
"products": [
|
||||
{
|
||||
"compileSdkVersion": 12,
|
||||
"compatibleSdkVersion": 12,
|
||||
"name": "default",
|
||||
"signingConfig": "default",
|
||||
}
|
||||
],
|
||||
"buildModeSet": [
|
||||
{
|
||||
"name": "debug",
|
||||
},
|
||||
{
|
||||
"name": "release"
|
||||
}
|
||||
]
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
"name": "entry",
|
||||
"srcPath": "./entry",
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"applyToProducts": [
|
||||
"default"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
6
code/BasicFeature/Extension/Contexttest/entry/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/node_modules
|
||||
/oh_modules
|
||||
/.preview
|
||||
/build
|
||||
/.cxx
|
||||
/.test
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{
|
||||
"apiType": "stageMode",
|
||||
"buildOption": {
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
},
|
||||
{
|
||||
"name": "ohosTest",
|
||||
}
|
||||
]
|
||||
}
|
21
code/BasicFeature/Extension/Contexttest/entry/hvigorfile.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"license": "",
|
||||
"devDependencies": {},
|
||||
"author": "",
|
||||
"name": "entry",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
||||
import hilog from '@ohos.hilog';
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import window from '@ohos.window';
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
||||
console.log('entryAbility onCreate going');
|
||||
let bundleCodeDir = this.context.bundleCodeDir;
|
||||
// data/sto
|
||||
let bundleCodeDir2 = this.context.getApplicationContext().bundleCodeDir;
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate preferencesDir:' + bundleCodeDir + ' preferencesDir2:' + bundleCodeDir2);
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage): void {
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
|
||||
windowStage.loadContent('pages/Index', (err, data) => {
|
||||
if (err.code) {
|
||||
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
||||
return;
|
||||
}
|
||||
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
// Main window is destroyed, release UI related resources
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
||||
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
// Ability has brought to foreground
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
// Ability has back to background
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import buffer from '@ohos.buffer';
|
||||
import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility';
|
||||
import keyboardController from './model/KeyboardController';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import fs, { ReadOptions } from '@ohos.file.fs';
|
||||
|
||||
export default class InputDemo1Service extends InputMethodExtensionAbility {
|
||||
onCreate(want: Want): void {
|
||||
keyboardController.onCreate(this.context); // 初始化窗口并注册对输入法框架的事件监听
|
||||
let filesDir = this.context.filesDir;
|
||||
let filesDir2 = this.context.getApplicationContext().filesDir;
|
||||
// 创建inputmethod module级别的独立extension的沙箱文件 /entry
|
||||
let file1 = fs.openSync(filesDir + '/inputtest1.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
|
||||
// 写入一段内容至文件
|
||||
let writeLen = fs.writeSync(file1.fd, 'main Try to write str.');
|
||||
console.info('main The length of str is:' + writeLen);
|
||||
// 关闭文件
|
||||
fs.closeSync(file1);
|
||||
// 创建inputmethod应用级别的独立extension的沙箱文件
|
||||
let file2 = fs.openSync(filesDir2 + '/inputtest2.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
|
||||
// 写入一段内容至文件
|
||||
let writeLen2 = fs.writeSync(file2.fd, 'main Try to write str.'); //返回流文件length
|
||||
console.info('main The length of str is:' + writeLen2);
|
||||
// 关闭文件
|
||||
fs.closeSync(file2);
|
||||
|
||||
//预期结果,无法读写
|
||||
try {
|
||||
fs.openSync(filesDir + '/inputtest3.txt', fs.OpenMode.READ_WRITE);
|
||||
} catch (e) {
|
||||
console.log(`input openSync module err: ${JSON.stringify(e)}`);
|
||||
}
|
||||
|
||||
//预期结果,无法读写
|
||||
try {
|
||||
fs.openSync(filesDir2 + '/inputtest4.txt', fs.OpenMode.READ_WRITE);
|
||||
} catch (e) {
|
||||
console.log(`input openSync app err: ${JSON.stringify(e)}`);
|
||||
}
|
||||
|
||||
// inputmethod 访问其配置groupId的宿主应用的共享沙箱 访问成功 用户开启非严格模式 可以读写
|
||||
this.context.getGroupDir("test1", (err, data) => {
|
||||
if (err) {
|
||||
console.error(`1:getGroupDir failed, err: ${JSON.stringify(err)}`);
|
||||
} else {
|
||||
filesDir = data;
|
||||
try {
|
||||
let file = fs.openSync(filesDir + '/groupTest1.txt', fs.OpenMode.READ_WRITE);
|
||||
let writeLen = 0;
|
||||
try {
|
||||
writeLen = fs.writeSync(file.fd, '1:inputMethod Try to write str.');
|
||||
} catch (e) {
|
||||
console.log(`1:fs.writeSync err: ${JSON.stringify(e)}`);
|
||||
}
|
||||
console.info('1:The length of str is:' + writeLen);
|
||||
// 从文件读取一段内容
|
||||
let arrayBuffer = new ArrayBuffer(1024);
|
||||
let readOptions: ReadOptions = {
|
||||
offset: 0,
|
||||
length: arrayBuffer.byteLength
|
||||
};
|
||||
let readLen = fs.readSync(file.fd, arrayBuffer, readOptions);
|
||||
let buf = buffer.from(arrayBuffer, 0, readLen);
|
||||
console.log('1:the content of file:' + buf.toString());
|
||||
// 关闭文件
|
||||
fs.closeSync(file);
|
||||
} catch (e) {
|
||||
console.log(`1:fs.openSync err: ${JSON.stringify(e)}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 访问失败 没有权限
|
||||
this.context.getGroupDir('test2', (err, data) => {
|
||||
if (err) {
|
||||
console.error(`2:getGroupDir failed, err: ${JSON.stringify(err)}`);
|
||||
} else {
|
||||
filesDir = data;
|
||||
try {
|
||||
let file = fs.openSync(filesDir + '/groupTest2.txt', fs.OpenMode.READ_WRITE);
|
||||
let writeLen = 0;
|
||||
try {
|
||||
writeLen = fs.writeSync(file.fd, '2:inputMethod Try to write str.');
|
||||
} catch (e) {
|
||||
console.log(`2:fs.writeSync err: ${JSON.stringify(e)}`);
|
||||
}
|
||||
console.info('2:The length of str is:' + writeLen);
|
||||
// 从文件读取一段内容
|
||||
let arrayBuffer = new ArrayBuffer(1024);
|
||||
let readOptions: ReadOptions = {
|
||||
offset: 0,
|
||||
length: arrayBuffer.byteLength
|
||||
};
|
||||
let readLen = fs.readSync(file.fd, arrayBuffer, readOptions);
|
||||
let buf = buffer.from(arrayBuffer, 0, readLen);
|
||||
console.log('2:the content of file:' + buf.toString());
|
||||
// 关闭文件
|
||||
fs.closeSync(file);
|
||||
} catch (e) {
|
||||
console.log(`2:fs.openSync err: ${JSON.stringify(e)}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
keyboardController.onDestroy(); // 销毁窗口并去注册事件监听
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import display from '@ohos.display';
|
||||
import inputMethodEngine from '@ohos.inputMethodEngine';
|
||||
import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext';
|
||||
|
||||
// 调用输入法框架的getInputMethodAbility方法获取实例,并由此实例调用输入法框架功能接口
|
||||
const inputMethodAbility: inputMethodEngine.InputMethodAbility = inputMethodEngine.getInputMethodAbility();
|
||||
|
||||
export class KeyboardController {
|
||||
private mContext: InputMethodExtensionContext | undefined = undefined; // 保存InputMethodExtensionAbility中的context属性
|
||||
private panel: inputMethodEngine.Panel | undefined = undefined;
|
||||
private textInputClient: inputMethodEngine.InputClient | undefined = undefined;
|
||||
private keyboardController: inputMethodEngine.KeyboardController | undefined = undefined;
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
public onCreate(context: InputMethodExtensionContext): void
|
||||
{
|
||||
this.mContext = context;
|
||||
this.initWindow(); // 初始化窗口
|
||||
this.registerListener(); // 注册对输入法框架的事件监听
|
||||
}
|
||||
|
||||
public onDestroy(): void // 应用生命周期销毁
|
||||
{
|
||||
this.unRegisterListener(); // 去注册事件监听
|
||||
if(this.panel) { // 销毁窗口
|
||||
this.panel.hide();
|
||||
inputMethodAbility.destroyPanel(this.panel);
|
||||
}
|
||||
if(this.mContext) {
|
||||
this.mContext.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public insertText(text: string): void {
|
||||
if(this.textInputClient) {
|
||||
this.textInputClient.insertText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public deleteForward(length: number): void {
|
||||
if(this.textInputClient) {
|
||||
this.textInputClient.deleteForward(length);
|
||||
}
|
||||
}
|
||||
|
||||
private initWindow(): void // 初始化窗口
|
||||
{
|
||||
if(this.mContext === undefined) {
|
||||
return;
|
||||
}
|
||||
let dis = display.getDefaultDisplaySync();
|
||||
let dWidth = dis.width;
|
||||
let dHeight = dis.height;
|
||||
let keyHeightRate = 0.47;
|
||||
let keyHeight = dHeight * keyHeightRate;
|
||||
let nonBarPosition = dHeight - keyHeight;
|
||||
let panelInfo: inputMethodEngine.PanelInfo = {
|
||||
type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
|
||||
flag: inputMethodEngine.PanelFlag.FLG_FIXED
|
||||
};
|
||||
inputMethodAbility.createPanel(this.mContext, panelInfo).then(async (inputPanel: inputMethodEngine.Panel) => {
|
||||
this.panel = inputPanel;
|
||||
if(this.panel) {
|
||||
await this.panel.resize(dWidth, keyHeight);
|
||||
await this.panel.moveTo(0, nonBarPosition);
|
||||
await this.panel.setUiContent('inputmethodextability1/pages/Index');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private registerListener(): void
|
||||
{
|
||||
this.registerInputListener(); // 注册对输入法框架服务的监听
|
||||
// 注册隐藏键盘事件监听等
|
||||
}
|
||||
|
||||
private registerInputListener(): void { // 注册对输入法框架服务的开启及停止事件监听
|
||||
inputMethodAbility.on('inputStart', (kbController, textInputClient) => {
|
||||
this.textInputClient = textInputClient; // 此为输入法客户端实例,由此调用输入法框架提供给输入法应用的功能接口
|
||||
this.keyboardController = kbController;
|
||||
})
|
||||
inputMethodAbility.on('inputStop', () => {
|
||||
this.onDestroy(); // 销毁KeyboardController
|
||||
});
|
||||
}
|
||||
|
||||
private unRegisterListener(): void
|
||||
{
|
||||
inputMethodAbility.off('inputStart');
|
||||
inputMethodAbility.off('inputStop', () => {});
|
||||
}
|
||||
}
|
||||
|
||||
const keyboardController = new KeyboardController();
|
||||
|
||||
export default keyboardController;
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import fs from '@ohos.file.fs';
|
||||
import InputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility';
|
||||
import keyboardController1 from './model/KeyboardController1';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
|
||||
export default class InputDemo2Service extends InputMethodExtensionAbility {
|
||||
onCreate(want: Want): void {
|
||||
keyboardController1.onCreate(this.context); // 初始化窗口并注册对输入法框架的事件监听
|
||||
let filesDir = this.context.filesDir;
|
||||
let filesDir2 = this.context.getApplicationContext().filesDir;
|
||||
let file3 = fs.openSync(filesDir + '/inputtest3.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
|
||||
let file4 = fs.openSync(filesDir2 + '/inputtest4.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
|
||||
|
||||
//预期结果,无法读写
|
||||
try {
|
||||
fs.openSync(filesDir + '/inputtest1.txt', fs.OpenMode.READ_WRITE);
|
||||
} catch (e) {
|
||||
console.log(`input openSync module err: ${JSON.stringify(e)}`);
|
||||
}
|
||||
|
||||
//预期结果,无法读写
|
||||
try {
|
||||
fs.openSync(filesDir2 + '/inputtest2.txt', fs.OpenMode.READ_WRITE);
|
||||
} catch (e) {
|
||||
console.log(`input openSync app err: ${JSON.stringify(e)}`);
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
keyboardController1.onDestroy(); // 销毁窗口并去注册事件监听
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import display from '@ohos.display';
|
||||
import inputMethodEngine from '@ohos.inputMethodEngine';
|
||||
import InputMethodExtensionContext from '@ohos.InputMethodExtensionContext';
|
||||
|
||||
// 调用输入法框架的getInputMethodAbility方法获取实例,并由此实例调用输入法框架功能接口
|
||||
const inputMethodAbility: inputMethodEngine.InputMethodAbility = inputMethodEngine.getInputMethodAbility();
|
||||
|
||||
export class KeyboardController1 {
|
||||
private mContext: InputMethodExtensionContext | undefined = undefined; // 保存InputMethodExtensionAbility中的context属性
|
||||
private panel: inputMethodEngine.Panel | undefined = undefined;
|
||||
private textInputClient: inputMethodEngine.InputClient | undefined = undefined;
|
||||
private keyboardController: inputMethodEngine.KeyboardController | undefined = undefined;
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
public onCreate(context: InputMethodExtensionContext): void
|
||||
{
|
||||
this.mContext = context;
|
||||
this.initWindow(); // 初始化窗口
|
||||
this.registerListener(); // 注册对输入法框架的事件监听
|
||||
}
|
||||
|
||||
public onDestroy(): void // 应用生命周期销毁
|
||||
{
|
||||
this.unRegisterListener(); // 去注册事件监听
|
||||
if(this.panel) { // 销毁窗口
|
||||
this.panel.hide();
|
||||
inputMethodAbility.destroyPanel(this.panel);
|
||||
}
|
||||
if(this.mContext) {
|
||||
this.mContext.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public insertText(text: string): void {
|
||||
if(this.textInputClient) {
|
||||
this.textInputClient.insertText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public deleteForward(length: number): void {
|
||||
if(this.textInputClient) {
|
||||
this.textInputClient.deleteForward(length);
|
||||
}
|
||||
}
|
||||
|
||||
private initWindow(): void // 初始化窗口
|
||||
{
|
||||
if(this.mContext === undefined) {
|
||||
return;
|
||||
}
|
||||
let dis = display.getDefaultDisplaySync();
|
||||
let dWidth = dis.width;
|
||||
let dHeight = dis.height;
|
||||
let keyHeightRate = 0.47;
|
||||
let keyHeight = dHeight * keyHeightRate;
|
||||
let nonBarPosition = dHeight - keyHeight;
|
||||
let panelInfo: inputMethodEngine.PanelInfo = {
|
||||
type: inputMethodEngine.PanelType.SOFT_KEYBOARD,
|
||||
flag: inputMethodEngine.PanelFlag.FLG_FIXED
|
||||
};
|
||||
inputMethodAbility.createPanel(this.mContext, panelInfo).then(async (inputPanel: inputMethodEngine.Panel) => {
|
||||
this.panel = inputPanel;
|
||||
if(this.panel) {
|
||||
await this.panel.resize(dWidth, keyHeight);
|
||||
await this.panel.moveTo(0, nonBarPosition);
|
||||
await this.panel.setUiContent('inputmethodextability2/pages/Index');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private registerListener(): void
|
||||
{
|
||||
this.registerInputListener(); // 注册对输入法框架服务的监听
|
||||
// 注册隐藏键盘事件监听等
|
||||
}
|
||||
|
||||
private registerInputListener(): void { // 注册对输入法框架服务的开启及停止事件监听
|
||||
inputMethodAbility.on('inputStart', (kbController, textInputClient) => {
|
||||
this.textInputClient = textInputClient; // 此为输入法客户端实例,由此调用输入法框架提供给输入法应用的功能接口
|
||||
this.keyboardController = kbController;
|
||||
})
|
||||
inputMethodAbility.on('inputStop', () => {
|
||||
this.onDestroy(); // 销毁KeyboardController
|
||||
});
|
||||
}
|
||||
|
||||
private unRegisterListener(): void
|
||||
{
|
||||
inputMethodAbility.off('inputStart');
|
||||
inputMethodAbility.off('inputStop', () => {});
|
||||
}
|
||||
}
|
||||
|
||||
const keyboardController1 = new KeyboardController1();
|
||||
|
||||
export default keyboardController1;
|
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import buffer from '@ohos.buffer';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import promptAction from '@ohos.promptAction';
|
||||
import fs, { ReadOptions } from '@ohos.file.fs';
|
||||
|
||||
// 获取应用文件路径
|
||||
let context = getContext(this) as common.UIAbilityContext;
|
||||
let filesDir1 = context.filesDir;
|
||||
let filesDir2 = context.getApplicationContext().filesDir;
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State Message: string = 'UIAbility';
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Column() {
|
||||
Text(this.Message)
|
||||
.fontSize(60)
|
||||
.lineHeight(90)
|
||||
.fontWeight(700)
|
||||
.textAlign(TextAlign.Start)
|
||||
.margin({ bottom: 100 })
|
||||
|
||||
Button($r('app.string.SharedFileSuccess'))
|
||||
.onClick(() => {
|
||||
let filesDir = '';
|
||||
try {
|
||||
context.getGroupDir('test1', (err, data) => {
|
||||
if (err) {
|
||||
promptAction.showToast({
|
||||
message: $r('app.string.CreatedFail'),
|
||||
duration: 2000,
|
||||
bottom: 464
|
||||
})
|
||||
console.error(`getGroupDir faile, err: ${JSON.stringify(err)}`);
|
||||
} else {
|
||||
filesDir = data;
|
||||
console.log(`getGroupDir result is: ${JSON.stringify(data)}`);
|
||||
let file = fs.openSync(filesDir + '/groupTest1.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
|
||||
// 写入一段内容至文件
|
||||
let writeLen = fs.writeSync(file.fd, 'Try to write str.');
|
||||
// 从文件读取一段内容
|
||||
let arrayBuffer = new ArrayBuffer(1024);
|
||||
let readOptions: ReadOptions = {
|
||||
offset: 0,
|
||||
length: arrayBuffer.byteLength
|
||||
};
|
||||
let readLen = fs.readSync(file.fd, arrayBuffer, readOptions);
|
||||
//创建新的buffer对象
|
||||
let buf = buffer.from(arrayBuffer, 0, readLen);
|
||||
console.info('the content of file:' + buf.toString());
|
||||
promptAction.showToast({
|
||||
message: $r('app.string.CreatedSuccess'),
|
||||
duration: 2000,
|
||||
bottom: 530
|
||||
})
|
||||
// 关闭文件
|
||||
fs.closeSync(file);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(`getGroupDir err: ${JSON.stringify(e)}`);
|
||||
}
|
||||
})
|
||||
.margin({ bottom: 24 })
|
||||
.height(90)
|
||||
.fontSize(32)
|
||||
.backgroundColor('#007DFF')
|
||||
.fontFamily('HarmonyHeiTi-Medium')
|
||||
.fontWeight(500)
|
||||
.width('90%')
|
||||
|
||||
Button($r('app.string.SharedFileFail'))
|
||||
.onClick(() => {
|
||||
let filesDir = '';
|
||||
try {
|
||||
context.getGroupDir('test2', (err, data) => {
|
||||
if (err) {
|
||||
promptAction.showToast({
|
||||
message: $r('app.string.CreatedFail'),
|
||||
duration: 2000,
|
||||
bottom: 530
|
||||
})
|
||||
console.error(`getGroupDir faile, err: ${JSON.stringify(err)}`);
|
||||
} else {
|
||||
filesDir = data;
|
||||
console.log(`getGroupDir result is: ${JSON.stringify(data)}`);
|
||||
let file = fs.openSync(filesDir + '/groupTest2.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
|
||||
// 写入一段内容至文件
|
||||
let writeLen = fs.writeSync(file.fd, 'Try to write str.');
|
||||
console.info('The length of str is:' + writeLen);
|
||||
// 从文件读取一段内容
|
||||
let arrayBuffer = new ArrayBuffer(1024);
|
||||
let readOptions: ReadOptions = {
|
||||
offset: 0,
|
||||
length: arrayBuffer.byteLength
|
||||
};
|
||||
let readLen = fs.readSync(file.fd, arrayBuffer, readOptions);
|
||||
let buf = buffer.from(arrayBuffer, 0, readLen);
|
||||
console.info('the content of file:' + buf.toString());
|
||||
promptAction.showToast({
|
||||
message: $r('app.string.CreatedSuccess'),
|
||||
duration: 2000,
|
||||
bottom: 530
|
||||
})
|
||||
// 关闭文件
|
||||
fs.closeSync(file);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(`getGroupDir err: ${JSON.stringify(e)}`);
|
||||
}
|
||||
})
|
||||
.margin({ bottom: 24 })
|
||||
.height(90)
|
||||
.fontSize(32)
|
||||
.backgroundColor('#007DFF')
|
||||
.fontFamily('HarmonyHeiTi-Medium')
|
||||
.fontWeight(500)
|
||||
.width('90%')
|
||||
|
||||
// 预期结果 无法读写
|
||||
Button($r('app.string.InterviewModuleExtension'))
|
||||
.onClick(() => {
|
||||
try {
|
||||
fs.openSync(filesDir1 + '/inputtest1.txt', fs.OpenMode.READ_WRITE);
|
||||
promptAction.showToast({
|
||||
message: $r('app.string.AccessSuccess'),
|
||||
duration: 2000,
|
||||
bottom: 530
|
||||
})
|
||||
} catch (e) {
|
||||
promptAction.showToast({
|
||||
message: $r('app.string.AccessFail'),
|
||||
duration: 2000,
|
||||
bottom: 530
|
||||
})
|
||||
console.log(`openSync err: ${JSON.stringify(e)}`);
|
||||
this.Message = 'moduleFailed';
|
||||
}
|
||||
})
|
||||
.margin({ bottom: 24 })
|
||||
.height(90)
|
||||
.fontSize(32)
|
||||
.backgroundColor('#007DFF')
|
||||
.fontFamily('HarmonyHeiTi-Medium')
|
||||
.fontWeight(500)
|
||||
.width('90%')
|
||||
|
||||
// 预期结果 无法读写
|
||||
Button($r('app.string.InterviewApplyExtension'))
|
||||
.onClick(() => {
|
||||
try {
|
||||
fs.openSync(filesDir2 + '/inputtest2.txt', fs.OpenMode.READ_WRITE);
|
||||
promptAction.showToast({
|
||||
message: $r('app.string.AccessSuccess'),
|
||||
duration: 2000,
|
||||
bottom: 530
|
||||
})
|
||||
} catch (e) {
|
||||
promptAction.showToast({
|
||||
message: $r('app.string.AccessFail'),
|
||||
duration: 2000,
|
||||
bottom: 530
|
||||
})
|
||||
console.log(`openSync err: ${JSON.stringify(e)}`);
|
||||
this.Message = 'appFailed';
|
||||
}
|
||||
})
|
||||
.height(90)
|
||||
.fontSize(32)
|
||||
.backgroundColor('#007DFF')
|
||||
.fontFamily('HarmonyHeiTi-Medium')
|
||||
.fontWeight(500)
|
||||
.width('90%')
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.height('100%')
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{
|
||||
"module": {
|
||||
"name": "entry",
|
||||
"type": "entry",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ts",
|
||||
"description": "$string:module_desc",
|
||||
"mainElement": "EntryAbility",
|
||||
"deviceTypes": [
|
||||
"default",
|
||||
"tablet"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ts",
|
||||
"description": "$string:EntryAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:EntryAbility_label",
|
||||
"startWindowIcon": "$media:startIcon",
|
||||
"startWindowBackground": "$color:start_window_background",
|
||||
"exported": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"extensionAbilities": [
|
||||
{
|
||||
"name": "inputMethod",
|
||||
"srcEntry": "./ets/inputmethodextability1/InputMethodService.ts",
|
||||
"description": "$string:ExtensionAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:ExtensionAbility_label",
|
||||
"type": "inputMethod",
|
||||
"exported": true,
|
||||
"dataGroupIds": [
|
||||
"test1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "inputMethod1",
|
||||
"srcEntry": "./ets/inputmethodextability2/InputMethodService.ts",
|
||||
"description": "$string:ExtensionAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:ExtensionAbility_label",
|
||||
"type": "inputMethod",
|
||||
"exported": true,
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "stageContextEntryAbility1_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "stageContextEntryAbility1_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "StageEntryAbility1_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "StageEntryAbility1_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "ExtensionAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "ExtensionAbility_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility1_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility1_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "SharedFileSuccess",
|
||||
"value": "创建\"test1\"共享文件"
|
||||
},
|
||||
{
|
||||
"name": "SharedFileFail",
|
||||
"value": "创建\"test2\"共享文件"
|
||||
},
|
||||
{
|
||||
"name": "InterviewModuleExtension",
|
||||
"value": "访问module级别沙箱文件"
|
||||
},
|
||||
{
|
||||
"name": "InterviewApplyExtension",
|
||||
"value": "访问应用级别沙箱文件"
|
||||
},
|
||||
{
|
||||
"name": "CreatedSuccess",
|
||||
"value": "创建成功"
|
||||
},
|
||||
{
|
||||
"name": "CreatedFail",
|
||||
"value": "创建失败"
|
||||
},
|
||||
{
|
||||
"name": "AccessSuccess",
|
||||
"value": "访问成功"
|
||||
},
|
||||
{
|
||||
"name": "AccessFail",
|
||||
"value": "访问失败"
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 4.2 KiB |
@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "stageContextEntryAbility1_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "stageContextEntryAbility1_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "StageEntryAbility1_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "StageEntryAbility1_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "ExtensionAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "ExtensionAbility_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility1_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility1_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "SharedFileSuccess",
|
||||
"value": "创建\"test1\"共享文件"
|
||||
},
|
||||
{
|
||||
"name": "SharedFileFail",
|
||||
"value": "创建\"test2\"共享文件"
|
||||
},
|
||||
{
|
||||
"name": "InterviewModuleExtension",
|
||||
"value": "访问module级别沙箱文件"
|
||||
},
|
||||
{
|
||||
"name": "InterviewApplyExtension",
|
||||
"value": "访问应用级别沙箱文件"
|
||||
},
|
||||
{
|
||||
"name": "CreatedSuccess",
|
||||
"value": "创建成功"
|
||||
},
|
||||
{
|
||||
"name": "CreatedFail",
|
||||
"value": "创建失败"
|
||||
},
|
||||
{
|
||||
"name": "AccessSuccess",
|
||||
"value": "访问成功"
|
||||
},
|
||||
{
|
||||
"name": "AccessFail",
|
||||
"value": "访问失败"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "模块描述"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "stageContextEntryAbility1_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "stageContextEntryAbility1_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "StageEntryAbility1_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "StageEntryAbility1_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "ExtensionAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "ExtensionAbility_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility1_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility1_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "SharedFileSuccess",
|
||||
"value": "创建\"test1\"共享文件"
|
||||
},
|
||||
{
|
||||
"name": "SharedFileFail",
|
||||
"value": "创建\"test2\"共享文件"
|
||||
},
|
||||
{
|
||||
"name": "InterviewModuleExtension",
|
||||
"value": "访问module级别沙箱文件"
|
||||
},
|
||||
{
|
||||
"name": "InterviewApplyExtension",
|
||||
"value": "访问应用级别沙箱文件"
|
||||
},
|
||||
{
|
||||
"name": "CreatedSuccess",
|
||||
"value": "创建成功"
|
||||
},
|
||||
{
|
||||
"name": "CreatedFail",
|
||||
"value": "创建失败"
|
||||
},
|
||||
{
|
||||
"name": "AccessSuccess",
|
||||
"value": "访问成功"
|
||||
},
|
||||
{
|
||||
"name": "AccessFail",
|
||||
"value": "访问失败"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import { describe, it, expect, beforeAll, beforeEach, afterEach } from '@ohos/hypium';
|
||||
import { Driver, ON } from '@ohos.UiTest'
|
||||
|
||||
const SUBSCRIBE_BUNDLE_NAME = 'com.example.contexttest';
|
||||
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
|
||||
let driver: Driver = Driver.create();
|
||||
let resourceManager = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext().resourceManager;
|
||||
const INPUTSTOP = 'aa stop-service -a inputMethod -b com.example.contexttest';
|
||||
const INPUTONESTOP = 'aa stop-service -a inputMethod1 -b com.example.contexttest';
|
||||
const INPUTSTART = 'aa start -a inputMethod -b com.example.contexttest';
|
||||
|
||||
export default function abilityTest() {
|
||||
describe('ActsAbilityTest', () => {
|
||||
beforeAll(async () => {
|
||||
await abilityDelegator.startAbility({
|
||||
bundleName: SUBSCRIBE_BUNDLE_NAME,
|
||||
abilityName: 'EntryAbility'
|
||||
})
|
||||
await driver.delayMs(1000);
|
||||
})
|
||||
beforeEach(async () => {
|
||||
await abilityDelegator.executeShellCommand('hilog -r')
|
||||
})
|
||||
afterEach(async () => {
|
||||
await abilityDelegator.executeShellCommand(INPUTSTOP)
|
||||
await abilityDelegator.executeShellCommand(INPUTONESTOP)
|
||||
})
|
||||
|
||||
/**
|
||||
* inputmethod访问其配置groupId为test1的宿主应用的共享沙箱成功
|
||||
*/
|
||||
it('Extension_Course_Test_AbilityContext_0100', 0, async (done: Function) => {
|
||||
await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.SharedFileSuccess'))))
|
||||
.then(async (data) => {
|
||||
await data.click();
|
||||
})
|
||||
await driver.delayMs(1000);
|
||||
await abilityDelegator.executeShellCommand(INPUTSTART)
|
||||
.then((data) => {
|
||||
})
|
||||
await driver.delayMs(1000);
|
||||
await abilityDelegator.executeShellCommand("hilog -x | grep '1:inputMethod Try to write str.'")
|
||||
.then((data) => {
|
||||
let std = data.stdResult;
|
||||
let str = (std.split('file:1:')[1].split('str.')[0]) + 'str.';
|
||||
expect(str === 'inputMethod Try to write str.').assertTrue();
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* inputmethod访问其配置groupId为test1的宿主应用的共享沙箱失败
|
||||
*/
|
||||
it('Extension_Course_Test_AbilityContext_0200', 0, async (done: Function) => {
|
||||
await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.SharedFileFail'))))
|
||||
.then(async (data) => {
|
||||
await data.click();
|
||||
})
|
||||
await driver.delayMs(1000);
|
||||
await abilityDelegator.executeShellCommand(INPUTSTART)
|
||||
await driver.delayMs(4000);
|
||||
await abilityDelegator.executeShellCommand('hilog -x | grep 13900002')
|
||||
.then((data) => {
|
||||
let std = data.stdResult;
|
||||
let str = (std.split("139"))[1];
|
||||
let strResult = '139' + str.split('002')[0] + '002';
|
||||
expect(strResult === '13900002').assertTrue();
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* uiability访问inputmethod module级别的独立extension的沙箱文件
|
||||
*/
|
||||
it('Extension_Course_Test_AbilityContext_0300', 0, async (done: Function) => {
|
||||
await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.InterviewModuleExtension'))))
|
||||
.then(async (data) => {
|
||||
await data.click();
|
||||
})
|
||||
await driver.delayMs(1000);
|
||||
await abilityDelegator.executeShellCommand(INPUTSTART)
|
||||
await driver.delayMs(1000);
|
||||
await driver.assertComponentExist(ON.text('moduleFailed')).catch((err: BusinessError) => {
|
||||
expect().assertFailed();
|
||||
})
|
||||
done();
|
||||
})
|
||||
|
||||
/**
|
||||
* uiability访问inputmethod 应用级别的独立extension的沙箱文件
|
||||
*/
|
||||
it('Extension_Course_Test_AbilityContext_0400', 0, async (done: Function) => {
|
||||
await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.InterviewApplyExtension'))))
|
||||
.then(async (data) => {
|
||||
await data.click();
|
||||
})
|
||||
await driver.delayMs(1000);
|
||||
await abilityDelegator.executeShellCommand(INPUTSTART)
|
||||
await driver.delayMs(1000);
|
||||
await driver.assertComponentExist(ON.text('appFailed')).catch((err: BusinessError) => {
|
||||
expect().assertFailed();
|
||||
})
|
||||
done();
|
||||
})
|
||||
})
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import abilityTest from './Ability.test';
|
||||
|
||||
export default function testsuite() {
|
||||
abilityTest();
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
||||
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
|
||||
import hilog from '@ohos.hilog';
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import window from '@ohos.window';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import testsuite from '../test/List.test';
|
||||
import { Hypium } from '@ohos/hypium';
|
||||
|
||||
export default class TestAbility extends UIAbility {
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
|
||||
let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator;
|
||||
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
|
||||
let abilityDelegatorArguments: AbilityDelegatorRegistry.AbilityDelegatorArgs;
|
||||
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
|
||||
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage) {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
|
||||
windowStage.loadContent('testability/pages/Index', (err, data) => {
|
||||
if (err.code) {
|
||||
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
||||
return;
|
||||
}
|
||||
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
|
||||
JSON.stringify(data) ?? '');
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy() {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State message: string = 'Hello World';
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Column() {
|
||||
Text(this.message)
|
||||
.fontSize(50)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.height('100%')
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
|
||||
import hilog from '@ohos.hilog';
|
||||
import TestRunner from '@ohos.application.testRunner';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
|
||||
let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator | undefined = undefined
|
||||
let abilityDelegatorArguments: AbilityDelegatorRegistry.AbilityDelegatorArgs | undefined = undefined
|
||||
|
||||
async function onAbilityCreateCallback() {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
|
||||
}
|
||||
|
||||
async function addAbilityMonitorCallback(err : Error) {
|
||||
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
|
||||
}
|
||||
|
||||
export default class OpenHarmonyTestRunner implements TestRunner {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
onPrepare() {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
|
||||
}
|
||||
|
||||
async onRun() {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
|
||||
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
|
||||
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
|
||||
const bundleName = abilityDelegatorArguments.bundleName;
|
||||
const testAbilityName = 'TestAbility';
|
||||
let lMonitor: AbilityDelegatorRegistry.AbilityMonitor = {
|
||||
abilityName: testAbilityName,
|
||||
onAbilityCreate: onAbilityCreateCallback,
|
||||
};
|
||||
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
|
||||
const want: Want = {
|
||||
bundleName: bundleName,
|
||||
abilityName: testAbilityName
|
||||
};
|
||||
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
|
||||
abilityDelegator.startAbility(want, (err, data) => {
|
||||
hilog.info(0x0000, 'testTag', 'startAbility : err : %{public}s', JSON.stringify(err) ?? '');
|
||||
hilog.info(0x0000, 'testTag', 'startAbility : data : %{public}s',JSON.stringify(data) ?? '');
|
||||
})
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{
|
||||
"module": {
|
||||
"name": "entry_test",
|
||||
"type": "feature",
|
||||
"description": "$string:module_test_desc",
|
||||
"mainElement": "TestAbility",
|
||||
"deviceTypes": [
|
||||
"default",
|
||||
"tablet"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:test_pages",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "TestAbility",
|
||||
"srcEntry": "./ets/testability/TestAbility.ets",
|
||||
"description": "$string:TestAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:TestAbility_label",
|
||||
"exported": true,
|
||||
"startWindowIcon": "$media:icon",
|
||||
"startWindowBackground": "$color:start_window_background",
|
||||
"skills": [
|
||||
{
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
],
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_test_desc",
|
||||
"value": "test ability description"
|
||||
},
|
||||
{
|
||||
"name": "TestAbility_desc",
|
||||
"value": "the test ability"
|
||||
},
|
||||
{
|
||||
"name": "TestAbility_label",
|
||||
"value": "test label"
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"testability/pages/Index"
|
||||
]
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
{
|
||||
"hvigorVersion": "3.2.4",
|
||||
"dependencies": {
|
||||
"@ohos/hvigor-ohos-plugin": "3.2.4"
|
||||
},
|
||||
"execution": {
|
||||
// "daemon": true, /* Enable daemon compilation. Default: true */
|
||||
// "incremental": true, /* Enable incremental compilation. Default: true */
|
||||
// "parallel": true, /* Enable parallel compilation. Default: true */
|
||||
// "typeCheck": false, /* Enable typeCheck. Default: false */
|
||||
},
|
||||
"logging": {
|
||||
// "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
|
||||
},
|
||||
"debugging": {
|
||||
// "stacktrace": false /* Disable stacktrace compilation. Default: false */
|
||||
}
|
||||
}
|
21
code/BasicFeature/Extension/Contexttest/hvigorfile.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { appTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
48
code/BasicFeature/Extension/Contexttest/hvigorw
Normal file
@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Hvigor startup script, version 1.0.0
|
||||
#
|
||||
# Required ENV vars:
|
||||
# ------------------
|
||||
# NODE_HOME - location of a Node home dir
|
||||
# or
|
||||
# Add /usr/local/nodejs/bin to the PATH environment variable
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
HVIGOR_APP_HOME="`pwd -P`"
|
||||
HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
|
||||
warn() {
|
||||
echo ""
|
||||
echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo ""
|
||||
echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
|
||||
}
|
||||
|
||||
fail() {
|
||||
error "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Determine node to start hvigor wrapper script
|
||||
if [ -n "${NODE_HOME}" ];then
|
||||
EXECUTABLE_NODE="${NODE_HOME}/bin/node"
|
||||
if [ ! -x "$EXECUTABLE_NODE" ];then
|
||||
fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed"
|
||||
fi
|
||||
else
|
||||
EXECUTABLE_NODE="node"
|
||||
which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
|
||||
fi
|
||||
|
||||
# Check hvigor wrapper script
|
||||
if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
|
||||
fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
|
||||
fi
|
||||
|
||||
# start hvigor-wrapper script
|
||||
exec "${EXECUTABLE_NODE}" \
|
||||
"${HVIGOR_WRAPPER_SCRIPT}" "$@"
|
64
code/BasicFeature/Extension/Contexttest/hvigorw.bat
Normal file
@ -0,0 +1,64 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Hvigor startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js
|
||||
set NODE_EXE=node.exe
|
||||
|
||||
goto start
|
||||
|
||||
:start
|
||||
@rem Find node.exe
|
||||
if defined NODE_HOME goto findNodeFromNodeHome
|
||||
|
||||
%NODE_EXE% --version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the NODE_HOME variable in your environment to match the
|
||||
echo location of your NodeJs installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findNodeFromNodeHome
|
||||
set NODE_HOME=%NODE_HOME:"=%
|
||||
set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE%
|
||||
|
||||
if exist "%NODE_EXE_PATH%" goto execute
|
||||
echo.
|
||||
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the NODE_HOME variable in your environment to match the
|
||||
echo location of your NodeJs installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Execute hvigor
|
||||
"%NODE_EXE%" "%WRAPPER_MODULE_PATH%" %*
|
||||
|
||||
if "%ERRORLEVEL%" == "0" goto hvigorwEnd
|
||||
|
||||
:fail
|
||||
exit /b 1
|
||||
|
||||
:hvigorwEnd
|
||||
if "%OS%" == "Windows_NT" endlocal
|
||||
|
||||
:end
|
12
code/BasicFeature/Extension/Contexttest/oh-package.json5
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"license": "",
|
||||
"devDependencies": {
|
||||
"@ohos/hypium": "1.0.11"
|
||||
},
|
||||
"author": "",
|
||||
"name": "contexttest",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {}
|
||||
}
|
11
code/BasicFeature/Extension/Contexttest/ohosTest.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Extension测试用例归档
|
||||
|
||||
## 用例表
|
||||
|
||||
| 测试功能 | 预置条件 |输入| 预期输出 | 是否自动 |测试结果|
|
||||
|----------------------|----------------|--------------------------------|----------------------------------|------|--------------------------------|
|
||||
| 拉起应用 | startAbility应用 | 设备正常运行 | | 成功拉起应用 | 是 |Pass|
|
||||
| 访问共享文件成功 | 页面显示正常 |点击屏幕上的uiability在由"test1"的groupId产生的主应用共享目录下创建共享文件按钮| 访问成功,打印日志Try to write str. | 是 |Pass|
|
||||
| 访问共享文件失败 | 页面显示正常 |点击屏幕上的uiability在由"test2"的groupId产生的主应用共享目录下创建共享文件按钮| 访问失败,打印日志{"code":13900002} | 是 |Pass|
|
||||
| 访问module级别独立extension | 页面显示正常 |点击屏幕上的uiability访问inputmethod module级别的独立extension的沙箱文件按钮| 页面上UIAbility1变为inputtest1 failed | 是 |Pass|
|
||||
| 访问应用级别独立extension | 页面显示正常 |点击屏幕上的uiability访问inputmethod module级别的独立extension的沙箱文件按钮| 页面上UIAbility1变为inputtest2 failed | 是 |Pass|
|
After Width: | Height: | Size: 73 KiB |
After Width: | Height: | Size: 78 KiB |
After Width: | Height: | Size: 78 KiB |