!4027 【Sample】线程间大数据传输和主线程与子线程间通信文章示例代码

Merge pull request !4027 from haoxiaohui/master
This commit is contained in:
openharmony_ci 2024-01-26 09:58:33 +00:00 committed by Gitee
commit 2943799b3e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
48 changed files with 1828 additions and 24 deletions

View File

@ -20,9 +20,9 @@
{
"name": "default",
"signingConfig": "default",
"compileSdkVersion": 10,
"compatibleSdkVersion": 10,
"targetSdkVersion": 10
"compileSdkVersion": 11,
"compatibleSdkVersion": 11,
"targetSdkVersion": 11
}
],
"buildModeSet": [
@ -110,6 +110,10 @@
{
"name": "nativeThreadsCallJS",
"srcPath": "./feature/nativeThreadsCallJS"
},
{
"name": "ThreadCommunication",
"srcPath": "./feature/ThreadCommunication"
}
]
}

View File

@ -0,0 +1,6 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test

View 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.
*/
export { IndependentTask } from './src/main/ets/pages/IndependentTask';
export { MultiTask } from './src/main/ets/pages/MultiTask';
export { TaskSendDataUsage } from './src/main/ets/pages/TaskSendDataUsage';
export { WorkerUsage } from './src/main/ets/pages/WorkerUsage';
export { WorkerCallGlobalUsage } from './src/main/ets/pages/WorkerCallGlobalUsage';
export { ThreadCommunicationHomePage } from './src/main/ets/pages/ThreadCommunicationHomePage';

View File

@ -0,0 +1,44 @@
/*
* 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": {
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": [
"./obfuscation-rules.txt"
]
},
"consumerFiles": [
"./consumer-rules.txt"
]
}
}
},
],
"targets": [
{
"name": "default"
}
]
}

View 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 { harTasks } from '@ohos/hvigor-ohos-plugin';
export default {
system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}

View File

@ -0,0 +1,18 @@
# Define project specific obfuscation rules here.
# You can include the obfuscation configuration files in the current module's build-profile.json5.
#
# For more details, see
# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
# Obfuscation options:
# -disable-obfuscation: disable all obfuscations
# -enable-property-obfuscation: obfuscate the property names
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
# -compact: remove unnecessary blank spaces and all line feeds
# -remove-log: remove all console.* statements
# -print-namecache: print the name cache that contains the mapping from the old names to new names
# -apply-namecache: reuse the given cache file
# Keep options:
# -keep-property-name: specifies property names that you want to keep
# -keep-global-name: specifies names that you want to keep in the global scope

View 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.
*/
{
"license": "Apache-2.0",
"devDependencies": {},
"author": "",
"name": "threadcommunication",
"description": "Please describe the basic information.",
"main": "ThreadCommunicationHomePage.ets",
"version": "1.0.0",
"dependencies": {}
}

View 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.
*/
// 图片显示类,用于存储图片和对应的文字数据
export class IconItemSource {
image: string | Resource = '';
text: string | Resource = '';
constructor(image: string | Resource = '', text: string | Resource = '') {
this.image = image;
this.text = text;
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.
*/
// 字体透明度
const TEXT_OPACITY: number = 0.8;
@Component
export struct IconItem {
image: string | Resource = '';
text: string | Resource = '';
build() {
Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignContent: FlexAlign.Center }) {
Image(this.image)
.height(40)
.width(40)
.objectFit(ImageFit.Contain)
.margin({
left: 15
})
Text(this.text)
.fontSize(20)
.fontColor(Color.Black)
.width(100)
.height(50)
.opacity(TEXT_OPACITY)
.textAlign(TextAlign.Center)
}
.width($r('app.string.percent_100'))
.height(50)
}
}

View File

