diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/AppScope/app.json5 b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/AppScope/app.json5 new file mode 100755 index 0000000..9e7a49f --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/AppScope/app.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 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.serviceextensiondemo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/AppScope/resources/base/element/string.json b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/AppScope/resources/base/element/string.json new file mode 100755 index 0000000..73a440d --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ServiceExtensionDemo" + } + ] +} diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/AppScope/resources/base/media/app_icon.png b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000..ce307a8 Binary files /dev/null and b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/AppScope/resources/base/media/app_icon.png differ diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/README_zh.md b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/README_zh.md new file mode 100644 index 0000000..867e527 --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/README_zh.md @@ -0,0 +1,29 @@ +# 跨设备绑定ServiceExtensionAbility示例 + +### 简介 +本示例展示了在eTS中如何构建stage模型跨设备绑定ServiceExtensionAbility,包含: + +1、远端实现待绑定 ServiceExtensionAbility + +2、申请分布式权限:DISTRIBUTED_DATASYNC + +3、发起端调用 context.connectAbility() 接口,传入 deviceId,bundleName,abilityName 绑定远端 ServiceExtensionAbility + +4、绑定成功获取远端 ServiceExtensionAbility 句柄,发起段使用句柄的 sendRequest() 接口调用远端定义的方法 + + +### 测试步骤 +1、两台设备都安装此应用,并组网成功(计算器可以跨端拉起) + +2、在设置里给予此应用分布式权限 + +3、设备 A 打开应用,选择待绑定设备 B 的 deviceId,点击 connect 按钮发起绑定 + +4、设备 A 日志区显示 “get proxy”,代表绑定成功 + +5、设备 A 在输入栏输入任意字符串,点击 send 按钮,信息被发送到远端设备 B + +6、设备 A 收到设备 B 的回复消息 “MyServiceExtensionAbility receive your message” + +### 约束与限制 +1、本示例仅支持标准系统上运行。 2、本示例为Stage模型,仅支持API version 9,IDE版本3.0.1.900以上,系统版本OpenHarmony3.1 release。 \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/build-profile.json5 b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/build-profile.json5 new file mode 100755 index 0000000..4f4576c --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/build-profile.json5 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 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": [], + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, + "products": [ + { + "name": "default", + "signingConfig": "default" + } + ], + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/build-profile.json5 b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/build-profile.json5 new file mode 100755 index 0000000..7d044e6 --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/build-profile.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022 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", + } + ] +} \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/hvigorfile.js b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/hvigorfile.js new file mode 100755 index 0000000..4300c6c --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/hvigorfile.js @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 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. + */ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/package-lock.json b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/package-lock.json new file mode 100755 index 0000000..6b5c677 --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "entry", + "version": "1.0.0", + "lockfileVersion": 1 +} diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/package.json b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/package.json new file mode 100755 index 0000000..3e64cf5 --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/package.json @@ -0,0 +1,14 @@ +{ + "license":"ISC", + "devDependencies":{}, + "name":"entry", + "ohos":{ + "org":"ohos", + "directoryLevel":"module", + "buildTool":"hvigor" + }, + "description":"example description", + "repository":{}, + "version":"1.0.0", + "dependencies":{} +} \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/Application/MyAbilityStage.ts b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100755 index 0000000..396606f --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/Application/MyAbilityStage.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/MainAbility/MainAbility.ts b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100755 index 0000000..d482754 --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2022 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. + */ +// @ts-nocheck + +import Ability from '@ohos.application.Ability' +import RemoteDeviceModel from '../Model/RemoteDeviceModel' +import rpc from '@ohos.rpc' + +var printLog = '[ServiceExtensionDemo]' +var remoteDeviceModel = new RemoteDeviceModel +var messageProxy = null +var connectedAbility + +var options = { + onConnect: async function (elementName, proxy) { + showLog("service extension ability connect success") + if (proxy === null) { + showLog("can not get proxy") + return + } + messageProxy = proxy + showLog("get proxy, elementName: " + elementName) + }, + onDisconnect: function () { + showLog("service extension ability disconnect success") + }, + onFailed: function () { + showLog("service extension ability connect fail") + } +} + +function ConnectRemoteAbility() { + showLog("connect service extension ability begin") + showLog("connect remote device id is " + globalThis.selectDevice) + let want = { + bundleName: "com.example.serviceextensiondemo", + abilityName: "MyServiceExtensionAbility", + deviceId: globalThis.selectDevice + } + connectedAbility = globalThis.context.connectAbility(want, options) + showLog("connect service extension ability, connectId = " + connectedAbility) +} + +async function DisconnectRemoteAbility() { + showLog("disconnect service extension ability begin") + showLog("disconnect remote device id is " + globalThis.selectDevice) + await globalThis.context.disconnectAbility(connectedAbility) + showLog("disconnect service extension ability, connectId = " + connectedAbility) + connectedAbility = null +} + +async function SendMessage() { + if (messageProxy === null) { + showLog("can not get proxy") + return + } + showLog("send message : " + AppStorage.Get("message")) + let option = new rpc.MessageOption() + let data = new rpc.MessageParcel() + let reply = new rpc.MessageParcel() + data.writeString(AppStorage.Get("message")) + + await messageProxy.sendRequest(1, data, reply, option) + showLog("send message success") + + globalThis.receiveMessage = reply.readString() + showLog("receive reply message : " + globalThis.receiveMessage) +} + +function showLog(logMessage) { + console.log(printLog + logMessage) + AppStorage.Set("receiveMessage", AppStorage.Get("receiveMessage") + logMessage + "\n") +} + +function RegisterDeviceListCallback() { + remoteDeviceModel.registerDeviceListCallback(() => { + let deviceSize = remoteDeviceModel.deviceList.length + for (var i = 0; i < deviceSize; i++) { + globalThis.DeviceIdList.push(remoteDeviceModel.deviceList[i].deviceId) + } + }) +} + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + console.log("[ServiceExtensionDemo] MainAbility onCreate") + globalThis.abilityWant = want; + globalThis.context = this.context + globalThis.DeviceIdList = [] + globalThis.selectDevice + globalThis.receiveMessage = "" + RegisterDeviceListCallback() + } + + onDestroy() { + AppStorage.Set("receiveMessage", "") + console.log("[ServiceExtensionDemo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[ServiceExtensionDemo] MainAbility onWindowStageCreate") + globalThis.ConnectRemoteAbility = ConnectRemoteAbility + globalThis.DisconnectRemoteAbility = DisconnectRemoteAbility + globalThis.SendMessage = SendMessage + windowStage.loadContent("pages/index", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[ServiceExtensionDemo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[ServiceExtensionDemo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[ServiceExtensionDemo] MainAbility onBackground") + } +}; diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/Model/RemoteDeviceModel.ts b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/Model/RemoteDeviceModel.ts new file mode 100755 index 0000000..d6ddd01 --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/Model/RemoteDeviceModel.ts @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 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 deviceManager from '@ohos.distributedHardware.deviceManager'; + +var SUBSCRIBE_ID = 100; + +export default class RemoteDeviceModel { + deviceList = []; + discoverList = []; + callback; + authCallback = null; + #deviceManager; + + constructor() { + } + + registerDeviceListCallback(callback) { + if (typeof (this.#deviceManager) === 'undefined') { + console.log('[ServiceExtensionDemo] deviceManager.createDeviceManager begin'); + let self = this; + deviceManager.createDeviceManager('com.example.serviceextensiondemo', (error, value) => { + if (error) { + console.error('createDeviceManager failed.'); + return; + } + self.#deviceManager = value; + self.registerDeviceListCallback_(callback); + console.log('[ServiceExtensionDemo] createDeviceManager callback returned, error=' + error + ' value=' + value); + }); + console.log('[ServiceExtensionDemo] deviceManager.createDeviceManager end'); + } else { + this.registerDeviceListCallback_(callback); + } + } + + registerDeviceListCallback_(callback) { + console.info('[ServiceExtensionDemo] registerDeviceListCallback'); + this.callback = callback; + if (this.#deviceManager == undefined) { + console.error('[ServiceExtensionDemo] deviceManager has not initialized'); + this.callback(); + return; + } + + console.info('[ServiceExtensionDemo] getTrustedDeviceListSync begin'); + var list = this.#deviceManager.getTrustedDeviceListSync(); + console.info('[ServiceExtensionDemo] getTrustedDeviceListSync end, deviceList=' + JSON.stringify(list)); + if (typeof (list) != 'undefined' && typeof (list.length) != 'undefined') { + this.deviceList = list; + } + this.callback(); + console.info('[ServiceExtensionDemo] callback finished'); + } + + getTrustDeviceList(callback) { + console.info('[ServiceExtensionDemo] getTrustDeviceListSync begin'); + var list = this.#deviceManager.getTrustedDeviceListSync(); + console.info('[ServiceExtensionDemo] getTrustedDeviceListSync end, deviceList=' + JSON.stringify(list)); + if (typeof (list) != 'undefined' && typeof (list.length) != 'undefined') { + this.deviceList = list; + } + + console.info('[ServiceExtensionDemo] getTrustDeviceListSync end'); + callback(); + } + + unregisterDeviceListCallback() { + console.info('[dmsDemo] stopDeviceDiscovery ' + SUBSCRIBE_ID); + this.#deviceManager.stopDeviceDiscovery(SUBSCRIBE_ID); + this.#deviceManager.off('deviceStateChange'); + this.#deviceManager.off('deviceFound'); + this.#deviceManager.off('discoverFail'); + this.#deviceManager.off('serviceDie'); + this.deviceList = []; + } +} \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/MyServiceExtensionAbility/MyServiceExtensionAbility.ts b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/MyServiceExtensionAbility/MyServiceExtensionAbility.ts new file mode 100755 index 0000000..76df4b9 --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/MyServiceExtensionAbility/MyServiceExtensionAbility.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 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. + */ +// @ts-nocheck + +import rpc from '@ohos.rpc'; +import ServiceExtensionAbility from '@ohos.application.ServiceExtensionAbility'; +var printLog = '[ServiceExtensionDemo]' + +class MyServiceExtensionAbilityStub extends rpc.RemoteObject { + constructor(des) { + super(des) + } + + onRemoteRequest(code, data, reply, option) { + console.log(printLog + "MyServiceExtensionAbility onRemoteRequest call") + if (code === 1) { + globalThis.receiveMessage = data.readString() + console.log(printLog + "receive message : " + globalThis.receiveMessage) + } else { + console.log(printLog + "unknown request code") + } + reply.writeString("MyServiceExtensionAbility receive your message") + return true + } + + queryLocalInterface(descriptor) { + return null + } + + getInterfaceDescriptor() { + return '' + } + + sendRequest(code, data, reply, option) { + return null + } + + getCallingPid() { + return 1 + } + + getCallingUid() { + return 1 + } + + attachLocalInterface(localInterface, descriptor) {} +} + +export default class MyServiceExtensionAbility extends ServiceExtensionAbility { + onCreate(want) { + console.log(printLog + 'MyServiceExtensionAbility OnCreate, want : ' + want.abilityName) + } + onRequest(want) { + console.log(printLog + 'MyServiceExtensionAbility onRequest, want : ' + want.abilityName) + } + onConnect(want) { + console.log(printLog + 'MyServiceExtensionAbility onConnect, want : ' + want.abilityName) + return new MyServiceExtensionAbilityStub('test') + } + onDisconnect(want) { + console.log(printLog + 'MyServiceExtensionAbility onDisconnect, want : ' + want.abilityName) + } + onDestroy() { + console.log(printLog + 'MyServiceExtensionAbility onDestroy') + } +} \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/pages/index.ets b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/pages/index.ets new file mode 100755 index 0000000..9b49353 --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/ets/pages/index.ets @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2022 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. + */ +// @ts-nocheck +var printLog = '[ServiceExtensionDemo]' +AppStorage.Link("message") +AppStorage.Link("receiveMessage") + +@Entry +@Component +struct Index { + @State selectDeviceName : string = "" + @StorageLink("message") message : string = "" + @StorageLink("receiveMessage") receiveMessage : string = "" + + build() { + Column() { + Row() { + Text("select device id : " + this.selectDeviceName) + .width('100%') + .height('100%') + .fontSize(20) + .textAlign(TextAlign.Start) + } + .height('10%') + .width('100%') + + Row() { + Column() { + Button('connect') + .width(100) + .height(50) + .onClick(() => { + globalThis.ConnectRemoteAbility() + }) + + Button('discon') + .width(100) + .height(50) + .onClick(() => { + globalThis.DisconnectRemoteAbility() + }) + + List({ space: 10, initialIndex: 0}) { + ForEach(globalThis.DeviceIdList, (item : string) => { + ListItem() { + Button(item) + .width('100%').height(50).fontSize(10) + .onClick(() => { + console.log(printLog + "select device : " + item) + AppStorage.Set('receiveMessage', AppStorage.Get("receiveMessage") + + "select device:" + item + '\n') + }) + }.editable(this.editFlag) + }, (item : string) => item.toString()) + }.height('100%').width('100%').borderWidth(1).align(ItemAlign.Start) + }.width('30%').height('100%').padding(5) + + Column() { + Text('日志') + .height('5%') + .width('100%') + .fontSize(20) + .borderWidth(1) + .textAlign(TextAlign.Center) + .backdropBlur(Color.Gray) + + Scroll() { + Text(this.receiveMessage) + .width('100%') + .fontSize(20) + .textAlign(TextAlign.Start) + }.scrollable(BarState.Auto) + .height('55%') + .align(ItemAlign.Start) + .borderWidth(1) + + Text("待发送数据:") + .height('5%') + .width('100%') + .fontSize(20) + .borderWidth(1) + .textAlign(TextAlign.Center) + .backgroundColor(Color.Gray) + + Text(this.message) + .height('10%') + .width('100%') + .fontSize(20) + .borderWidth(1) + .textAlign(TextAlign.Start) + + TextInput("输入消息") + .width('10%') + .height('100%') + .borderStyle(BorderStyle.Solid) + .type(InputType.Normal) + .onChange((value : string) => { + AppStorage.Set('message', value) + }) + + Row() { + Button('send') + .width(100) + .height(50) + .onClick(() => { + globalThis.SendMessage() + }) + }.height('15%') + }.width('70%') + }.width('100%').height('90%') + }.width('100%').height('100%') + } +} \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/module.json5 b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/module.json5 new file mode 100755 index 0000000..0f5c55d --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/module.json5 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 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", + "srcEntrance": "./ets/Application/MyAbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "MyServiceExtensionAbility", + "icon": "$media:icon", + "description": "service", + "type": "service", + "visible": true, + "srcEntrance": "./ets/MyServiceExtensionAbility/MyServiceExtensionAbility.ts" + }, + ], + "requestPermissions": [ + { + "name": "ohos.permission.DISTRIBUTED_DATASYNC" + } + ] + } +} \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/element/color.json b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000..62a137a --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/element/string.json b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000..fc57044 --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "ServiceExtensionDemo" + } + ] +} \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/media/icon.png b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000..ce307a8 Binary files /dev/null and b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/media/icon.png differ diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/profile/main_pages.json b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000..feec276 --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/hvigorfile.js b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/hvigorfile.js new file mode 100755 index 0000000..5dfbd26 --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/hvigorfile.js @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2022 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. + */ + +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').appTasks \ No newline at end of file diff --git a/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/package.json b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/package.json new file mode 100755 index 0000000..21886de --- /dev/null +++ b/services/dtbschedmgr/test/samples/ServiceExtenisonDemo/package.json @@ -0,0 +1,18 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "serviceextensiondemo", + "ohos": { + "org": "ohos", + "directoryLevel": "project", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "@ohos/hypium": "1.0.1", + "@ohos/hvigor-ohos-plugin": "1.1.6", + "@ohos/hvigor": "1.1.6" + } +}