diff --git a/ability/ability_runtime/actsusers/actsconnectabilitysystemabilitytest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts b/ability/ability_runtime/actsusers/actsconnectabilitysystemabilitytest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts index 7d3ea0dcf0c7064982e2fca9bee5e8dda80f90b5..b6d7515c05b17403eed25d20c133c67d6e80c1f4 100644 --- a/ability/ability_runtime/actsusers/actsconnectabilitysystemabilitytest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts +++ b/ability/ability_runtime/actsusers/actsconnectabilitysystemabilitytest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts @@ -16,31 +16,44 @@ import commonEvent from '@ohos.commonEvent' import ServiceExtension from '@ohos.application.ServiceExtensionAbility' import rpc from '@ohos.rpc'; var conn = -1; -function publishCallBackOne () { +function publishCallBackOne() { console.log("========Publish CallBack AMS_ConnectAbility_0100_commonEvent========"); } -function publishCallBackTwo () { +function publishCallBackTwo() { console.log("========Publish CallBack AMS_ConnectAbility_0200_commonEvent========"); } -function publishCallBackThree () { +function publishCallBackThree() { console.log("========Publish CallBack AMS_ConnectAbility_0300_commonEvent========"); } -function publishCallBackFour () { +function publishCallBackFour() { console.log("========Publish CallBack AMS_ConnectAbility_0400_commonEvent========"); } -function publishCallBackFive () { +function publishCallBackFive() { console.log("========Publish CallBack AMS_ConnectAbility_0500_commonEvent========"); } -function publishCallBackSix () { +function publishCallBackSix() { console.log("========Publish CallBack AMS_ConnectAbility_0600_commonEvent========"); } -function publishCallBackzero () { +function publishCallBackzero() { console.log("========Publish CallBack AMSc_disonnectAbility_0100_commonEvent========"); } -function publishCallBackttwo () { +function publishCallBackttwo() { console.log("========Publish CallBack AMSc_disonnectAbility_0200_commonEvent========"); } +function onConnectCallback(element, remote) { + console.log('onConnectCallback====> element=' + JSON.stringify(element)); + console.log('onConnectCallback====> remote=' + JSON.stringify(remote)); +} + +function onDisconnectCallback(element) { + console.log('onDisconnectCallback====> element=' + JSON.stringify(element)); +} + +function onFailedCallback(code) { + console.log('onFailedCallback====> code=' + JSON.stringify(code)) +} + export default class ServiceAbility extends ServiceExtension { onCreate(want) { console.log('ServiceAbility onCreate, want: ' + want.abilityName); @@ -85,7 +98,11 @@ export default class ServiceAbility extends ServiceExtension { { bundleName: "com.example.actsconnectabilitysystemabilitytest", abilityName: "com.example.actsconnectabilitysystemabilitytest.ServiceAbility2", - } + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); }; if (want.action == "Eight") { @@ -93,7 +110,11 @@ export default class ServiceAbility extends ServiceExtension { { bundleName: "com.example.actsconnectabilitysystemabilitytest", abilityName: "com.example.actsconnectabilitysystemabilitytest.ServiceAbility3", - } + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); }; if (want.action == "Nine") { @@ -102,12 +123,16 @@ export default class ServiceAbility extends ServiceExtension { { bundleName: 'com.example.actsconnectabilitysystemabilitytest', abilityName: 'com.example.actsconnectabilitysystemabilitytest.ServiceAbility2' - }) - setTimeout(()=>{ - extensionContext.disconnectAbility(num).then(()=>{ + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + }) + setTimeout(() => { + extensionContext.disconnectAbility(num).then(() => { console.log('in disconnectAbility'); }) - },1000) + }, 1000) }; if (want.action == "Ten") { @@ -116,12 +141,16 @@ export default class ServiceAbility extends ServiceExtension { { bundleName: 'com.example.actsconnectabilitysystemabilitytest', abilityName: 'com.example.actsconnectabilitysystemabilitytest.ServiceAbility2' - }) - setTimeout(()=>{ - extensionContext.disconnectAbility(num).then(()=>{ + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + }) + setTimeout(() => { + extensionContext.disconnectAbility(num).then(() => { console.log('in disconnectAbility2'); }) - },1000) + }, 1000) }; if (want.action == "Ten one") { @@ -130,12 +159,16 @@ export default class ServiceAbility extends ServiceExtension { { bundleName: 'com.example.actsconnectabilitysystemabilitytest', abilityName: 'com.example.actsconnectabilitysystemabilitytest.ServiceAbility2' - }) - setTimeout(()=>{ - extensionContext.disconnectAbility(2222).then(()=>{ + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + }) + setTimeout(() => { + extensionContext.disconnectAbility(2222).then(() => { console.log('in disconnectAbility3'); }) - },1000) + }, 1000) }; if (want.action == "Ten two") { @@ -144,12 +177,16 @@ export default class ServiceAbility extends ServiceExtension { { bundleName: 'com.example.actsconnectabilitysystemabilitytest', abilityName: 'com.example.actsconnectabilitysystemabilitytest.ServiceAbility2' - }) - setTimeout(()=>{ - extensionContext.disconnectAbility(2222).then(()=>{ + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + }) + setTimeout(() => { + extensionContext.disconnectAbility(2222).then(() => { console.log('in disconnectAbility4'); }) - },1000) + }, 1000) }; return new rpc.RemoteObject('connect'); @@ -157,8 +194,8 @@ export default class ServiceAbility extends ServiceExtension { onDisconnect(want) { console.log('ServiceAbility onDisconnect, want:' + want.abilityName); - commonEvent.publish("AMSc_disonnectAbility_0100_commonEvent",publishCallBackzero); - commonEvent.publish("AMSc_disonnectAbility_0200_commonEvent",publishCallBackttwo); + commonEvent.publish("AMSc_disonnectAbility_0100_commonEvent", publishCallBackzero); + commonEvent.publish("AMSc_disonnectAbility_0200_commonEvent", publishCallBackttwo); } onDestroy() { diff --git a/ability/ability_runtime/actsusers/actsconnectabilitysystemabilitytest/entry/src/main/ets/pages/index/index.ets b/ability/ability_runtime/actsusers/actsconnectabilitysystemabilitytest/entry/src/main/ets/pages/index/index.ets index 85d2f648a55a82c8f8d4abd60faa6c35433363de..deb36d6e373e96df2187afa8f50ab06d6e656e81 100644 --- a/ability/ability_runtime/actsusers/actsconnectabilitysystemabilitytest/entry/src/main/ets/pages/index/index.ets +++ b/ability/ability_runtime/actsusers/actsconnectabilitysystemabilitytest/entry/src/main/ets/pages/index/index.ets @@ -13,7 +13,7 @@ * limitations under the License. */ import file from '@system.file'; -import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets" +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" import testsuite from "../../test/List.test.ets" @Entry