@ -0,0 +1,103 @@
/*
* 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 router from '@ohos.router';
import taskpool from '@ohos.taskpool';
import { IconItem } from './IconView';
import { IconItemSource } from './IconItemSource';
@Concurrent
function loadPicture(count: number): IconItemSource[] {
let iconItemSourceList: IconItemSource[] = [];
// 遍历添加count*6个IconItem的数据
for (let index = 0; index < count; index++) {
const numStart: number = index * 6;
// 此处循环使用6张图片资源
iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`));
iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`));
iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`));
iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`));
iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`));
iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`));
}
return iconItemSourceList;
}
@Component
export struct IndependentTask {
@State iconItemSourceList: IconItemSource[] = [];
build() {
Column() {
// 顶部导航栏
Row() {
Image($r("app.media.back"))
.height(24)
.width(24)
.onClick(() => {
router.back();
})
Text($r('app.string.scenario_1'))
.fontSize(24)
.lineHeight(30)
.fontColor(Color.Black)
.fontWeight(FontWeight.Bold)
.textAlign(TextAlign.Start)
.margin({
left: 16
})
}
.width($r('app.string.percent_100'))
.height(50)
.justifyContent(FlexAlign.Start)
.padding({
left: 24
})
Button($r('app.string.load_image'), { type: ButtonType.Normal, stateEffect: true })
.fontSize(14)
.borderRadius(8)
.backgroundColor(Color.Blue)
.width(250)
.height(60)
.margin({
top: 30
})
.onClick(() => {
let lodePictureTask: taskpool.Task = new taskpool.Task(loadPicture, 30);
taskpool.execute(lodePictureTask).then((res: Object) => {
this.iconItemSourceList = res as IconItemSource[];
})
})
if (this.iconItemSourceList.length > 0) {
List({ space: 20 }) {
ForEach(this.iconItemSourceList, (item: IconItemSource) => {
ListItem() {
IconItem({ image: item.image, text: item.text });
}
}, (item: IconItemSource, index) => index.toString())
}
.divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线
.width($r('app.string.percent_100'))
.height($r('app.string.percent_100'))
.layoutWeight(1)
}
}
.width($r('app.string.percent_100'))
.height($r('app.string.percent_100'))
.alignItems(HorizontalAlign.Center)
}
}

View File

@ -0,0 +1,111 @@
/*
* 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 router from '@ohos.router';
import taskpool from '@ohos.taskpool';
import { IconItem } from './IconView';
import { IconItemSource } from './IconItemSource';
@Concurrent
function loadPicture(count: number): IconItemSource[] {
let iconItemSourceList: IconItemSource[] = [];
// 遍历添加count*6个IconItem的数据
for (let index = 0; index < count; index++) {
const numStart: number = index * 6;
// 此处循环使用6张图片资源
iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`));
iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`));
iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`));
iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`));
iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`));
iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`));
}
return iconItemSourceList;
}
@Component
export struct MultiTask {
@State iconItemSourceList: IconItemSource[] = [];
build() {
Column() {
// 顶部导航栏
Row() {
Image($r("app.media.back"))
.height(24)
.width(24)
.onClick(() => {
router.back();
})
Text($r('app.string.scenario_2'))
.fontSize(24)
.lineHeight(30)
.fontColor(Color.Black)
.fontWeight(FontWeight.Bold)
.textAlign(TextAlign.Start)
.margin({
left: 16
})
}
.width($r('app.string.percent_100'))
.height(50)
.justifyContent(FlexAlign.Start)
.padding({
left: 24
})
Button($r('app.string.load_image'), { type: ButtonType.Normal, stateEffect: true })
.fontSize(14)
.borderRadius(8)
.backgroundColor(Color.Blue)
.width(250)
.height(60)
.margin({
top: 30
})
.onClick(() => {
let taskGroup: taskpool.TaskGroup = new taskpool.TaskGroup();
taskGroup.addTask(new taskpool.Task(loadPicture, 30));
taskGroup.addTask(new taskpool.Task(loadPicture, 20));
taskGroup.addTask(new taskpool.Task(loadPicture, 10));
taskpool.execute(taskGroup).then((ret: Object[]) => {
for (let i = 0; i < ret.length; i++) {
let iconItems: IconItemSource[] = (ret[i] as IconItemSource[]);
for (let j = 0; j < iconItems.length; j++) {
this.iconItemSourceList.push(iconItems[j] as IconItemSource);
}
}
})
})
if (this.iconItemSourceList.length > 0) {
List({ space: 20 }) {
ForEach(this.iconItemSourceList, (item: IconItemSource) => {
ListItem() {
IconItem({ image: item.image, text: item.text });
}
}, (item: IconItemSource, index) => index.toString())
}
.divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线
.width($r('app.string.percent_100'))
.height($r('app.string.percent_100'))
.layoutWeight(1)
}
}
.width($r('app.string.percent_100'))
.height($r('app.string.percent_100'))
.alignItems(HorizontalAlign.Center)
}
}

View File

@ -0,0 +1,112 @@
/*
* 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 router from '@ohos.router';
import taskpool from '@ohos.taskpool';
import { IconItem } from './IconView';
import { IconItemSource } from './IconItemSource';
import Logger from '../util/Logger';
const LOAD_SUCCESS: string = getContext().resourceManager.getStringSync($r('app.string.process_success'));
@Concurrent
function loadPicture(count: number): IconItemSource[] {
let iconItemSourceList: IconItemSource[] = [];
// 遍历添加count*6个IconItem的数据
for (let index = 0; index < count; index++) {
const numStart: number = index * 6;
// 此处循环使用6张图片资源
iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`));
iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`));
iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`));
iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`));
iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`));
iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`));
}
taskpool.Task.sendData(iconItemSourceList.length);
return iconItemSourceList;
}
function notice(data: number): void {
Logger.info(LOAD_SUCCESS + data);
}
@Component
export struct TaskSendDataUsage {
@State iconItemSourceList: IconItemSource[] = [];
build() {
Column() {
// 顶部导航栏
Row() {
Image($r("app.media.back"))
.height(24)
.width(24)
.onClick(() => {
router.back();
})
Text($r('app.string.scenario_3'))
.fontSize(24)
.lineHeight(30)
.fontColor(Color.Black)
.fontWeight(FontWeight.Bold)
.textAlign(TextAlign.Start)
.margin({
left: 16
})
}
.width($r('app.string.percent_100'))
.height(50)
.justifyContent(FlexAlign.Start)
.padding({
left: 24
})
Button($r('app.string.load_image'), { type: ButtonType.Normal, stateEffect: true })
.fontSize(14)
.borderRadius(8)
.backgroundColor(Color.Blue)
.width(250)
.height(60)
.margin({
top: 30
})
.onClick(() => {
let lodePictureTask: taskpool.Task = new taskpool.Task(loadPicture, 30);
lodePictureTask.onReceiveData(notice);
taskpool.execute(lodePictureTask).then((res: Object) => {
this.iconItemSourceList = res as IconItemSource[];
})
})
if (this.iconItemSourceList.length > 0) {
List({ space: 20 }) {
ForEach(this.iconItemSourceList, (item: IconItemSource) => {
ListItem() {
IconItem({ image: item.image, text: item.text });
}
}, (item: IconItemSource, index) => index.toString())
}
.divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线
.width($r('app.string.percent_100'))
.height($r('app.string.percent_100'))
.layoutWeight(1)
}
}
.width($r('app.string.percent_100'))
.height($r('app.string.percent_100'))
.alignItems(HorizontalAlign.Center)
}
}

View File

@ -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 router from '@ohos.router';
@Component
export struct ThreadCommunicationHomePage {
build() {
Column() {
Row() {
Row() {
Text($r('app.string.thread_communication'))
.fontSize(20)
.lineHeight(30)
.fontColor(Color.Black)
.fontWeight(FontWeight.Bold)
.textAlign(TextAlign.Center)
.width($r('app.string.percent_100'))
.height(30)
}
.height(56)
.backgroundColor(Color.White)
}
.margin({
left: 24
})
Button($r('app.string.scenario_1'), { type: ButtonType.Normal, stateEffect: true })
.id('Scenario_1')
.fontSize(14)
.borderRadius(8)
.backgroundColor(Color.Blue)
.width(250)
.height(60)
.margin({
top: 30
})
.onClick(() => {
router.pushUrl({
url: 'pages/ThreadCommunication/IndependentTaskPage'
})
})
Button($r('app.string.scenario_2'), { type: ButtonType.Normal, stateEffect: true })
.id('Scenario_2')
.fontSize(14)
.borderRadius(8)
.backgroundColor(Color.Blue)
.width(250)
.height(60)
.margin({
top: 30
})
.onClick(() => {
router.pushUrl({
url: 'pages/ThreadCommunication/MultiTaskPage'
})
})
Button($r('app.string.scenario_3'), { type: ButtonType.Normal, stateEffect: true })
.id('Scenario_3')
.fontSize(14)
.borderRadius(8)
.backgroundColor(Color.Blue)
.width(250)
.height(60)
.margin({
top: 30
})
.onClick(() => {
router.pushUrl({
url: 'pages/ThreadCommunication/TaskSendDataUsagePage'
})
})
Button($r('app.string.scenario_4'), { type: ButtonType.Normal, stateEffect: true })
.id('Scenario_4')
.fontSize(14)
.borderRadius(8)
.backgroundColor(Color.Blue)
.width(250)
.height(60)
.margin({
top: 30
})
.onClick(() => {
router.pushUrl({
url: 'pages/ThreadCommunication/WorkerUsagePage'
})
})
Button($r('app.string.scenario_5'), { type: ButtonType.Normal, stateEffect: true })
.id('Scenario_5')
.fontSize(14)
.borderRadius(8)
.backgroundColor(Color.Blue)
.width(250)
.height(60)
.margin({
top: 30
})
.onClick(() => {
router.pushUrl({
url: 'pages/ThreadCommunication/WorkerCallGlobalUsagePage'
})
})
}
.height(200)
.width($r('app.string.percent_100'))
}
}

View File

@ -0,0 +1,119 @@
/*
* 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 router from '@ohos.router';
import worker from '@ohos.worker';
import { IconItem } from './IconView';
import { IconItemSource } from './IconItemSource';
class PicData {
public iconItemSourceList: IconItemSource[] = [];
public setUp(): string {
for (let index = 0; index < 20; index++) {
const numStart: number = index * 6;
// 此处循环使用6张图片资源
this.iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`));
this.iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`));
this.iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`));
this.iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`));
this.iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`));
this.iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`));
}
return "setUpIconItemSourceList success!";
}
}
@Component
export struct WorkerCallGlobalUsage {
@State iconItemSourceList: IconItemSource[] = [];
private workerInstance: worker.ThreadWorker | undefined = undefined;
private message: string = "run setUp in picData";
aboutToAppear() {
this.initWorker();
}
build() {
Column() {
// 顶部导航栏
Row() {
Image($r("app.media.back"))
.height(24)
.width(24)
.onClick(() => {
router.back();
})
Text($r('app.string.scenario_5'))
.fontSize(24)
.lineHeight(30)
.fontColor(Color.Black)
.fontWeight(FontWeight.Bold)
.textAlign(TextAlign.Start)
.margin({
left: 16
})
}
.width($r('app.string.percent_100'))
.height(50)
.justifyContent(FlexAlign.Start)
.padding({
left: 24
})
Button($r('app.string.load_image'), { type: ButtonType.Normal, stateEffect: true })
.fontSize(14)
.borderRadius(8)
.backgroundColor(Color.Blue)
.width(250)
.height(60)
.margin({
top: 30
})
.onClick(() => {
if (this.workerInstance !== undefined) {
this.workerInstance.postMessage(this.message);
}
})
if (this.iconItemSourceList.length > 0) {
List({ space: 20 }) {
ForEach(this.iconItemSourceList, (item: IconItemSource) => {
ListItem() {
IconItem({ image: item.image, text: item.text });
}
}, (item: IconItemSource, index) => index.toString())
}
.divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线
.width($r('app.string.percent_100'))
.height($r('app.string.percent_100'))
.layoutWeight(1)
}
}
.width($r('app.string.percent_100'))
.height($r('app.string.percent_100'))
.alignItems(HorizontalAlign.Center)
}
initWorker() {
if (this.workerInstance !== undefined) {
let picData: PicData = new PicData();
// 在ThreadWorker实例上注册registerObj
this.workerInstance.registerGlobalCallObject("picData", picData);
}
}
}

View File

@ -0,0 +1,107 @@
/*
* 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 router from '@ohos.router';
import worker, { MessageEvents } from '@ohos.worker';
import { IconItem } from './IconView';
import { IconItemSource } from './IconItemSource';
@Component
export struct WorkerUsage {
@State iconItemSourceList: IconItemSource[] = [];
private workerInstance: worker.ThreadWorker | undefined = undefined;
aboutToAppear() {
for (let index = 0; index < 20; index++) {
const numStart: number = index * 6;
// 此处循环使用6张图片资源
this.iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`));
this.iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`));
this.iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`));
this.iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`));
this.iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`));
this.iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`));
}
if (this.workerInstance !== undefined) {
this.workerInstance.onmessage = (e: MessageEvents): void => {
if (e.data instanceof Array) {
this.iconItemSourceList = e.data;
}
}
}
}
build() {
Column() {
// 顶部导航栏
Row() {
Image($r("app.media.back"))
.height(24)
.width(24)
.onClick(() => {
router.back();
})
Text($r('app.string.scenario_4'))
.fontSize(24)
.lineHeight(30)
.fontColor(Color.Black)
.fontWeight(FontWeight.Bold)
.textAlign(TextAlign.Start)
.margin({
left: 16
})
}
.width($r('app.string.percent_100'))
.height(50)
.justifyContent(FlexAlign.Start)
.padding({
left: 24
})
Button($r('app.string.change_image_number'), { type: ButtonType.Normal, stateEffect: true })
.fontSize(14)
.borderRadius(8)
.backgroundColor(Color.Blue)
.width(250)
.height(60)
.margin({
top: 30
})
.onClick(() => {
if (this.workerInstance !== undefined) {
this.workerInstance.postMessage(this.iconItemSourceList);
}
})
if (this.iconItemSourceList.length > 0) {
List({ space: 20 }) {
ForEach(this.iconItemSourceList, (item: IconItemSource) => {
ListItem() {
IconItem({ image: item.image, text: item.text });
}
}, (item: IconItemSource, index) => index.toString())
}
.divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线
.width($r('app.string.percent_100'))
.height($r('app.string.percent_100'))
.layoutWeight(1)
}
}
.width($r('app.string.percent_100'))
.height($r('app.string.percent_100'))
.alignItems(HorizontalAlign.Center)
}
}

View File

@ -0,0 +1,45 @@
/*
* 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 hilog from '@ohos.hilog';
const DOMAIN: number = 0xF811;
class Logger {
private prefix: string="";
private format: string = '%{public}s, %{public}s';
constructor(prefix: string) {
this.prefix = prefix;
}
debug(...args: string[]): void {
hilog.debug(DOMAIN, this.prefix, this.format, args);
}
info(...args: string[]): void {
hilog.info(DOMAIN, this.prefix, this.format, args);
}
warn(...args: string[]): void {
hilog.warn(DOMAIN, this.prefix, this.format, args);
}
error(...args: string[]): void {
hilog.error(DOMAIN, this.prefix, this.format, args);
}
}
export default new Logger('ThreadCommunication');

View 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.
*/
{
"module": {
"name": "ThreadCommunication",
"type": "har",
"deviceTypes": [
"default",
"tablet"
]
}
}

