提交 62b993fd 编写于 作者: O openharmony_ci 提交者: Gitee

!1253 Update xts service 1201

Merge pull request !1253 from blackleon/master_xts_1201
...@@ -29,6 +29,7 @@ group("ams_standard") { ...@@ -29,6 +29,7 @@ group("ams_standard") {
"serviceability/sceneProject/particletestserver:ParticleTestServer", "serviceability/sceneProject/particletestserver:ParticleTestServer",
"serviceability/stserviceabilityclient:amsStServiceAbilityClient", "serviceability/stserviceabilityclient:amsStServiceAbilityClient",
"serviceability/stserviceabilityserver:amsStServiceAilityServer", "serviceability/stserviceabilityserver:amsStServiceAilityServer",
"serviceability/stserviceabilityserversecond:amsStServiceAilityServerSecond",
] ]
} }
} }
...@@ -12,54 +12,411 @@ ...@@ -12,54 +12,411 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import rpc from "@ohos.rpc";
import featureAbility from '@ohos.ability.featureAbility' 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 () { describe('ActsStServiceAbilityTest', function () {
let bundleName = "com.amsst.stserviceabilityserver"; let bundleName = "com.amsst.stserviceabilityserver";
let abilityName = "com.amsst.stserviceabilityserver.MainAbility"; let abilityName = "com.amsst.stserviceabilityserver.MainAbility";
let g_setTimeout = 10
var mConnIdJsPromise;
var mConnIdJsCallback;
var mRemote;
function onConnectCallback(element, remote){ var subscriber_0100;
console.log('ACTS_featureAbilityTest ConnectAbility onConnect element.deviceId : ' + element.deviceId) var CommonEventSubscribeInfo_0100 = {
console.log('ACTS_featureAbilityTest ConnectAbility onConnect element.bundleName : ' + element.bundleName) events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0100",
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) var subscriber_0200;
console.log('ACTS_featureAbilityTest ConnectAbility onConnect remote : ' + remote); var CommonEventSubscribeInfo_0200 = {
mRemote = remote; events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0200",
console.log('ACTS_featureAbilityTest ConnectAbility onConnect remote 是否为proxy:' + (remote instanceof rpc.RemoteProxy)); ],
};
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 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 ====<begin');
console.debug('= ACTS_beforeAll ====<end');
done();
})
beforeEach(async (done) => {
setTimeout(function () {
done();
}, g_setTimeout);
})
afterEach(async (done) => {
setTimeout(function () {
done();
}, g_setTimeout);
})
afterAll((done) => {
console.debug('= ACTS_afterAll ====<begin');
setTimeout(function () {
console.debug('= ACTS_afterAll ====<end');
featureAbility.terminateSelf();
done();
}, g_setTimeout);
})
function onDisconnectCallback(element){ /*
console.log('ACTS_featureAbilityTest ConnectAbility onDisconnect element.deviceId : ' + element.deviceId) * @tc.number: ACTS_JsServiceAbility_0100
console.log('ACTS_featureAbilityTest ConnectAbility onDisconnect element.bundleName : ' + element.bundleName) * @tc.name: featureAbility.startAbility : Use page to test startAbiltiy service.
console.log('ACTS_featureAbilityTest ConnectAbility onDisconnect element.abilityName : ' + element.abilityName) * @tc.desc: Check the return value of the interface (by Promise)
console.log('ACTS_featureAbilityTest ConnectAbility onDisconnect element.uri : ' + element.uri) */
console.log('ACTS_featureAbilityTest ConnectAbility onDisconnect element.shortName : ' + element.shortName) it('ACTS_JsServiceAbility_0100', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_0100====<begin');
try {
commonEvent.createSubscriber(CommonEventSubscribeInfo_0100).then(async (data) => {
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====<end');
done();
});
})
featureAbility.startAbility(
{
want:
{
bundleName: bundleName,
abilityName: abilityName,
action: "PageStartService_0100",
},
} }
).then(data => {
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====<end .catch(err)');
done();
})
} catch (err) {
expect("catch").assertEqual(err);
console.debug('ACTS_JsServiceAbility_0100====<end catch(err)');
done();
}
})
function onFailedCallback(code){ /*
console.log('ACTS_featureAbilityTest ConnectAbility onFailed errCode : ' + code) * @tc.number: ACTS_JsServiceAbility_0200
* @tc.name: featureAbility.startAbility : Use page to test startAbiltiy service.
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_JsServiceAbility_0200', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_0200====<begin');
try {
commonEvent.createSubscriber(CommonEventSubscribeInfo_0200).then(async (data) => {
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====<end');
done()
});
})
await featureAbility.startAbility(
{
want:
{
bundleName: bundleName,
abilityName: abilityName,
action: "PageStartService_0200",
},
}, (err, data) => {
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====<end catch(err)');
done();
}
})
/*
* @tc.number: ACTS_JsServiceAbility_0300
* @tc.name: featureAbility.startAbility : Use page to test startAbiltiy service.
* @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_JsServiceAbility_0300', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_0300====<begin');
try {
commonEvent.createSubscriber(CommonEventSubscribeInfo_0300).then(async (data) => {
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====<end .catch(err) 2');
done();
})
} else {
expect("ACTS_SerivceAbilityServer_onCommand_PageStartService_0301").assertEqual(
data.event);
unsubscribe("ACTS_JsServiceAbility_0300_unsubscribe", subscriber_0300);
console.debug('ACTS_JsServiceAbility_0300====<end');
done();
}
});
})
featureAbility.startAbility(
{
want:
{
bundleName: bundleName,
abilityName: abilityName,
action: "PageStartService_0300",
},
}
).then(data => {
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====<end .catch(err) 1');
done();
})
} catch (err) {
expect("catch").assertEqual(err);
console.debug('ACTS_JsServiceAbility_0300====<end catch(err)');
done();
}
})
/*
* @tc.number: ACTS_JsServiceAbility_0400
* @tc.name: featureAbility.startAbility : Use page to test startAbiltiy service.
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_JsServiceAbility_0400', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_0400====<begin');
try {
commonEvent.createSubscriber(CommonEventSubscribeInfo_0400).then(async (data) => {
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====<end');
done();
}
});
})
featureAbility.startAbility(
{
want:
{
bundleName: bundleName,
abilityName: abilityName,
action: "PageStartService_0400",
},
}, (err, data) => {
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====<end catch(err)');
done();
}
})
/*
* @tc.number: ACTS_JsServiceAbility_0500
* @tc.name: featureAbility.ConnectAbility : Connects an ability to a Service ability.
* @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_JsServiceAbility_0500', 0, async function (done) {
console.log('ACTS_JsServiceAbility_0500====<begin');
try {
var mConnIdJsPromise;
commonEvent.createSubscriber(CommonEventSubscribeInfo_0500).then(async (data) => {
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====<end .catch(err)');
done();
})
} else {
expect("ACTS_SerivceAbilityServer_onDisConnect").assertEqual(data.event);
unsubscribe("ACTS_JsServiceAbility_0500_unsubscribe", subscriber_0500);
console.debug('ACTS_JsServiceAbility_0500====<end');
done();
}
});
})
function onConnectCallback(element, remote) {
console.debug('ACTS_JsServiceAbility_0500_onConnectCallback ====> 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====<begin');
let ret = false;
try{
mConnIdJsPromise = featureAbility.connectAbility( mConnIdJsPromise = featureAbility.connectAbility(
{ {
bundleName: bundleName, bundleName: bundleName,
abilityName: abilityName, abilityName: abilityName,
action: "PageConnectService_0500",
}, },
{ {
onConnect: onConnectCallback, onConnect: onConnectCallback,
...@@ -67,155 +424,413 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -67,155 +424,413 @@ describe('ActsStServiceAbilityTest', function () {
onFailed: onFailedCallback, onFailed: onFailedCallback,
}, },
) )
// ).then(function (data) { } catch (err) {
// console.debug("=ACTS_ConnectAbility_0100 then data====>" expect("catch").assertEqual(err);
// + (" json data 【") + JSON.stringify(data)+ (" 】; ====>")+data); console.log('ACTS_JsServiceAbility_0500====<end err')
// 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;
done(); done();
} }
setTimeout(function(){
expect(ret).assertTrue();
}, g_setTimeout);
console.log('ACTS_ConnectAbility_0100====<end')
}) })
/* /*
* @tc.number: ACTS_DisconnectAbility_0100 * @tc.number: ACTS_JsServiceAbility_0600
* @tc.name: DisconnectAbility : Disconnects an ability from a Service ability.. * @tc.name: featureAbility.ConnectAbility : Connects an ability to a Service ability.
* @tc.desc: Check the return value of the interface (by Promise) * @tc.desc: Check the return value of the interface (by AsyncCallback)
*/ */
it('ACTS_DisconnectAbility_0100',0, async function (done) { it('ACTS_JsServiceAbility_0600', 0, async function (done) {
console.log('ACTS_DisconnectAbility_0100====<begin'); console.log('ACTS_JsServiceAbility_0600====<begin');
let ret = false; try {
try{ var mConnIdJsAsyncCallback;
console.log('=ACTS_DisconnectAbility_0100====>' + mConnIdJsPromise); commonEvent.createSubscriber(CommonEventSubscribeInfo_0600).then(async (data) => {
var result = featureAbility.disconnectAbility( console.debug("=ACTS_JsServiceAbility_0600 createSubscriber .then(data)=======>"
mConnIdJsPromise, + ("json data【") + JSON.stringify(data) + ("")
).then(function (data) { + " ,data=" + data);
console.debug("=ACTS_DisconnectAbility_0100 then data====>" subscriber_0600 = data;
+ (" json data 【") + JSON.stringify(data)+ (" 】; ====>")+data); await commonEvent.subscribe(subscriber_0600, async (err, data) => {
expect(typeof(data)).assertEqual("object"); console.debug("=ACTS_JsServiceAbility_0600 subscribe (err,data)=======>"
console.log('=ACTS_DisconnectAbility_0100 promise result)====>:' + JSON.stringify(result)+","+result); + ("json err【") + JSON.stringify(err) + ("")
ret = true; + ("json data【") + JSON.stringify(data) + ("")
done() + " ,err=" + err + " ,data=" + data);
}).catch(function (err){ if (data.event != "ACTS_SerivceAbilityServer_onDisConnect") {
console.debug("=ACTS_DisconnectAbility_0100 catch err====>" expect("ACTS_SerivceAbilityServer_onConnect_PageConnectService_0600").assertEqual(
+ ("json err 【") + JSON.stringify(err) + (" 】 ====>")+err); data.event);
console.log('=ACTS_DisconnectAbility_0100 result====>:' + JSON.stringify(result)) featureAbility.disconnectAbility(mConnIdJsAsyncCallback, (err) => {
ret = false; 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====<end')
done(); done();
}
}); });
})
function onConnectCallback(element, remote) {
console.debug('ACTS_JsServiceAbility_0600_onConnectCallback ====> 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)
}
console.log('=ACTS_DisconnectAbility_0100 result ====>: ' mConnIdJsAsyncCallback = featureAbility.connectAbility(
+ ("json result 【") + JSON.stringify(result) + (" 】 ,")+result); {
}catch(err) { bundleName: bundleName,
console.error('=ACTS_DisconnectAbility_0100 catch(err)====>:' abilityName: abilityName,
+ ("json err 【") + JSON.stringify(err) + (" 】 ,")+err); action: "PageConnectService_0600",
ret = false; },
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
)
} catch (err) {
expect("catch").assertEqual(err);
console.log('ACTS_JsServiceAbility_0600====<end err')
done(); done();
} }
})
setTimeout(function(){ /*
expect(ret).assertTrue(); * @tc.number: ACTS_JsServiceAbility_0900
}, g_setTimeout); * @tc.name: particleability.startAbility : Use page to test startAbiltiy service.
console.log('ACTS_DisconnectAbility_0100====<end') * @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_JsServiceAbility_0900', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_0900====<begin');
try {
commonEvent.createSubscriber(CommonEventSubscribeInfo_0900).then(async (data) => {
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====<end');
done();
});
})
featureAbility.startAbility(
{
want:
{
bundleName: bundleName,
abilityName: abilityName,
action: "ServiceStartService_0900",
},
}
).then(data => {
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====<end .catch(err)');
done();
})
} catch (err) {
expect("catch").assertEqual(err);
console.debug('ACTS_JsServiceAbility_0900====<end catch(err)');
done();
}
}) })
/*
* @tc.number: ACTS_JsServiceAbility_1000
* @tc.name: particleability.startAbility : Use page to test startAbiltiy service.
* @tc.desc: Check the return value of the interface (by AsyncCallback)
*/
it('ACTS_JsServiceAbility_1000', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_1000====<begin');
try {
commonEvent.createSubscriber(CommonEventSubscribeInfo_1000).then(async (data) => {
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====<end');
done()
});
})
await featureAbility.startAbility(
{
want:
{
bundleName: bundleName,
abilityName: abilityName,
action: "ServiceStartService_1000",
},
}, (err, data) => {
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====<end catch(err)');
done();
}
})
/* /*
* @tc.number: ACTS_ConnectAbility_0200 * @tc.number: ACTS_JsServiceAbility_1300
* @tc.name: ConnectAbility : Connects an ability to a Service ability. * @tc.name: particleability.ConnectAbility : Connects an ability to a Service ability.
* @tc.desc: Check the return value of the interface (by AsyncCallback) * @tc.desc: Check the return value of the interface (by Promise)
*/ */
it('ACTS_ConnectAbility_0200',0, async function (done) { it('ACTS_JsServiceAbility_1300', 0, async function (done) {
console.log('ACTS_ConnectAbility_0200====<begin'); console.log('ACTS_JsServiceAbility_1300====<begin');
let ret = false; try {
try{ var mConnIdJsPromise;
mConnIdJsCallback = featureAbility.connectAbility( commonEvent.createSubscriber(CommonEventSubscribeInfo_1300).then(async (data) => {
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====<end')
done();
}
});
})
function onConnectCallback(element, remote) {
console.debug('ACTS_JsServiceAbility_1300_onConnectCallback ====> 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====<end onDisconnectCallback')
done();
}
function onFailedCallback(code) {
console.debug('ACTS_JsServiceAbility_1300_onFailedCallback ====> code='
+ JSON.stringify(code) + " , " + code)
}
mConnIdJsPromise = featureAbility.connectAbility(
{ {
bundleName: bundleName, bundleName: bundleName,
abilityName: abilityName, abilityName: abilityName,
action: "ServiceConnectService_1300",
}, },
{ {
onConnect: onConnectCallback, onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback, onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback, 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; } catch (err) {
done() expect("catch").assertEqual(err);
}catch(err) { console.log('ACTS_JsServiceAbility_1300====<end err')
console.error('=ACTS_ConnectAbility_0200 catch(err)====>:'
+ ("json err 【") + JSON.stringify(err) + (" 】 ,")+err);
ret = false;
done(); done();
} }
setTimeout(function(){
expect(ret).assertTrue();
}, g_setTimeout);
console.log('ACTS_ConnectAbility_0200====<end')
}) })
/* /*
* @tc.number: ACTS_DisconnectAbility_0200 * @tc.number: ACTS_JsServiceAbility_1400
* @tc.name: DisconnectAbility : Disconnects an ability from a Service ability.. * @tc.name: particleability.ConnectAbility : Connects an ability to a Service ability.
* @tc.desc: Check the return value of the interface (by AsyncCallback) * @tc.desc: Check the return value of the interface (by AsyncCallback)
*/ */
it('ACTS_DisconnectAbility_0200',0, async function (done) { it('ACTS_JsServiceAbility_1400', 0, async function (done) {
console.log('ACTS_DisconnectAbility_0200====<begin'); console.log('ACTS_JsServiceAbility_1400====<begin');
let ret = false; try {
try{ var mConnIdJsAsyncCallback;
console.log('=ACTS_DisconnectAbility_0200====>' + mConnIdJsCallback); commonEvent.createSubscriber(CommonEventSubscribeInfo_1400).then(async (data) => {
var result = featureAbility.disconnectAbility( console.debug("=ACTS_JsServiceAbility_1400 createSubscriber .then(data)=======>"
mConnIdJsCallback, + ("json data【") + JSON.stringify(data) + ("")
// { + " ,data=" + data);
// onConnect: onConnectCallback, subscriber_1400 = data;
// onDisconnect: onDisconnectCallback, await commonEvent.subscribe(subscriber_1400, async (err, data) => {
// onFailed: onFailedCallback, console.debug("=ACTS_JsServiceAbility_1400 subscribe (err,data)=======>"
// }, + ("json err【") + JSON.stringify(err) + ("")
(err,data) => { + ("json data【") + JSON.stringify(data) + ("")
console.debug("=ACTS_DisconnectAbility_0200 disconnectAbility err,data====>" + " ,err=" + err + " ,data=" + data);
+ ("json err【") + JSON.stringify(err) + (" 】json data【") + JSON.stringify(data)+ (" 】;")); if (data.event != "ACTS_SerivceAbilityServerSecond_onDisConnect") {
ret = true; expect("ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1400"
done() ).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====<end')
done();
}
});
})
function onConnectCallback(element, remote) {
console.debug('ACTS_JsServiceAbility_1400_onConnectCallback ====> 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",
}, },
); {
console.log('=ACTS_DisconnectAbility_0200 result ====>: ' onConnect: onConnectCallback,
+ ("json result 【") + JSON.stringify(result) + (" 】 ,")+result); onDisconnect: onDisconnectCallback,
}catch(err) { onFailed: onFailedCallback,
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====<end err')
done(); done();
} }
})
setTimeout(function(){ /*
expect(ret).assertTrue(); * @tc.number: ACTS_JsServiceAbility_1500
}, g_setTimeout); * @tc.name: particleability.ConnectAbility : Connects an ability to a Service ability.
console.log('ACTS_DisconnectAbility_0200====<end') * @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_JsServiceAbility_1500', 0, async function (done) {
console.log('ACTS_JsServiceAbility_1500====<begin');
try {
var mConnIdJsPromise;
commonEvent.createSubscriber(CommonEventSubscribeInfo_1500).then(async (data) => {
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====<end .catch(err)');
done();
})
} else {
expect("ACTS_SerivceAbilityServer_onDisConnect").assertEqual(
data.event);
unsubscribe("ACTS_JsServiceAbility_1500_unsubscribe", subscriber_1500);
console.log('ACTS_JsServiceAbility_1500====<end')
done();
}
});
})
function onConnectCallback(element, remote) {
console.debug('ACTS_JsServiceAbility_1500_onConnectCallback ====> 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====<end onDisconnectCallback')
done();
}
function onFailedCallback(code) {
console.debug('ACTS_JsServiceAbility_1500_onFailedCallback ====> 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====<end err')
done();
}
}) })
}) })
\ No newline at end of file
...@@ -22,26 +22,18 @@ ...@@ -22,26 +22,18 @@
"distro": { "distro": {
"deliveryWithInstall": true, "deliveryWithInstall": true,
"moduleName": "entry", "moduleName": "entry",
"moduleType": "entry" "moduleType": "entry",
"installationFree": true
}, },
"abilities": [ "abilities": [
{ {
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "com.amsst.stserviceabilityserver.MainAbility", "name": "com.amsst.stserviceabilityserver.MainAbility",
"icon": "$media:icon", "icon": "$media:icon",
"description": "$string:mainability_description", "description": "$string:mainability_description",
"label": "$string:app_name", "label": "$string:app_name",
"type": "service", "type": "service",
"visible": true, "visible": true,
"uri": "serviceability://com.amsst.stserviceabilityserver",
"launchType": "standard" "launchType": "standard"
} }
], ],
......
...@@ -12,12 +12,14 @@ ...@@ -12,12 +12,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import rpc from "@ohos.rpc"; import rpc from "@ohos.rpc";
let mMyStub; let mMyStub;
let mMyProxy; import particleAbility from '@ohos.ability.particleability'
import featureAbility from '@ohos.ability.featureAbility'
import commonEvent from '@ohos.commonevent'
var serversecond_bundleName = "com.amsst.stserviceabilityserversecond";
var serversecond_abilityName = "com.amsst.stserviceabilityserversecond.MainAbility";
var mConnIdJs;
export default { export default {
data: { data: {
title: "" title: ""
...@@ -25,75 +27,150 @@ export default { ...@@ -25,75 +27,150 @@ export default {
onInit() { onInit() {
this.title = this.$t('strings.world'); this.title = this.$t('strings.world');
}, },
onStart(want) { onShow() {
console.log('SerivceAbilityServer onStart'); console.debug('ACTS_SerivceAbilityServer ====<onShow')
class MyStub extends rpc.RemoteObject{ },
constructor(des) { onReady() {
if (typeof des === 'string') { console.debug('ACTS_SerivceAbilityServer ====<onReady');
super(des, des.length); },
onReconnect(want) {
console.debug('ACTS_SerivceAbilityServer ====>onReconnect='
+ want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServer_onReconnect" + "_" + want.action, (err) => { });
},
onActive() {
console.debug('ACTS_SerivceAbilityServer ====<onActive');
commonEvent.publish("ACTS_SerivceAbilityServer_onActive", (err) => { });
},
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; );
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();
} }
onRemoteRequest(code, message, reply, option) { );
console.log("RPCTestServer onRemoteRequest code:" + code); } else {
if (code === 1) { commonEvent.publish("ACTS_SerivceAbilityServer_onCommand" + "_" + want.action, (err) => {
console.log("RPCTestServer: 调用到方法"); if (!err.code) {
let getContextObject = rpc.IPCSkeleton.getContextObject(); if (want.action == 'PageStartService_0100' || want.action == 'PageStartService_0200'
console.log("RPCTestServer: getContextObject 方法调用的结果为: " + getContextObject); || want.action == 'PageStartService_0301' || want.action == 'PageStartService_0401') {
let getCallingPid = rpc.IPCSkeleton.getCallingPid(); console.debug('ACTS_SerivceAbilityServer_onCommand 100 200 301 401.terminateSelf()=====>'
console.log("RPCTestServer: getCallingPid 方法调用的结果为: " + getCallingPid); + want.action);
let getCallingUid = rpc.IPCSkeleton.getCallingUid(); featureAbility.terminateSelf();
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;
} }
} 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() { onStart(want) {
console.info('SerivceAbilityServer onReady'); 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() { onStop() {
console.info('SerivceAbilityServer onStop'); console.debug('ACTS_SerivceAbilityServer ====<onStop');
commonEvent.publish("ACTS_SerivceAbilityServer_onStop", (err) => { });
featureAbility.terminateSelf();
}, },
onConnect(want) { onConnect(want) {
console.info('stub SerivceAbilityServer OnConnect'); console.debug('ACTS_SerivceAbilityServer ====>onConnect='
return mMyStub; + 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,
}, },
onReconnect(want) { {
console.info('SerivceAbilityServer onReconnect'); onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
}, },
onDisconnect() { )
console.info('SerivceAbilityServer OnDisConnect'); } else {
commonEvent.publish("ACTS_SerivceAbilityServer_onConnect" + "_" + want.action, (err) => { });
}
return mMyStub;
}, },
onCommand(want, restart, startId) { OnAbilityConnectDone(element, remoteObject, resultCode) {
console.info('SerivceAbilityServer onCommand'); 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) => { });
},
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
# 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"
}
{
"description": "Configuration for hjunit demo Tests"
}
{
"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
/*
* 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');
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
}
}
\ No newline at end of file
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
.titleST {
font-size: 32px;
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
<text class="titleST">
StServiceAbilityServer
</text>
</div>
/*
* 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 ====<onShow')
},
onReady() {
console.debug('ACTS_SerivceAbilityServerSecond ====<onReady');
},
onReconnect(want) {
console.debug('ACTS_SerivceAbilityServerSecond ====>onReconnect='
+ want + " , JSON." + JSON.stringify(want));
},
onActive() {
console.debug('ACTS_SerivceAbilityServerSecond ====<onActive');
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onActive", (err) => { });
},
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 ====<onStop');
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onStop", (err) => { });
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
{
"string": [
{
"name": "app_name",
"value": "StServiceAbilityServer"
},
{
"name": "mainability_description",
"value": "hap sample empty page"
}
]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册