diff --git a/appexecfwk/ams_standard/BUILD.gn b/appexecfwk/ams_standard/BUILD.gn index db5a1e7479f610c7a9e0021665408d0cf93da95f..1de9e56759968a710a6f67c37061bd237a0c39ae 100644 --- a/appexecfwk/ams_standard/BUILD.gn +++ b/appexecfwk/ams_standard/BUILD.gn @@ -26,6 +26,7 @@ group("ams_standard") { "serviceability/sceneProject/particletestserver:ParticleTestServer", "serviceability/stserviceabilityclient:amsStServiceAbilityClient", "serviceability/stserviceabilityserver:amsStServiceAilityServer", + "serviceability/stserviceabilityserversecond:stserviceabilityserversecond", ] } } diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityclient/entry/src/main/js/test/StServiceAbilityClient.test.js b/appexecfwk/ams_standard/serviceability/stserviceabilityclient/entry/src/main/js/test/StServiceAbilityClient.test.js index c7025c26541414fc6603b42be5b0e326825c1950..92c1af547e8408b35e2c90c587815497d3855518 100755 --- a/appexecfwk/ams_standard/serviceability/stserviceabilityclient/entry/src/main/js/test/StServiceAbilityClient.test.js +++ b/appexecfwk/ams_standard/serviceability/stserviceabilityclient/entry/src/main/js/test/StServiceAbilityClient.test.js @@ -12,54 +12,411 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import rpc from "@ohos.rpc"; import featureAbility from '@ohos.ability.featureAbility' -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import commonEvent from '@ohos.commonevent' + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' describe('ActsStServiceAbilityTest', function () { let bundleName = "com.amsst.stserviceabilityserver"; let abilityName = "com.amsst.stserviceabilityserver.MainAbility"; - let g_setTimeout = 10 - var mConnIdJsPromise; - var mConnIdJsCallback; - var mRemote; - - function onConnectCallback(element, remote){ - console.log('ACTS_featureAbilityTest ConnectAbility onConnect element.deviceId : ' + element.deviceId) - console.log('ACTS_featureAbilityTest ConnectAbility onConnect element.bundleName : ' + element.bundleName) - console.log('ACTS_featureAbilityTest ConnectAbility onConnect element.abilityName : ' + element.abilityName) - console.log('ACTS_featureAbilityTest ConnectAbility onConnect element.uri : ' + element.uri) - console.log('ACTS_featureAbilityTest ConnectAbility onConnect element.shortName : ' + element.shortName) - console.log('ACTS_featureAbilityTest ConnectAbility onConnect remote : ' + remote); - mRemote = remote; - console.log('ACTS_featureAbilityTest ConnectAbility onConnect remote 是否为proxy:' + (remote instanceof rpc.RemoteProxy)); - } - function onDisconnectCallback(element){ - console.log('ACTS_featureAbilityTest ConnectAbility onDisconnect element.deviceId : ' + element.deviceId) - console.log('ACTS_featureAbilityTest ConnectAbility onDisconnect element.bundleName : ' + element.bundleName) - console.log('ACTS_featureAbilityTest ConnectAbility onDisconnect element.abilityName : ' + element.abilityName) - console.log('ACTS_featureAbilityTest ConnectAbility onDisconnect element.uri : ' + element.uri) - console.log('ACTS_featureAbilityTest ConnectAbility onDisconnect element.shortName : ' + element.shortName) - } + var subscriber_0100; + var CommonEventSubscribeInfo_0100 = { + events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0100", + ], + }; + var subscriber_0200; + var CommonEventSubscribeInfo_0200 = { + events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0200", + ], + }; + var subscriber_0300; + var CommonEventSubscribeInfo_0300 = { + events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0300", + "ACTS_SerivceAbilityServer_onCommand_PageStartService_0301", + ], + }; + var subscriber_0400; + var CommonEventSubscribeInfo_0400 = { + events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0400", + "ACTS_SerivceAbilityServer_onCommand_PageStartService_0401", + ], + }; + var subscriber_0500; + var CommonEventSubscribeInfo_0500 = { + events: ["ACTS_SerivceAbilityServer_onConnect_PageConnectService_0500", + "ACTS_SerivceAbilityServer_onDisConnect", + ], + }; + var subscriber_0600; + var CommonEventSubscribeInfo_0600 = { + events: ["ACTS_SerivceAbilityServer_onConnect_PageConnectService_0600", + "ACTS_SerivceAbilityServer_onDisConnect", + ], + }; + var subscriber_0900; + var CommonEventSubscribeInfo_0900 = { + events: ["ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_0900", + ], + }; + var subscriber_1000; + var CommonEventSubscribeInfo_1000 = { + events: ["ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_1000", + ], + }; + var subscriber_1300; + var CommonEventSubscribeInfo_1300 = { + events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1300", + "ACTS_SerivceAbilityServerSecond_onDisConnect", + ], + }; + var subscriber_1400; + var CommonEventSubscribeInfo_1400 = { + events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1400", + "ACTS_SerivceAbilityServerSecond_onDisConnect", + ], + }; + var subscriber_1500; + var CommonEventSubscribeInfo_1500 = { + events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1500", + "ACTS_SerivceAbilityServer_onDisConnect", + ], + }; - function onFailedCallback(code){ - console.log('ACTS_featureAbilityTest ConnectAbility onFailed errCode : ' + code) + function unsubscribe(caller, subscriber) { + commonEvent.unsubscribe(subscriber, (err, data) => { + console.debug("=ACTS_unsubscribe (err,data)=======>" + + (caller) + + (" , json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + }); } + let g_setTimeout = 1000 + beforeAll(async (done) => { + console.debug('= ACTS_beforeAll ==== { + setTimeout(function () { + done(); + }, g_setTimeout); + }) + afterEach(async (done) => { + setTimeout(function () { + done(); + }, g_setTimeout); + }) + afterAll((done) => { + console.debug('= ACTS_afterAll ==== { + console.debug("=ACTS_JsServiceAbility_0100 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber_0100 = data; + await commonEvent.subscribe(subscriber_0100, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_0100 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + expect("ACTS_SerivceAbilityServer_onCommand_PageStartService_0100").assertEqual( + data.event); + unsubscribe("ACTS_JsServiceAbility_0100_unsubscribe", subscriber_0100); + console.debug('ACTS_JsServiceAbility_0100==== { + console.debug("=ACTS_JsServiceAbility_0100 .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + }).catch(err => { + expect(".catch").assertEqual(err); + console.debug('ACTS_JsServiceAbility_0100==== { + console.debug("=ACTS_JsServiceAbility_0200 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber_0200 = data; + await commonEvent.subscribe(subscriber_0200, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_0200 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + expect("ACTS_SerivceAbilityServer_onCommand_PageStartService_0200").assertEqual( + data.event); + unsubscribe("ACTS_JsServiceAbility_0200_unsubscribe", subscriber_0200); + console.debug('ACTS_JsServiceAbility_0200==== { + console.debug("=ACTS_JsServiceAbility_0200 startAbility (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + } + ) + } catch (err) { + expect("catch").assertEqual(err); + console.debug('ACTS_JsServiceAbility_0200==== { + console.debug("=ACTS_JsServiceAbility_0300 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber_0300 = data; + await commonEvent.subscribe(subscriber_0300, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_0300 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + if (data.event == "ACTS_SerivceAbilityServer_onCommand_PageStartService_0300") { + expect("ACTS_SerivceAbilityServer_onCommand_PageStartService_0300").assertEqual( + data.event); + featureAbility.startAbility( + { + want: + { + bundleName: bundleName, + abilityName: abilityName, + action: "PageStartService_0301", + }, + } + ).then(data => { + console.debug("=ACTS_JsServiceAbility_0300 .then(data) 2=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + }).catch(err => { + expect(".catch").assertEqual(err); + console.debug('ACTS_JsServiceAbility_0300==== { + console.debug("=ACTS_JsServiceAbility_0300 .then(data) 1=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + }).catch(err => { + expect(".catch").assertEqual(err); + console.debug('ACTS_JsServiceAbility_0300==== { + console.debug("=ACTS_JsServiceAbility_0400 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber_0400 = data; + await commonEvent.subscribe(subscriber_0400, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_0400 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + if (data.event == "ACTS_SerivceAbilityServer_onCommand_PageStartService_0400") { + expect("ACTS_SerivceAbilityServer_onCommand_PageStartService_0400").assertEqual( + data.event); + featureAbility.startAbility( + { + want: + { + bundleName: bundleName, + abilityName: abilityName, + action: "PageStartService_0401", + }, + }, (err, data) => { + console.debug("=ACTS_JsServiceAbility_0400 startAbility (err,data) 2=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + } + ) + } else { + expect("ACTS_SerivceAbilityServer_onCommand_PageStartService_0401").assertEqual( + data.event); + unsubscribe("ACTS_JsServiceAbility_0400_unsubscribe", subscriber_0400); + console.debug('ACTS_JsServiceAbility_0400==== { + console.debug("=ACTS_JsServiceAbility_0400 startAbility (err,data) 1=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + } + ) + } catch (err) { + expect("catch").assertEqual(err); + console.debug('ACTS_JsServiceAbility_0400==== { + console.debug("=ACTS_JsServiceAbility_0500 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber_0500 = data; + await commonEvent.subscribe(subscriber_0500, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_0500 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + if (data.event != "ACTS_SerivceAbilityServer_onDisConnect") { + expect("ACTS_SerivceAbilityServer_onConnect_PageConnectService_0500").assertEqual( + data.event); + featureAbility.disconnectAbility(mConnIdJsPromise).then(() => { + }).catch(err => { + expect(".catch").assertEqual(err); + console.debug('ACTS_JsServiceAbility_0500==== mConnIdJsPromise=' + + JSON.stringify(mConnIdJsPromise) + " , " + mConnIdJsPromise); + console.debug('ACTS_JsServiceAbility_0500_onConnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + console.debug('ACTS_JsServiceAbility_0500_onConnectCallback ====> remote=' + + JSON.stringify(remote) + " , " + remote); + console.debug('ACTS_JsServiceAbility_0500_onConnectCallback ====> remote is proxy:' + + (remote instanceof rpc.RemoteProxy)); + } + + function onDisconnectCallback(element) { + console.debug('ACTS_JsServiceAbility_0500_onDisconnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + } + + function onFailedCallback(code) { + console.debug('ACTS_JsServiceAbility_0500_onFailedCallback ====> code=' + + JSON.stringify(code) + " , " + code) + } -/* -* @tc.number: ACTS_ConnectAbility_0100 -* @tc.name: ConnectAbility : Connects an ability to a Service ability. -* @tc.desc: Check the return value of the interface (by Promise) -*/ - it('ACTS_ConnectAbility_0100',0, async function (done) { - console.log('ACTS_ConnectAbility_0100====" -// + (" json data 【") + JSON.stringify(data)+ (" 】; ====>")+data); -// expect(typeof(data)).assertEqual("object"); -// console.log('=ACTS_ConnectAbility_0100 promise mConnIdJsPromise)====>:' + JSON.stringify(mConnIdJsPromise)+","+mConnIdJsPromise); -// ret = true; -// done() -// }).catch(function (err){ -// console.debug("=ACTS_ConnectAbility_0100 catch err====>" -// + ("json err 【") + JSON.stringify(err) + (" 】 ====>")+err); -// console.log('=ACTS_ConnectAbility_0100 mConnIdJsPromise====>:' + JSON.stringify(mConnIdJsPromise)) -// ret = false; -// done(); -// }); - ret = true; - done() - }catch(err) { - console.error('=ACTS_ConnectAbility_0100 catch(err)====>:' - + ("json err 【") + JSON.stringify(err) + (" 】 ,")+err); - ret = false; + } catch (err) { + expect("catch").assertEqual(err); + console.log('ACTS_JsServiceAbility_0500==== { + console.debug("=ACTS_JsServiceAbility_0600 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber_0600 = data; + await commonEvent.subscribe(subscriber_0600, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_0600 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + if (data.event != "ACTS_SerivceAbilityServer_onDisConnect") { + expect("ACTS_SerivceAbilityServer_onConnect_PageConnectService_0600").assertEqual( + data.event); + featureAbility.disconnectAbility(mConnIdJsAsyncCallback, (err) => { + console.debug("=ACTS_JsServiceAbility_0600 disconnectAbility err====>" + + ("json err=") + JSON.stringify(err)); + }) + } else { + expect("ACTS_SerivceAbilityServer_onDisConnect").assertEqual( + data.event); + unsubscribe("ACTS_JsServiceAbility_0600_unsubscribe", subscriber_0600); + console.log('ACTS_JsServiceAbility_0600==== mConnIdJsAsyncCallback=' + + JSON.stringify(mConnIdJsAsyncCallback) + " , " + mConnIdJsAsyncCallback); + console.debug('ACTS_JsServiceAbility_0600_onConnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + console.debug('ACTS_JsServiceAbility_0600_onConnectCallback ====> remote=' + + JSON.stringify(remote) + " , " + remote); + console.debug('ACTS_JsServiceAbility_0600_onConnectCallback ====> remote is proxy:' + + (remote instanceof rpc.RemoteProxy)); + } + + function onDisconnectCallback(element) { + console.debug('ACTS_JsServiceAbility_0600_onDisconnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + } + + function onFailedCallback(code) { + console.debug('ACTS_JsServiceAbility_0600_onFailedCallback ====> code=' + + JSON.stringify(code) + " , " + code) + } + + mConnIdJsAsyncCallback = featureAbility.connectAbility( + { + bundleName: bundleName, + abilityName: abilityName, + action: "PageConnectService_0600", + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, + }, + ) + } catch (err) { + expect("catch").assertEqual(err); + console.log('ACTS_JsServiceAbility_0600====' + mConnIdJsPromise); - var result = featureAbility.disconnectAbility( - mConnIdJsPromise, - ).then(function (data) { - console.debug("=ACTS_DisconnectAbility_0100 then data====>" - + (" json data 【") + JSON.stringify(data)+ (" 】; ====>")+data); - expect(typeof(data)).assertEqual("object"); - console.log('=ACTS_DisconnectAbility_0100 promise result)====>:' + JSON.stringify(result)+","+result); - ret = true; - done() - }).catch(function (err){ - console.debug("=ACTS_DisconnectAbility_0100 catch err====>" - + ("json err 【") + JSON.stringify(err) + (" 】 ====>")+err); - console.log('=ACTS_DisconnectAbility_0100 result====>:' + JSON.stringify(result)) - ret = false; + * @tc.number: ACTS_JsServiceAbility_0900 + * @tc.name: particleability.startAbility : Use page to test startAbiltiy service. + * @tc.desc: Check the return value of the interface (by Promise) + */ + it('ACTS_JsServiceAbility_0900', 0, async function (done) { + console.debug('ACTS_JsServiceAbility_0900==== { + console.debug("=ACTS_JsServiceAbility_0900 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber_0900 = data; + await commonEvent.subscribe(subscriber_0900, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_0900 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + expect("ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_0900").assertEqual( + data.event); + unsubscribe("ACTS_JsServiceAbility_0900_unsubscribe", subscriber_0900); + console.debug('ACTS_JsServiceAbility_0900==== { + console.debug("=ACTS_JsServiceAbility_0900 .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + }).catch(err => { + expect(".catch").assertEqual(err); + console.debug('ACTS_JsServiceAbility_0900====: ' - + ("json result 【") + JSON.stringify(result) + (" 】 ,")+result); - }catch(err) { - console.error('=ACTS_DisconnectAbility_0100 catch(err)====>:' - + ("json err 【") + JSON.stringify(err) + (" 】 ,")+err); - ret = false; + }) + } catch (err) { + expect("catch").assertEqual(err); + console.debug('ACTS_JsServiceAbility_0900==== { + console.debug("=ACTS_JsServiceAbility_1000 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber_1000 = data; + await commonEvent.subscribe(subscriber_1000, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_1000 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + expect("ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_1000").assertEqual( + data.event); + unsubscribe("ACTS_JsServiceAbility_1000_unsubscribe", subscriber_1000); + console.debug('ACTS_JsServiceAbility_1000==== { + console.debug("=ACTS_JsServiceAbility_1000 startAbility (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + } + ) + } catch (err) { + expect("catch").assertEqual(err); + console.debug('ACTS_JsServiceAbility_1000==== { + console.debug("=ACTS_JsServiceAbility_1300 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber_1300 = data; + await commonEvent.subscribe(subscriber_1300, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_1300 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + if (data.event != "ACTS_SerivceAbilityServerSecond_onDisConnect") { + expect("ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1300" + ).assertEqual(data.event); + featureAbility.disconnectAbility(mConnIdJsPromise).then((err) => { + console.debug("=ACTS_JsServiceAbility_1300 disconnectAbility err====>" + + ("json err=") + JSON.stringify(err)); + }) + } else { + expect("ACTS_SerivceAbilityServerSecond_onDisConnect").assertEqual( + data.event); + unsubscribe("ACTS_JsServiceAbility_1300_unsubscribe", subscriber_1300); + console.log('ACTS_JsServiceAbility_1300==== mConnIdJsPromise=' + + JSON.stringify(mConnIdJsPromise) + " , " + mConnIdJsPromise); + console.debug('ACTS_JsServiceAbility_1300_onConnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + console.debug('ACTS_JsServiceAbility_1300_onConnectCallback ====> remote=' + + JSON.stringify(remote) + " , " + remote); + console.debug('ACTS_JsServiceAbility_1300_onConnectCallback ====> remote is proxy:' + + (remote instanceof rpc.RemoteProxy)); + } + + function onDisconnectCallback(element) { + console.debug('ACTS_JsServiceAbility_1300_onDisconnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + unsubscribe("ACTS_JsServiceAbility_1300_unsubscribe", subscriber_1300); + console.log('ACTS_JsServiceAbility_1300==== code=' + + JSON.stringify(code) + " , " + code) + } + + mConnIdJsPromise = featureAbility.connectAbility( { bundleName: bundleName, abilityName: abilityName, + action: "ServiceConnectService_1300", }, { onConnect: onConnectCallback, onDisconnect: onDisconnectCallback, onFailed: onFailedCallback, }, - // (err,data) => { - // console.debug("=ACTS_ConnectAbility_0200 connectAbility err,data====>" - // + ("json err【") + JSON.stringify(err) + (" 】json data【") + JSON.stringify(data)+ (" 】;")); - // ret = true; - // done() - // }, ) - ret = true; - done() - }catch(err) { - console.error('=ACTS_ConnectAbility_0200 catch(err)====>:' - + ("json err 【") + JSON.stringify(err) + (" 】 ,")+err); - ret = false; + } catch (err) { + expect("catch").assertEqual(err); + console.log('ACTS_JsServiceAbility_1300====' + mConnIdJsCallback); - var result = featureAbility.disconnectAbility( - mConnIdJsCallback, -// { -// onConnect: onConnectCallback, -// onDisconnect: onDisconnectCallback, -// onFailed: onFailedCallback, -// }, - (err,data) => { - console.debug("=ACTS_DisconnectAbility_0200 disconnectAbility err,data====>" - + ("json err【") + JSON.stringify(err) + (" 】json data【") + JSON.stringify(data)+ (" 】;")); - ret = true; - done() + * @tc.number: ACTS_JsServiceAbility_1400 + * @tc.name: particleability.ConnectAbility : Connects an ability to a Service ability. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + */ + it('ACTS_JsServiceAbility_1400', 0, async function (done) { + console.log('ACTS_JsServiceAbility_1400==== { + console.debug("=ACTS_JsServiceAbility_1400 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber_1400 = data; + await commonEvent.subscribe(subscriber_1400, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_1400 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + if (data.event != "ACTS_SerivceAbilityServerSecond_onDisConnect") { + expect("ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1400" + ).assertEqual(data.event); + featureAbility.disconnectAbility(mConnIdJsAsyncCallback, (err) => { + console.debug("=ACTS_JsServiceAbility_1400 disconnectAbility err====>" + + ("json err=") + JSON.stringify(err)); + }) + } else { + expect("ACTS_SerivceAbilityServerSecond_onDisConnect").assertEqual( + data.event); + unsubscribe("ACTS_JsServiceAbility_1400_unsubscribe", subscriber_1400); + console.log('ACTS_JsServiceAbility_1400==== mConnIdJsAsyncCallback=' + + JSON.stringify(mConnIdJsAsyncCallback) + " , " + mConnIdJsAsyncCallback); + console.debug('ACTS_JsServiceAbility_1400_onConnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + console.debug('ACTS_JsServiceAbility_1400_onConnectCallback ====> remote=' + + JSON.stringify(remote) + " , " + remote); + console.debug('ACTS_JsServiceAbility_1400_onConnectCallback ====> remote is proxy:' + + (remote instanceof rpc.RemoteProxy)); + } + + function onDisconnectCallback(element) { + console.debug('ACTS_JsServiceAbility_1400_onDisconnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + } + + function onFailedCallback(code) { + console.debug('ACTS_JsServiceAbility_1400_onFailedCallback ====> code=' + + JSON.stringify(code) + " , " + code) + } + + mConnIdJsAsyncCallback = featureAbility.connectAbility( + { + bundleName: bundleName, + abilityName: abilityName, + action: "ServiceConnectService_1400", + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, }, - ); - console.log('=ACTS_DisconnectAbility_0200 result ====>: ' - + ("json result 【") + JSON.stringify(result) + (" 】 ,")+result); - }catch(err) { - console.error('=ACTS_DisconnectAbility_0200 catch(err)====>:' - + ("json err 【") + JSON.stringify(err) + (" 】 ,")+err); - ret = false; + ) + } catch (err) { + expect("catch").assertEqual(err); + console.log('ACTS_JsServiceAbility_1400==== { + console.debug("=ACTS_JsServiceAbility_1500 createSubscriber .then(data)=======>" + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,data=" + data); + subscriber_1500 = data; + await commonEvent.subscribe(subscriber_1500, async (err, data) => { + console.debug("=ACTS_JsServiceAbility_1500 subscribe (err,data)=======>" + + ("json err【") + JSON.stringify(err) + (" 】") + + ("json data【") + JSON.stringify(data) + (" 】") + + " ,err=" + err + " ,data=" + data); + if (data.event != "ACTS_SerivceAbilityServer_onDisConnect") { + expect("ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1500").assertEqual( + data.event); + featureAbility.disconnectAbility(mConnIdJsPromise).then(() => { + }).catch(err => { + expect(".catch").assertEqual(err); + console.debug('ACTS_JsServiceAbility_1500==== mConnIdJsPromise=' + + JSON.stringify(mConnIdJsPromise) + " , " + mConnIdJsPromise); + console.debug('ACTS_JsServiceAbility_1500_onConnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + console.debug('ACTS_JsServiceAbility_1500_onConnectCallback ====> remote=' + + JSON.stringify(remote) + " , " + remote); + } + + function onDisconnectCallback(element) { + console.debug('ACTS_JsServiceAbility_1500_onDisconnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + unsubscribe("ACTS_JsServiceAbility_1500_unsubscribe", subscriber_1500); + console.log('ACTS_JsServiceAbility_1500==== code=' + + JSON.stringify(code) + " , " + code) + } + + mConnIdJsPromise = featureAbility.connectAbility( + { + bundleName: bundleName, + abilityName: abilityName, + action: "ServiceConnectService_1500", + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, + }, + ) + } catch (err) { + expect("catch").assertEqual(err); + console.log('ACTS_JsServiceAbility_1500====onReconnect=' + + want + " , JSON." + JSON.stringify(want)); + commonEvent.publish("ACTS_SerivceAbilityServer_onReconnect" + "_" + want.action, (err) => { }); + }, + onActive() { + console.debug('ACTS_SerivceAbilityServer ==== { }); + }, + onCommand(want, restart, startId) { + console.debug('ACTS_SerivceAbilityServer ====>onCommand=' + + "JSON(want)=" + JSON.stringify(want) + + " ,restart=" + restart + " ,startId=" + startId); + if (want.action == 'ServiceStartService_0900') { + particleAbility.startAbility( + { + want: + { + bundleName: serversecond_bundleName, + abilityName: serversecond_abilityName, + action: "ServiceStartService_0900", + }, } - return null; - } - onRemoteRequest(code, message, reply, option) { - console.log("RPCTestServer onRemoteRequest code:" + code); - if (code === 1) { - console.log("RPCTestServer: 调用到方法"); - let getContextObject = rpc.IPCSkeleton.getContextObject(); - console.log("RPCTestServer: getContextObject 方法调用的结果为: " + getContextObject); - let getCallingPid = rpc.IPCSkeleton.getCallingPid(); - console.log("RPCTestServer: getCallingPid 方法调用的结果为: " + getCallingPid); - let getCallingUid = rpc.IPCSkeleton.getCallingUid(); - console.log("RPCTestServer: getCallingUid 方法调用的结果为: " + getCallingUid); - let getCallingDeviceID = rpc.IPCSkeleton.getCallingDeviceID(); - console.log("RPCTestServer: getCallingDeviceID 方法调用的结果为: " + getCallingDeviceID); - let getLocalDeviceID = rpc.IPCSkeleton.getLocalDeviceID(); - console.log("RPCTestServer: getLocalDeviceID 方法调用的结果为: " + getLocalDeviceID); - let isLocalCalling = rpc.IPCSkeleton.isLocalCalling(); - console.log("RPCTestServer: isLocalCalling 方法调用的结果为: " + isLocalCalling); - let remoteObject = new rpc.RemoteObject("aaa",3); - let flushCommands = rpc.IPCSkeleton.flushCommands(remoteObject); - console.log("RPCTestServer: flushCommands 方法调用的结果为: " + flushCommands); - let resetCallingIdentity = rpc.IPCSkeleton.resetCallingIdentity(); - console.log("RPCTestServer: resetCallingIdentity 方法调用的结果为: " + resetCallingIdentity); - let setCallingIdentity = rpc.IPCSkeleton.setCallingIdentity("aaa", 3); - console.log("RPCTestServer: setCallingIdentity 方法调用的结果为: " + setCallingIdentity); - let num = message.readInt(); - let msg = message.readString(); - console.log("num is " + num + "msg is " + msg); - reply.writeString("Success"); - return true; + ); + featureAbility.terminateSelf(); + } else if (want.action == 'ServiceStartService_1000') { + particleAbility.startAbility( + { + want: + { + bundleName: serversecond_bundleName, + abilityName: serversecond_abilityName, + action: "ServiceStartService_1000", + }, + }, (err, data) => { + console.debug('ACTS_SerivceAbilityServer start Ability 1000 callback=====' + + err + ', data= ' + data + " , JSON." + JSON.stringify(data)); + featureAbility.terminateSelf(); } - } + ); + } else { + commonEvent.publish("ACTS_SerivceAbilityServer_onCommand" + "_" + want.action, (err) => { + if (!err.code) { + if (want.action == 'PageStartService_0100' || want.action == 'PageStartService_0200' + || want.action == 'PageStartService_0301' || want.action == 'PageStartService_0401') { + console.debug('ACTS_SerivceAbilityServer_onCommand 100 200 301 401.terminateSelf()=====>' + + want.action); + featureAbility.terminateSelf(); + } + } else { + console.debug('ACTS_SerivceAbilityServer_onCommand publish err=====>' + err); + } + }); } - - console.log("RPCTestServer: 判断其是否可以创建对象") - mMyStub = new MyStub("ServiceAbility-test"); - console.log("xxx RPCTestServer: 创建的对象为:" + mMyStub) - // console.log("RPCTestServer: 向saMgr中注册stub"); - // let result = rpc.IPCSkeleton.addLocalAbility(mMyStub); - // console.log("RPCTestServer: 注册的结果为:" + result); - - // mMyProxy = rpc.IPCSkeleton.getLocalAbility(); - // console.log("RPCTestProxy: 判断当前获取的对象是不是proxy:" + (mMyProxy instanceof rpc.RemoteProxy)); }, - onReady() { - console.info('SerivceAbilityServer onReady'); + onStart(want) { + console.debug('ACTS_SerivceAbilityServer ====>onStart=' + + want + " , JSON." + JSON.stringify(want)); + commonEvent.publish("ACTS_SerivceAbilityServer_onStart", (err) => { }); + class MyStub extends rpc.RemoteObject { + constructor(des) { super(des); } + } + console.debug("ACTS_SerivceAbilityServer ====< RPCTestServer"); + mMyStub = new MyStub("ServiceAbility-test"); + console.debug("ACTS_SerivceAbilityServer RPCTestServer: mMyStub:" + mMyStub + + " , " + JSON.stringify(mMyStub)) }, - onStop() { - console.info('SerivceAbilityServer onStop'); + console.debug('ACTS_SerivceAbilityServer ==== { }); + featureAbility.terminateSelf(); }, onConnect(want) { - console.info('stub SerivceAbilityServer OnConnect'); + console.debug('ACTS_SerivceAbilityServer ====>onConnect=' + + want + " , JSON." + JSON.stringify(want)); + function onConnectCallback(element, remote) { + console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> mConnIdJs=' + + JSON.stringify(mConnIdJs) + " , " + mConnIdJs); + console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> remote=' + + JSON.stringify(remote) + " , " + remote); + } + function onDisconnectCallback(element) { + console.debug('ACTS_SerivceAbilityServer_onDisconnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + } + function onFailedCallback(code) { + console.debug('ACTS_SerivceAbilityServer_onFailedCallback ====> code=' + + JSON.stringify(code) + " , " + code) + } + if (want.action == 'ServiceConnectService_1300' || want.action == 'ServiceConnectService_1400' + || want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1600') { + mConnIdJs = particleAbility.connectAbility( + { + bundleName: serversecond_bundleName, + abilityName: serversecond_abilityName, + action: want.action, + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, + }, + ) + } else { + commonEvent.publish("ACTS_SerivceAbilityServer_onConnect" + "_" + want.action, (err) => { }); + } return mMyStub; }, - onReconnect(want) { - console.info('SerivceAbilityServer onReconnect'); - }, - onDisconnect() { - console.info('SerivceAbilityServer OnDisConnect'); + OnAbilityConnectDone(element, remoteObject, resultCode) { + console.debug('ACTS_SerivceAbilityServer ====>OnAbilityConnectDone=' + + element + " , JSON." + JSON.stringify(element) + + remoteObject + " , JSON." + JSON.stringify(remoteObject) + + resultCode + " , JSON." + JSON.stringify(resultCode) + ); + commonEvent.publish("ACTS_SerivceAbilityServer_OnAbilityConnectDone", (err) => { }); }, - onCommand(want, restart, startId) { - console.info('SerivceAbilityServer onCommand'); + onDisconnect(want) { + console.debug('ACTS_SerivceAbilityServer ====>onDisConnect=' + + want + " , JSON." + JSON.stringify(want)); + commonEvent.publish("ACTS_SerivceAbilityServer_onDisConnect", (err) => { + if (err.code) { + console.debug('ACTS_SerivceAbilityServer_onDisConnect publish err=====>' + err); + } else { + console.debug('ACTS_SerivceAbilityServer_onDisConnect featureAbility.terminateSelf()=====<' + + want.action); + if (want.action == 'ServiceConnectService_1300' || want.action == 'ServiceConnectService_1400' + || want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1501' + || want.action == 'ServiceConnectService_1600' || want.action == 'ServiceConnectService_1601' + ) { + particleAbility.disconnectAbility(mConnIdJs, (err) => { + console.debug("=ACTS_SerivceAbilityServer_onDisConnect 13 14 15 16 err====>" + + ("json err=") + JSON.stringify(err) + " , " + want.action); + }) + } + featureAbility.terminateSelf(); + } + }); }, } \ No newline at end of file diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/BUILD.gn b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8866bf52443f3c28f7855c90a06b0bc9ab2bc98a --- /dev/null +++ b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/BUILD.gn @@ -0,0 +1,31 @@ +# Copyright (c) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("amsStServiceAilityServerSecond") { + hap_profile = "./entry/src/main/config.json" + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "amsStServiceAilityServerSecond" +} +ohos_js_assets("hjs_demo_js_assets") { + source_dir = "./entry/src/main/js/default" +} +ohos_resources("hjs_demo_resources") { + sources = [ "./entry/src/main/js/resources" ] + hap_profile = "./entry/src/main/config.json" +} diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/Test.json b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..4300a64be9af93e37a31f6b5c6fc734e8f1b4563 --- /dev/null +++ b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/Test.json @@ -0,0 +1,3 @@ +{ + "description": "Configuration for hjunit demo Tests" +} diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/config.json b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/config.json new file mode 100755 index 0000000000000000000000000000000000000000..d0d69567dd9e65841d154ef805645e6a15cb265f --- /dev/null +++ b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/config.json @@ -0,0 +1,53 @@ +{ + "app": { + "bundleName": "com.amsst.stserviceabilityserversecond", + "vendor": "amsst", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.amsst.stserviceabilityserversecond", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": true + }, + "abilities": [ + { + "name": "com.amsst.stserviceabilityserversecond.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "service", + "visible": true, + "uri": "serviceability://com.amsst.stserviceabilityserversecond", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/app.js b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..743ddb4640d5204342f4a538f730162334613c49 --- /dev/null +++ b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/app.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021 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 default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/i18n/en-US.json b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/i18n/en-US.json new file mode 100755 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/i18n/zh-CN.json b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/i18n/zh-CN.json new file mode 100755 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/pages/index/index.css b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..ac39915c295d19be6b0c23ae374d30b8f13bc066 --- /dev/null +++ b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,12 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} +.titleST { + font-size: 32px; +} diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/pages/index/index.hml b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..4170d83f7fa26079387e8dc73c21ac69867864d2 --- /dev/null +++ b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,8 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + + + StServiceAbilityServer + +
diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/pages/index/index.js b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..6d318afa2a7a9d9a8b76d8eaeb4a747f80b9dcf6 --- /dev/null +++ b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2021 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 rpc from "@ohos.rpc"; +let mMyStub; +import particleAbility from '@ohos.ability.particleability' +import featureAbility from '@ohos.ability.featureAbility' +import commonEvent from '@ohos.commonevent' +var server_bundleName = "com.amsst.stserviceabilityserver"; +var server_abilityName = "com.amsst.stserviceabilityserver.MainAbility"; +var mConnIdJs; +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.debug('ACTS_SerivceAbilityServer ====onReconnect=' + + want + " , JSON." + JSON.stringify(want)); + }, + onActive() { + console.debug('ACTS_SerivceAbilityServerSecond ==== { }); + }, + onCommand(want, restart, startId) { + console.debug('ACTS_SerivceAbilityServerSecond ====>onCommand=' + + "JSON(want)=" + JSON.stringify(want) + + " ,restart=" + restart + " ,startId=" + startId); + commonEvent.publish("ACTS_SerivceAbilityServerSecond_onCommand" + "_" + want.action, (err) => { }); + featureAbility.terminateSelf(); + }, + onStart(want) { + console.debug('ACTS_SerivceAbilityServerSecond ====>onStart=' + + want + " , JSON." + JSON.stringify(want)); + commonEvent.publish("ACTS_SerivceAbilityServerSecond_onStart", (err) => { }); + class MyStub extends rpc.RemoteObject { + constructor(des) { super(des); } + } + console.debug("ACTS_SerivceAbilityServerSecond ====< RPCTestServer"); + mMyStub = new MyStub("ServiceAbility-test"); + console.debug("ACTS_SerivceAbilityServerSecond RPCTestServer: mMyStub:" + mMyStub + + " ,JSON. " + JSON.stringify(mMyStub)) + }, + onStop() { + console.debug('ACTS_SerivceAbilityServerSecond ==== { }); + featureAbility.terminateSelf(); + }, + onConnect(want) { + console.debug('ACTS_SerivceAbilityServerSecond ====>onConnect=' + + want + " , JSON." + JSON.stringify(want)); + function onConnectCallback(element, remote) { + console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> want.action=' + + JSON.stringify(want.action) + " , " + want.action); + console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> remote=' + + JSON.stringify(remote) + " , " + remote); + if(want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1600'){ + commonEvent.publish("ACTS_SerivceAbilityServerSecond_onConnect" + "_" + want.action, (err) => { + console.debug("publish = ACTS_SerivceAbilityServerSecond_onConnect" + "_" + want.action); + }); + } + } + + function onDisconnectCallback(element) { + console.debug('ACTS_SerivceAbilityServerSecond_onDisconnectCallback ====> element=' + + JSON.stringify(element) + " , " + element); + } + + function onFailedCallback(code) { + console.debug('ACTS_SerivceAbilityServerSecond_onFailedCallback ====> code=' + + JSON.stringify(code) + " , " + code) + } + if (want.action == 'ServiceConnectService_1500') { + mConnIdJs = particleAbility.connectAbility( + { + bundleName: server_bundleName, + abilityName: server_abilityName, + action: "ServiceConnectService_1501", + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, + }, + ) + } else if (want.action == 'ServiceConnectService_1600') { + mConnIdJs = particleAbility.connectAbility( + { + bundleName: server_bundleName, + abilityName: server_abilityName, + action: "ServiceConnectService_1601", + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, + }, + ) + } else if (want.action == 'ServiceConnectService_1590') { + mConnIdJs = particleAbility.connectAbility( + { + bundleName: server_bundleName, + abilityName: server_abilityName, + action: "ServiceConnectService_1591", + }, + { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback, + }, + ) + } else { + commonEvent.publish("ACTS_SerivceAbilityServerSecond_onConnect" + "_" + want.action, (err) => { }); + } + return mMyStub; + }, + OnAbilityConnectDone(element, remoteObject, resultCode) { + console.debug('ACTS_SerivceAbilityServerSecond ====>OnAbilityConnectDone=' + + element + " , JSON." + JSON.stringify(element) + + remoteObject + " , JSON." + JSON.stringify(remoteObject) + + resultCode + " , JSON." + JSON.stringify(resultCode) + ); + commonEvent.publish("ACTS_SerivceAbilityServerSecond_OnAbilityConnectDone", (err) => { }); + }, + onDisconnect(want) { + console.debug('ACTS_SerivceAbilityServerSecond ====>onDisConnect=' + + want + " , JSON." + JSON.stringify(want)); + commonEvent.publish("ACTS_SerivceAbilityServerSecond_onDisConnect", (err) => { + if (err.code) { + console.debug('ACTS_SerivceAbilityServerSecond_onDisConnect publish err=====>' + err); + } else { + console.debug('ACTS_SerivceAbilityServerSecond_onDisConnect featureAbility.terminateSelf()=====<' + + want.action); + if (want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1501' + || want.action == 'ServiceConnectService_1600' || want.action == 'ServiceConnectService_1601' + || want.action == 'ServiceConnectService_1590') { + particleAbility.disconnectAbility(mConnIdJs, (err) => { + console.debug("=ACTS_SerivceAbilityServerSecond_onDisConnect err====>" + + ("json err=") + JSON.stringify(err) + " , " + want.action); + }) + } + featureAbility.terminateSelf(); + } + }); + }, +} \ No newline at end of file diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/resources/base/element/string.json b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..3ef6a8608a2a13717d01a77d1f27a0c9f7ab84fb --- /dev/null +++ b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "StServiceAbilityServer" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] +} diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/resources/base/media/icon.png b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/entry/src/main/js/resources/base/media/icon.png differ diff --git a/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/signature/openharmony_sx.p7b b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/appexecfwk/ams_standard/serviceability/stserviceabilityserversecond/signature/openharmony_sx.p7b differ