View File

@ -0,0 +1,8 @@
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}

View File

@ -0,0 +1,56 @@
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "thread_communication",
"value": "主线程和子线程的通信"
},
{
"name": "scenario_1",
"value": "场景一:独立的耗时任务"
},
{
"name": "scenario_2",
"value": "场景二:多个任务执行结果统一返回"
},
{
"name": "scenario_3",
"value": "场景三TaskPool和主线程的即时通信"
},
{
"name": "scenario_4",
"value": "场景四Worker和主线程的即时通信"
},
{
"name": "scenario_5",
"value": "场景五:子线程同步调用主线程的接口"
},
{
"name": "load_image",
"value": "加载图片"
},
{
"name": "percent_100",
"value": "100%"
},
{
"name": "change_image_number",
"value": "将图片变成4个"
},
{
"name": "process_success",
"value": "子线程任务已执行完,共加载图片:"
}
]
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="22px" height="22px" viewBox="0 0 22 22" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>ic_applet</title>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="发现" transform="translate(-24.000000, -357.000000)">
<g id="编组-4备份-4" transform="translate(12.000000, 340.000000)">
<g id="List/single-line/48/with-right-element备份" transform="translate(12.000000, 16.000000)">
<g id="ic_applet" transform="translate(0.000000, 1.000000)">
<rect id="矩形" x="0" y="0" width="22" height="22"></rect>
<path d="M11,1 C16.5228571,1 21,5.47714286 21,11 C21,16.5228571 16.5228571,21 11,21 C5.47714286,21 1,16.5228571 1,11 C1,5.47714286 5.47714286,1 11,1 Z M11,2.42857143 C6.26613839,2.42857143 2.42857143,6.26613839 2.42857143,11 C2.42857143,15.7338616 6.26613839,19.5714286 11,19.5714286 C15.7338616,19.5714286 19.5714286,15.7338616 19.5714286,11 C19.5714286,6.26613839 15.7338616,2.42857143 11,2.42857143 Z M13.3277679,5.58399554 C14.9937723,5.58399554 16.3492634,6.93948661 16.3492634,8.60549107 C16.3492634,9.77866071 15.6610045,10.8554911 14.5960268,11.3485045 C14.502288,11.3920684 14.4001752,11.4146619 14.296808,11.4147098 C14.0186123,11.4148874 13.765693,11.2533209 13.6489062,11.0008259 C13.4850446,10.6468527 13.6359598,10.2277009 13.9859375,10.0587277 L13.9965848,10.053683 C14.5590848,9.79330357 14.9224107,9.22493304 14.9224107,8.60546875 C14.9224107,7.72613839 14.2071205,7.01084821 13.3277679,7.01084821 C12.4572321,7.01084821 11.7474554,7.71191964 11.7333482,8.57915179 L11.733125,8.60549107 C11.733125,8.62511161 11.7321652,8.64549107 11.7302679,8.66754464 L11.7300446,8.67232143 L11.7300446,13.3669643 L11.7219643,13.3669643 L11.7219643,13.4227679 C11.7219643,15.0887946 10.3664732,16.4442634 8.70049107,16.4442634 C7.03448661,16.4442634 5.67899554,15.0887946 5.67899554,13.4227902 C5.67899554,12.2489955 6.36774554,11.171942 7.43348214,10.6791518 C7.79107143,10.51375 8.21506696,10.6696205 8.38046875,11.0272768 C8.54419643,11.3813393 8.39308036,11.8004241 8.04301339,11.9692411 L8.03234375,11.9742634 C7.46946429,12.2345312 7.10584821,12.8029911 7.10584821,13.4227902 C7.10584821,14.3021205 7.82113839,15.0174107 8.70049107,15.0174107 C9.57982143,15.0174107 10.2951116,14.3021205 10.2951116,13.4227679 C10.2951116,13.3869866 10.2977902,13.3512277 10.3031027,13.3158259 L10.3037277,13.3116964 L10.3037054,8.66129464 L10.3062946,8.66129464 L10.3062946,8.60549107 C10.3062946,6.95616071 11.6347768,5.61116071 13.2778795,5.58441964 L13.3277679,5.58399554 L13.3277679,5.58399554 Z" id="形状" fill="#6236FF" fill-rule="nonzero"></path>
</g>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="20px" height="18px" viewBox="0 0 20 18" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>public/ic_back</title>
<defs>
<path d="M3.81079777,10.7499686 L9.78033009,16.7196699 L9.81407138,16.7556673 C10.0727547,17.0502619 10.0615076,17.4991526 9.78033009,17.7803301 C9.4991526,18.0615076 9.05026186,18.0727547 8.75566731,17.8140714 L8.71966991,17.7803301 L1.68929777,10.7499686 L3.81079777,10.7499686 Z M9.78033009,0.219669914 C10.0615076,0.500847404 10.0727547,0.949738137 9.81407138,1.24433269 L9.78033009,1.28033009 L2.8105,8.25 L19.5,8.25 C19.8994202,8.25 20.2259152,8.56222999 20.2487268,8.9559318 L20.25,9 C20.25,9.39942022 19.93777,9.72591522 19.5440682,9.74872683 L19.5,9.75 L1,9.75 C0.346037929,9.75 0.0115866314,8.97615472 0.440603566,8.50027227 L0.469669914,8.46966991 L8.71966991,0.219669914 C9.01256313,-0.0732233047 9.48743687,-0.0732233047 9.78033009,0.219669914 Z" id="path-1"></path>
</defs>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="朋友圈" transform="translate(-26.000000, -43.000000)">
<g id="AppBar/Regular/basic+actions" transform="translate(24.000000, 37.000000)">
<g id="public/ic_back" transform="translate(0.000000, 3.000000)">
<g id="symbol/frame/symbol_grid24-copy"></g>
<g id="编组" transform="translate(1.750000, 3.000000)">
<mask id="mask-2" fill="white">
<use xlink:href="#path-1"></use>
</mask>
<g id="形状结合" fill-rule="nonzero"></g>
<rect id="color/#000000" fill="#182431" mask="url(#mask-2)" x="-1.75" y="-3" width="24" height="24"></rect>
</g>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="22px" height="22px" viewBox="0 0 22 22" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>ic_cards</title>
<defs>
<filter color-interpolation-filters="auto" id="filter-1">
<feColorMatrix in="SourceGraphic" type="matrix" values="0 0 0 0 0.000000 0 0 0 0 0.490196 0 0 0 0 1.000000 0 0 0 1.000000 0"></feColorMatrix>
</filter>
<path d="M21.0833333,15.5833333 C21.0833333,17.6083774 19.4417107,19.25 17.4166667,19.25 L4.58333333,19.25 C2.55828925,19.25 0.916666667,17.6083774 0.916666667,15.5833333 L0.916666667,6.41666667 C0.916666667,4.39162258 2.55828925,2.75 4.58333333,2.75 L17.4166667,2.75 C19.3763867,2.75 20.9770232,4.28741969 21.0782508,6.22193384 L21.0833333,6.41666667 L21.0833333,15.5833333 Z M19.7076667,8.25 L2.29166667,8.25 L2.29166667,15.5833333 C2.29166667,16.8275341 3.28319539,17.840151 4.51918847,17.8741196 L4.58333333,17.875 L17.4166667,17.875 C18.6608675,17.875 19.6734844,16.8834713 19.7074529,15.6474782 L19.7083333,15.5833333 L19.7076667,8.25 Z M10.3125,9.625 C10.6921958,9.625 11,9.93280423 11,10.3125 C11,10.6921958 10.6921958,11 10.3125,11 L4.35416667,11 C3.9744709,11 3.66666667,10.6921958 3.66666667,10.3125 C3.66666667,9.93280423 3.9744709,9.625 4.35416667,9.625 L10.3125,9.625 Z M17.4808115,4.12588041 L4.58333333,4.125 C3.33913252,4.125 2.32651565,5.11652872 2.29254708,6.35252181 L2.29166667,6.416 L19.7083333,6.41666667 C19.7083333,5.17246585 18.7168046,4.15984898 17.4808115,4.12588041 Z" id="path-2"></path>
</defs>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="我的" transform="translate(-24.000000, -358.000000)">
<g id="ic_cards" transform="translate(12.000000, 197.000000)" filter="url(#filter-1)">
<g transform="translate(12.000000, 161.000000)">
<rect id="矩形" x="0" y="0" width="22" height="22"></rect>
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="形状结合" fill-rule="nonzero"></g>
<g id="编组" mask="url(#mask-3)" fill="#FA6400" fill-opacity="0.9">
<g id="Symbol/color-light/colorPrimary">
<rect id="color/#000000" x="0" y="0" width="22" height="22"></rect>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="18px" height="22px" viewBox="0 0 18 22" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>ic_near</title>
<defs>
<filter color-interpolation-filters="auto" id="filter-1">
<feColorMatrix in="SourceGraphic" type="matrix" values="0 0 0 0 0.105882 0 0 0 0 0.835294 0 0 0 0 0.509804 0 0 0 1.000000 0"></feColorMatrix>
</filter>
<path d="M11,0.816240026 C15.6799965,0.816240026 19.4791667,4.54359252 19.4791667,9.14814635 C19.4791667,10.9413637 18.9359957,12.6935534 17.9278262,14.4644549 C17.3001642,15.5669755 16.5459661,16.6050046 15.5474582,17.7902515 L15.5474582,17.7902515 L15.3030652,18.0776458 L15.048929,18.3713436 C14.9625528,18.4703657 14.8744924,18.5705468 14.7846876,18.6719953 C14.5844402,18.8982057 14.3595853,19.135905 14.1100407,19.3852499 L14.1100407,19.3852499 L13.9182516,19.5744445 C13.7873043,19.7020333 13.6501795,19.8325433 13.5068668,19.9659941 L13.5068668,19.9659941 L13.2872556,20.1683783 C13.2498799,20.2024774 13.2121171,20.236761 13.173967,20.2712292 L13.173967,20.2712292 L12.9404188,20.4802579 C12.8610197,20.5506746 12.7800704,20.6218326 12.6975697,20.6937345 L12.6975697,20.6937345 L12.4454119,20.9116738 C11.645446,21.5975104 10.4692289,21.618815 9.63358735,20.9564556 L9.63358735,20.9564556 L9.56839926,20.9021196 L9.26507984,20.6375891 L9.07795078,20.4728538 L8.81273835,20.2369709 L8.5660092,20.0144421 L8.33765747,19.8051438 L8.12757728,19.6089523 L7.99762241,19.4853786 L7.87570981,19.3675385 L7.76180812,19.2553955 L7.65588595,19.1489129 L7.55791196,19.0480542 C7.54224357,19.031711 7.52690504,19.0156006 7.51189573,18.9997223 L7.51189573,18.9997223 L7.42578517,18.9072306 L7.21319597,18.6700154 L6.97833832,18.4036777 C6.93967201,18.3594594 6.90124435,18.3153257 6.86305587,18.2712747 L6.86305587,18.2712747 L6.63679901,18.0079485 L6.41630662,17.7465258 L6.41630662,17.7465258 L6.30822974,17.6165022 L6.09642992,17.3577784 L5.89045574,17.1007496 C3.69071271,14.3251517 2.52083333,11.8332778 2.52083333,9.14814635 C2.52083333,4.57730584 6.14891831,0.890581125 10.7556612,0.81728588 L10.7556612,0.81728588 L10.8899427,0.816240026 Z M11,2.1912183 L10.8954084,2.1912183 L10.7720671,2.1921771 C6.92160051,2.25345789 3.89583333,5.32812971 3.89583333,9.14814635 C3.89583333,11.8217999 5.31593095,14.4119317 8.00841612,17.4928378 L8.00841612,17.4928378 L8.23897567,17.7543772 L8.44472439,17.9840122 C8.45625336,17.9965985 8.46810817,18.009428 8.4802884,18.0225002 L8.4802884,18.0225002 L8.55727142,18.1038423 L8.64204421,18.1909864 L8.73458647,18.2839089 L8.88792324,18.4340761 L9.05862717,18.5971127 L9.24662976,18.7729396 L9.38154136,18.8972241 L9.59822285,19.0941919 L9.83202035,19.3037387 L10.0828654,19.525785 L10.4591378,19.8547809 L10.4994215,19.8884098 C10.8078076,20.1327674 11.2507501,20.1247444 11.5504598,19.8677937 L11.5504598,19.8677937 L11.7911033,19.6598268 L12.0224506,19.4565243 C12.0980162,19.3895359 12.1720311,19.3233274 12.244494,19.2579011 L12.244494,19.2579011 L12.4572258,19.0639718 L12.6606382,18.8747511 L12.8547237,18.6902536 L13.0394744,18.5104942 C13.3095956,18.2444159 13.5481863,17.9943779 13.7551294,17.7606036 L13.7551294,17.7606036 L13.8713764,17.6288064 L14.0990641,17.367729 C14.1364784,17.3244905 14.173626,17.2813874 14.2105071,17.2384171 L14.2105071,17.2384171 L14.4285972,16.9821675 L14.6403003,16.7289778 C14.7793088,16.5611765 14.9140654,16.3953306 15.0445823,16.2312711 L15.0445823,16.2312711 L15.2371794,15.9865004 C17.1629544,13.5111891 18.1041667,11.4316478 18.1041667,9.14814635 C18.1041667,5.30891955 14.9264165,2.1912183 11,2.1912183 L11,2.1912183 Z M11,7.10416667 C12.1390873,7.10416667 13.0625,8.02757937 13.0625,9.16666667 C13.0625,10.305754 12.1390873,11.2291667 11,11.2291667 C9.8609127,11.2291667 8.9375,10.305754 8.9375,9.16666667 C8.9375,8.02757937 9.8609127,7.10416667 11,7.10416667 Z" id="path-2"></path>
</defs>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="发现" transform="translate(-26.000000, -425.000000)">
<g id="编组-4备份-5" transform="translate(12.000000, 408.000000)">
<g id="List/single-line/48/with-right-element备份" transform="translate(12.000000, 16.000000)">
<g id="Public/ic_public_gps" transform="translate(0.000000, 1.000000)" filter="url(#filter-1)">
<g>
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="蒙版" fill-rule="nonzero"></g>
<g id="编组" mask="url(#mask-3)" fill="#1BD582" fill-opacity="0.9">
<g id="Symbol/color-light/colorPrimary">
<rect id="color/#000000" x="0" y="0" width="22" height="22"></rect>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="20px" height="20px" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>ic_scan</title>
<defs>
<filter color-interpolation-filters="auto" id="filter-1">
<feColorMatrix in="SourceGraphic" type="matrix" values="0 0 0 0 0.000000 0 0 0 0 0.490196 0 0 0 0 1.000000 0 0 0 1.000000 0"></feColorMatrix>
</filter>
<path d="M19.4791667,12.8333333 C19.8272211,12.8333333 20.1148667,13.0919744 20.1603906,13.4275437 L20.1666667,13.5208333 L20.1666667,16.5 C20.1666667,18.4636791 18.6230289,20.0668223 16.6830036,20.1621793 L16.5,20.1666667 L13.5208333,20.1666667 C13.1411376,20.1666667 12.8333333,19.8588624 12.8333333,19.4791667 C12.8333333,19.1311122 13.0919744,18.8434666 13.4275437,18.7979427 L13.5208333,18.7916667 L16.5,18.7916667 C17.7150264,18.7916667 18.7092021,17.8460921 18.7867921,16.6506777 L18.7916667,16.5 L18.7916667,13.5208333 C18.7916667,13.1411376 19.0994709,12.8333333 19.4791667,12.8333333 Z M2.52083333,12.8333333 C2.86888779,12.8333333 3.15653338,13.0919744 3.20205727,13.4275437 L3.20833333,13.5208333 L3.20833333,16.5 C3.20833333,17.7150264 4.15390794,18.7092021 5.34932229,18.7867921 L5.5,18.7916667 L8.47916667,18.7916667 C8.85886243,18.7916667 9.16666667,19.0994709 9.16666667,19.4791667 C9.16666667,19.8272211 8.90802561,20.1148667 8.57245634,20.1603906 L8.47916667,20.1666667 L5.5,20.1666667 C3.53632089,20.1666667 1.9331777,18.6230289 1.8378207,16.6830036 L1.83333333,16.5 L1.83333333,13.5208333 C1.83333333,13.1411376 2.14113757,12.8333333 2.52083333,12.8333333 Z M16.7291667,10.3125 C17.1088624,10.3125 17.4166667,10.6203042 17.4166667,11 C17.4166667,11.3796958 17.1088624,11.6875 16.7291667,11.6875 L5.27083333,11.6875 C4.89113757,11.6875 4.58333333,11.3796958 4.58333333,11 C4.58333333,10.6203042 4.89113757,10.3125 5.27083333,10.3125 L16.7291667,10.3125 Z M16.5,1.83333333 C18.4636791,1.83333333 20.0668223,3.3769711 20.1621793,5.31699635 L20.1666667,5.5 L20.1666667,8.47916667 C20.1666667,8.85886243 19.8588624,9.16666667 19.4791667,9.16666667 C19.1311122,9.16666667 18.8434666,8.90802561 18.7979427,8.57245634 L18.7916667,8.47916667 L18.7916667,5.5 C18.7916667,4.28497355 17.8460921,3.29079788 16.6506777,3.21320787 L16.5,3.20833333 L13.5208333,3.20833333 C13.1411376,3.20833333 12.8333333,2.9005291 12.8333333,2.52083333 C12.8333333,2.17277888 13.0919744,1.88513329 13.4275437,1.8396094 L13.5208333,1.83333333 L16.5,1.83333333 Z M8.47916667,1.83333333 C8.85886243,1.83333333 9.16666667,2.14113757 9.16666667,2.52083333 C9.16666667,2.86888779 8.90802561,3.15653338 8.57245634,3.20205727 L8.47916667,3.20833333 L5.5,3.20833333 C4.28497355,3.20833333 3.29079788,4.15390794 3.21320787,5.34932229 L3.20833333,5.5 L3.20833333,8.47916667 C3.20833333,8.85886243 2.9005291,9.16666667 2.52083333,9.16666667 C2.17277888,9.16666667 1.88513329,8.90802561 1.8396094,8.57245634 L1.83333333,8.47916667 L1.83333333,5.5 C1.83333333,3.53632089 3.3769711,1.9331777 5.31699635,1.8378207 L5.5,1.83333333 L8.47916667,1.83333333 Z" id="path-2"></path>
</defs>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="发现" transform="translate(-25.000000, -174.000000)">
<g id="编组-4" transform="translate(12.000000, 156.000000)">
<g id="Public/ic_public_scan" transform="translate(12.000000, 17.000000)" filter="url(#filter-1)">
<g>
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="形状结合" fill-rule="nonzero"></g>
<g id="编组" mask="url(#mask-3)" fill="#007DFF" fill-opacity="0.9">
<g id="Symbol/color-light/colorPrimary">
<rect id="color/#000000" x="0" y="0" width="22" height="22"></rect>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="20px" height="20px" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>ic_shop</title>
<defs>
<filter color-interpolation-filters="auto" id="filter-1">
<feColorMatrix in="SourceGraphic" type="matrix" values="0 0 0 0 0.878431 0 0 0 0 0.125490 0 0 0 0 0.125490 0 0 0 1.000000 0"></feColorMatrix>
</filter>
<path d="M16.5,1.83333333 C18.5250441,1.83333333 20.1666667,3.47495592 20.1666667,5.5 L20.1666667,16.5 C20.1666667,18.5250441 18.5250441,20.1666667 16.5,20.1666667 L5.5,20.1666667 C3.47495592,20.1666667 1.83333333,18.5250441 1.83333333,16.5 L1.83333333,5.5 C1.83333333,3.47495592 3.47495592,1.83333333 5.5,1.83333333 L16.5,1.83333333 Z M16.5,3.20833333 L5.5,3.20833333 C4.28497355,3.20833333 3.29079788,4.15390794 3.21320787,5.34932229 L3.20833333,5.5 L3.20833333,16.5 C3.20833333,17.7150264 4.15390794,18.7092021 5.34932229,18.7867921 L5.5,18.7916667 L16.5,18.7916667 C17.7150264,18.7916667 18.7092021,17.8460921 18.7867921,16.6506777 L18.7916667,16.5 L18.7916667,5.5 C18.7916667,4.28497355 17.8460921,3.29079788 16.6506777,3.21320787 L16.5,3.20833333 Z M15.125,5.5 C15.5046958,5.5 15.8125,5.80780423 15.8125,6.1875 C15.8125,8.84537036 13.6578704,11 11,11 C8.34212964,11 6.1875,8.84537036 6.1875,6.1875 C6.1875,5.80780423 6.49530423,5.5 6.875,5.5 C7.25469577,5.5 7.5625,5.80780423 7.5625,6.1875 C7.5625,8.08597883 9.10152117,9.625 11,9.625 C12.8984788,9.625 14.4375,8.08597883 14.4375,6.1875 C14.4375,5.80780423 14.7453042,5.5 15.125,5.5 Z" id="path-2"></path>
</defs>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="发现" transform="translate(-25.000000, -500.000000)">
<g id="编组-4备份-2" transform="translate(8.000000, 482.000000)">
<g id="List/single-line/48/with-right-element备份" transform="translate(16.000000, 4.000000)">
<g id="Public/ic_public_appstore" transform="translate(0.000000, 13.000000)" filter="url(#filter-1)">
<g>
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="形状结合" fill-rule="nonzero"></g>
<g id="编组" mask="url(#mask-3)" fill="#E02020" fill-opacity="0.9">
<g id="Symbol/color-light/colorPrimary">
<rect id="color/#000000" x="0" y="0" width="22" height="22"></rect>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -0,0 +1,56 @@
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "thread_communication",
"value": "主线程和子线程的通信"
},
{
"name": "scenario_1",
"value": "场景一:独立的耗时任务"
},
{
"name": "scenario_2",
"value": "场景二:多个任务执行结果统一返回"
},
{
"name": "scenario_3",
"value": "场景三TaskPool和主线程的即时通信"
},
{
"name": "scenario_4",
"value": "场景四Worker和主线程的即时通信"
},
{
"name": "scenario_5",
"value": "场景五:子线程同步调用主线程的接口"
},
{
"name": "load_image",
"value": "加载图片"
},
{
"name": "percent_100",
"value": "100%"
},
{
"name": "change_image_number",
"value": "将图片变成4个"
},
{
"name": "process_success",
"value": "子线程任务已执行完,共加载图片:"
}
]
}

View File

@ -0,0 +1,56 @@
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "thread_communication",
"value": "主线程和子线程的通信"
},
{
"name": "scenario_1",
"value": "场景一:独立的耗时任务"
},
{
"name": "scenario_2",
"value": "场景二:多个任务执行结果统一返回"
},
{
"name": "scenario_3",
"value": "场景三TaskPool和主线程的即时通信"
},
{
"name": "scenario_4",
"value": "场景四Worker和主线程的即时通信"
},
{
"name": "scenario_5",
"value": "场景五:子线程同步调用主线程的接口"
},
{
"name": "load_image",
"value": "加载图片"
},
{
"name": "percent_100",
"value": "100%"
},
{
"name": "change_image_number",
"value": "将图片变成4个"
},
{
"name": "process_success",
"value": "子线程任务已执行完,共加载图片:"
}
]
}

View File

@ -1,3 +1,18 @@
/*
* Copyright (c) 2023 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.
*/
{
"license": "Apache-2.0",
"devDependencies": {},

View File

@ -37,11 +37,11 @@ export async function pixelMapProcessByTaskPool(pixelMap: image.PixelMap, lastAd
taskPoolGroup.addTask(createImageTask(arrayBufferSlice, lastAdjustData, currentAdjustData, isParamsByTransfer));
}
let start: number = new Date().getTime();
taskpool.execute(taskPoolGroup).then((data: ArrayBuffer[]) => {
taskpool.execute(taskPoolGroup).then((data: Object[]) => {
if (callback !== undefined) {
let end : number = new Date().getTime();
AppStorage.set<String>('timeCost', util.format('%s s', ((end - start) / 60).toFixed(2).toString()));
callback(concatenateArrayBuffers(data));
let end: number = new Date().getTime();
AppStorage.set<String>('timeCost', util.format('%s s', ((end - start) / 1000).toFixed(2).toString()));
callback(concatenateArrayBuffers(data as ArrayBuffer[]));
}
}).catch((e: BusinessError) => {
Logger.error(e.message);

View File

@ -74,7 +74,7 @@ struct SliderCustom {
step: CommonConstants.SLIDER_STEP,
min: this.min,
max: this.max
})
}).id('thread_transfer_data_slider')
.trackColor(Color.White)
.width($r('app.string.layout_80_percent'))
.showSteps(true)

View File

@ -39,28 +39,28 @@ export class WaterFlowDataSource implements IDataSource {
// 通知控制器数据增加
notifyDataAdd(index: number): void {
this.listeners.forEach(listener => {
listener.onDataAdded(index)
listener.onDataAdd(index)
})
}
// 通知控制器数据变化
notifyDataChange(index: number): void {
this.listeners.forEach(listener => {
listener.onDataChanged(index)
listener.onDataChange(index)
})
}
// 通知控制器数据删除
notifyDataDelete(index: number): void {
this.listeners.forEach(listener => {
listener.onDataDeleted(index)
listener.onDataDelete(index)
})
}
// 通知控制器数据位置变化
notifyDataMove(from: number, to: number): void {
this.listeners.forEach(listener => {
listener.onDataMoved(from, to)
listener.onDataMove(from, to)
})
}

View File

@ -19,7 +19,8 @@
"externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt",
"arguments": "",
"cppFlags": ""
"cppFlags": "",
"abiFilters": ["armeabi-v7a"]
},
},
"buildOptionSet": [

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
{
"lockfileVersion": 1,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",

View File

@ -15,6 +15,11 @@
{
"apiType": "stageMode",
"buildOption": {
"sourceOption": {
"workers": [
"./src/main/ets/pages/ThreadCommunication/workers/Worker.ts"
]
}
},
"targets": [
{

View File

@ -23,9 +23,10 @@
"dependencies": {
"@ohos/backgroundTask": "file:../../../feature/backgroundTask",
"@ohos/grid": "file:../../../feature/grid",
"@ohos/webPerformance": "file:../../../feature/webPerformance",
"@ohos/nativethreadscalljs": "file:../../../feature/nativeThreadsCallJS",
"@ohos/staticImport": "file:../../../feature/staticImport",
"@ohos/ThreadCommunication": "file:../../../feature/ThreadCommunication",
"@ohos/nativethreadscalljs": "file:../../../feature/nativeThreadsCallJS",
"@ohos/webPerformance": "file:../../../feature/webPerformance",
"@ohos/ifOrVisibility": "file:../../../feature/ifOrVisibility",
"@ohos/smartPerfEditor": "file:../../../feature/smartPerfEditor",
"@ohos/hiDumper": "file:../../../feature/hiDumper",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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
@ -73,6 +73,10 @@ export let performanceTypeArray: Array<PerformanceMsg> = [
uri: 'pages/nativeThreadsCallJS/NativeThreadsCallJS'
},
{
name: 'ThreadCommunication',
uri: 'pages/ThreadCommunication/ThreadCommunicationHomePage'
},
}
name: 'WebPerformance',
uri: 'pages/webPerformance/WebHomePage'
}

View File

@ -0,0 +1,26 @@
/*
* 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 { IndependentTask } from '@ohos/ThreadCommunication';
@Entry
@Component
struct IndependentTaskPage {
build() {
Column() {
IndependentTask()
}
}
}

View File

@ -0,0 +1,26 @@
/*
* 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 { MultiTask } from '@ohos/ThreadCommunication';
@Entry
@Component
struct MultiTaskPage {
build() {
Column() {
MultiTask()
}
}
}

View File

@ -0,0 +1,26 @@
/*
* 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 { TaskSendDataUsage } from '@ohos/ThreadCommunication';
@Entry
@Component
struct TaskSendDataUsagePage {
build() {
Column() {
TaskSendDataUsage()
}
}
}

View File

@ -0,0 +1,26 @@
/*
* 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 { ThreadCommunicationHomePage } from '@ohos/ThreadCommunication';
@Entry
@Component
struct ThreadCommunicationPage {
build() {
Column() {
ThreadCommunicationHomePage()
}
}
}

View File

@ -0,0 +1,29 @@
/*
* 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 { WorkerCallGlobalUsage } from '@ohos/ThreadCommunication';
import worker from '@ohos.worker';
const workerInstance = new worker.ThreadWorker("entry/ets/pages/ThreadCommunication/workers/Worker.ts");
@Entry
@Component
struct WorkerCallGlobalUsagePage {
build() {
Column() {
WorkerCallGlobalUsage({workerInstance:workerInstance});
}
}
}

View File

@ -0,0 +1,29 @@
/*
* 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 { WorkerUsage } from '@ohos/ThreadCommunication';
import worker from '@ohos.worker';
const workerInstance = new worker.ThreadWorker("entry/ets/pages/ThreadCommunication/workers/Worker.ts");
@Entry
@Component
struct WorkerUsagePage {
build() {
Column() {
WorkerUsage({ workerInstance: workerInstance });
}
}
}

View File

@ -0,0 +1,33 @@
/*
* 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 worker, { MessageEvents, ThreadWorkerGlobalScope } from '@ohos.worker';
const workerPort: ThreadWorkerGlobalScope = worker.workerPort;
workerPort.onmessage = (e: MessageEvents): void => {
if (typeof e.data === "string") {
try {
// 调用方法无入参
let res: string = workerPort.callGlobalCallObjectMethod("picData", "setUp", 0) as string;
console.error("worker: ", res);
} catch (error) {
// 异常处理
console.error("worker: error code is " + error.code + " error message is " + error.message);
}
} else if (e.data instanceof Array) {
workerPort.postMessage(e.data.slice(0, 4));
}
}

View File

@ -42,6 +42,12 @@
"pages/DFXStateManagement/DFXStateManagementPage",
"pages/DFXStateManagement/DFXStateBeforeOptimizationPage",
"pages/DFXStateManagement/DFXStateAfterOptimizationPage",
"pages/ThreadCommunication/ThreadCommunicationHomePage",
"pages/ThreadCommunication/IndependentTaskPage",
"pages/ThreadCommunication/MultiTaskPage",
"pages/ThreadCommunication/TaskSendDataUsagePage",
"pages/ThreadCommunication/WorkerUsagePage",
"pages/ThreadCommunication/WorkerCallGlobalUsagePage",
"pages/webPerformance/WebHomePage",
"pages/webPerformance/WebBrowserPage",
"pages/webPerformance/WebInitializedPage",

View File

@ -603,10 +603,12 @@ export default function abilityTest() {
await btnAccept.click();
await driver.delayMs(3000);
// 获取定位权限
await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.permission_while_use'))));
let locAcceptBtn = await driver.findComponent(ON.text(await getResourceString($r('app.string.permission_while_use'))));
await locAcceptBtn.click();
await driver.delayMs(1000);
await driver.delayMs(500);
if (locAcceptBtn !== null) {
await locAcceptBtn.click();
await driver.delayMs(1000);
}
// 点击开启定位服务
let startLocationBtn: Component = await driver.findComponent(ON.text('开启定位服务'));
await driver.delayMs(500);
@ -766,6 +768,169 @@ export default function abilityTest() {
done();
})
/**
* 主线程和子线程通信
*/
it(BUNDLE + "ThreadCommunication_001", 1, async (done: Function) => {
Logger.info(TAG, `${BUNDLE}ThreadCommunication_001 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(500);
await driver.swipe(10, 800, 10, 0, 600);
await driver.delayMs(500);
let threadHome: Component = await driver.findComponent(ON.text('ThreadCommunication'));
await driver.delayMs(500);
await threadHome.click();
await driver.delayMs(1000);
await driver.assertComponentExist(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.thread_communication'))));
await driver.delayMs(200);
await driver.assertComponentExist(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.scenario_1'))));
await driver.delayMs(200);
await driver.assertComponentExist(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.scenario_2'))));
await driver.delayMs(200);
await driver.assertComponentExist(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.scenario_3'))));
await driver.delayMs(200);
await driver.assertComponentExist(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.scenario_4'))));
await driver.delayMs(200);
await driver.assertComponentExist(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.scenario_5'))));
await driver.delayMs(200);
Logger.info(TAG, `${BUNDLE}ThreadCommunication_001 end`);
done();
})
/**
* 独立的耗时任务测试用例
*/
it(BUNDLE + "ThreadCommunication_002", 1, async (done: Function) => {
Logger.info(TAG, `${BUNDLE}ThreadCommunication_002 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(500);
let scenario: Component = await driver.findComponent(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.scenario_1'))));
await driver.delayMs(500);
await scenario.click();
await driver.delayMs(1000);
let loadImage: Component = await driver.findComponent(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.load_image'))));
await driver.delayMs(500);
await loadImage.click();
await driver.delayMs(1000);
await driver.pressBack();
Logger.info(TAG, `${BUNDLE}ThreadCommunication_002 end`);
done();
})
/**
* 多个任务执行结果统一返回测试用例
*/
it(BUNDLE + "ThreadCommunication_003", 1, async (done: Function) => {
Logger.info(TAG, `${BUNDLE}ThreadCommunication_003 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(500);
let scenario: Component = await driver.findComponent(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.scenario_2'))));
await driver.delayMs(500);
await scenario.click();
await driver.delayMs(1000);
let loadImage: Component = await driver.findComponent(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.load_image'))));
await driver.delayMs(500);
await loadImage.click();
await driver.delayMs(1000);
await driver.pressBack();
Logger.info(TAG, `${BUNDLE}ThreadCommunication_003 end`);
done();
})
/**
* TaskPool和主线程的即时通信测试用例
*/
it(BUNDLE + "ThreadCommunication_004", 1, async (done: Function) => {
Logger.info(TAG, `${BUNDLE}ThreadCommunication_004 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(500);
let scenario: Component = await driver.findComponent(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.scenario_3'))));
await driver.delayMs(500);
await scenario.click();
await driver.delayMs(1000);
let loadImage: Component = await driver.findComponent(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.load_image'))));
await driver.delayMs(500);
await loadImage.click();
await driver.delayMs(1000);
await driver.pressBack();
Logger.info(TAG, `${BUNDLE}ThreadCommunication_004 end`);
done();
})
/**
* Worker和主线程的即时通信测试用例
*/
it(BUNDLE + "ThreadCommunication_005", 1, async (done: Function) => {
Logger.info(TAG, `${BUNDLE}ThreadCommunication_005 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(500);
let scenario: Component = await driver.findComponent(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.scenario_4'))));
await driver.delayMs(500);
await scenario.click();
await driver.delayMs(1000);
let loadImage: Component = await driver.findComponent(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.change_image_number'))));
await driver.delayMs(500);
await loadImage.click();
await driver.delayMs(1000);
await driver.pressBack();
Logger.info(TAG, `${BUNDLE}ThreadCommunication_005 end`);
done();
})
/**
* 子线程同步调用主线程的接口测试用例
*/
it(BUNDLE + "ThreadCommunication_006", 1, async (done: Function) => {
Logger.info(TAG, `${BUNDLE}ThreadCommunication_006 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(500);
let scenario: Component = await driver.findComponent(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.scenario_5'))));
await driver.delayMs(500);
await scenario.click();
await driver.delayMs(1000);
let loadImage: Component = await driver.findComponent(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.load_image'))));
await driver.delayMs(500);
await loadImage.click();
await driver.delayMs(1000);
await driver.pressBack();
await driver.delayMs(500);
await driver.pressBack();
Logger.info(TAG, `${BUNDLE}ThreadCommunication_006 end`);
done();
})
/**
* 点击WebPerformance按钮进入Web首页面
*/
@ -832,6 +997,48 @@ export default function abilityTest() {
})
/**
* 线程间大数据传输测试用例
*/
it(BUNDLE + "ThreadDataTransfer_001", 1, async (done: Function) => {
Logger.info(TAG, `${BUNDLE}ThreadDataTransfer_001 begin`);
let driver: Driver = Driver.create();
await driver.delayMs(500);
await driver.swipe(10, 800, 10, 0, 600);
await driver.delayMs(500);
let threadDataTransfer: Component = await driver.findComponent(ON.text('ThreadDataTransfer'));
await driver.delayMs(500);
await threadDataTransfer.click();
await driver.delayMs(500);
await driver.assertComponentExist(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.saturation'))));
await driver.delayMs(200);
await driver.assertComponentExist(ON.text(getContext().resourceManager.getStringSync($r('app.string.task_num'))));
await driver.delayMs(200);
await driver.assertComponentExist(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.pass_params'))));
await driver.delayMs(200);
let transferData: Component = await driver.findComponent(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.start_transfer'))));
await driver.delayMs(200);
await driver.assertComponentExist(ON.text(getContext()
.resourceManager
.getStringSync($r('app.string.running_time'))));
await driver.delayMs(200);
await transferData.click();
await driver.delayMs(500);
let slider: Component = await driver.findComponent(ON.id('thread_transfer_data_slider'));
await driver.delayMs(500);
await slider.click();
await driver.delayMs(70000);
await driver.pressBack();
await driver.delayMs(500);
Logger.info(TAG, `${BUNDLE}ThreadDataTransfer_001 end`);
done();
}
* DFXStateManagement 查看内容
*/
it(BUNDLE + "DFXStateManagement", 2, async (done: Function) => {

View File

@ -12,14 +12,14 @@
"name": "TestAbility_label",
"value": "test label"
},
{
"name": "MemoryShared",
"value": "MemoryShared"
},
{
"name": "permission_while_use",
"value": "仅使用期间允许"
},
{
"name": "MemoryShared",
"value": "MemoryShared"
},
{
"name": "atomic_operation",
"value": "原子操作对比"
@ -48,6 +48,58 @@
"name": "write_success",
"value": "写入文件成功"
},
{
"name": "thread_communication",
"value": "主线程和子线程的通信"
},
{
"name": "scenario_1",
"value": "场景一:独立的耗时任务"
},
{
"name": "scenario_2",
"value": "场景二:多个任务执行结果统一返回"
},
{
"name": "scenario_3",
"value": "场景三TaskPool和主线程的即时通信"
},
{
"name": "scenario_4",
"value": "场景四Worker和主线程的即时通信"
},
{
"name": "scenario_5",
"value": "场景五:子线程同步调用主线程的接口"
},
{
"name": "load_image",
"value": "加载图片"
},
{
"name": "change_image_number",
"value": "将图片变成4个"
},
{
"name": "saturation",
"value": "饱和度"
},
{
"name": "task_num",
"value": "任务数"
},
{
"name": "pass_params",
"value": "传参方式"
},
{
"name": "start_transfer",
"value": "通过转移方式传参"
},
{
"name": "running_time",
"value": "运行时间:"
},
{
"name": "web_uninitialized",
"value": "常规Web首页"