!488 【ability】【master】xts-dcts DM 新接口适配,系统级别接口删除,接口用例补充

Merge pull request !488 from zhaominjie11/master
This commit is contained in:
openharmony_ci 2023-11-18 08:27:08 +00:00 committed by Gitee
commit 20636f01c7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
15 changed files with 553 additions and 2926 deletions

View File

@ -15,7 +15,7 @@
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import rpc from "@ohos.rpc";
import deviceManager from '@ohos.distributedHardware.deviceManager';
import deviceManager from '@ohos.distributedDeviceManager';
import featureAbility from "@ohos.ability.featureAbility";
import { UiDriver, BY } from '@ohos.UiTest';
import TestService from "./testService";
@ -27,23 +27,31 @@ let gIRemoteObject = null;
let testservice = null;
let localDeviceId = undefined;
let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator();
let dmInstance
deviceManager.createDeviceManager('ohos.dms.test', async (error, deviceManager) => {
console.info("CLIENT Create device manager success");
localDeviceId = deviceManager.getLocalDeviceInfoSync().networkId;
console.info("local device id is: " + localDeviceId);
let deviceList = deviceManager.getTrustedDeviceListSync();
dvList = deviceList;
let deviceId = deviceList[0].networkId;
dvId = deviceId;
console.info("deviceid is: " + deviceId);
console.info("deviceList is: " + JSON.stringify(deviceList));
})
export default function dmsJsUnitTest() {
describe('dmsJsUnitTest', function () {
async function getDeviceId() {
console.log('get deviceManager is begin')
try {
dmInstance = deviceManager.createDeviceManager('ohos.dms.test');
console.log('get deviceManager is success')
} catch (error) {
console.log('get deviceManager is failed' + JSON.stringify(error))
}
localDeviceId = dmInstance.getLocalDeviceNetworkId();
console.info("local device id is: " + localDeviceId);
let deviceList = dmInstance.getAvailableDeviceListSync();
dvList = deviceList;
let deviceId = deviceList[0].networkId;
dvId = deviceId;
console.info("deviceid is: " + deviceId);
console.info("deviceList is: " + JSON.stringify(deviceList));
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
@ -67,6 +75,7 @@ export default function dmsJsUnitTest() {
console.info(`button is ${JSON.stringify(button)}`);
sleep(5000);
await button.click();
sleep(5000);
} catch (err) {
console.info('err is ' + err);
return;
@ -83,6 +92,7 @@ export default function dmsJsUnitTest() {
console.info(`button is ${JSON.stringify(button)}`);
sleep(5000);
await button.click();
} catch (err) {
console.info('err is ' + err);
return;
@ -95,15 +105,10 @@ export default function dmsJsUnitTest() {
sleep(5000);
await driveFn();
sleep(5000);
testservice = new TestService();
console.info("TestService is:");
await testservice.toConnectAbility().then(data => {
gIRemoteObject = data;
console.info("toConnectAbility data is:" + data);
})
done();
await getDeviceId();
sleep(5000);
console.info("beforeAll done");
done();
})
beforeEach(async function (done) {

View File

@ -14,22 +14,23 @@
*/
import rpc from "@ohos.rpc";
import deviceManager from '@ohos.distributedHardware.deviceManager';
// import deviceManager from '@ohos.distributedHardware.deviceManager';
import deviceManager from '@ohos.distributedDeviceManager';
import featureAbility from '@ohos.ability.featureAbility';
var results;
var bundleName = "com.ohos.dmstest";
var abilityName = "com.ohos.dmstest.ServiceAbility";
var deviceList;
let dmInstance ;
export default class TestService {
constructor() {
}
getDeviceList(deviceManager) {
deviceList = deviceManager.getTrustedDeviceListSync();
getDeviceList(dmInstance) {
deviceList = dmInstance.getTrustedDeviceListSync();
console.info("getDeviceList success, deviceList id: " + JSON.stringify(deviceList));
}
@ -37,33 +38,38 @@ export default class TestService {
console.info("dmsClient: toConnectAbility");
return new Promise(resolve=>{
let self = this;
deviceManager.createDeviceManager('ohos.dmstest.test', (error, deviceManager) => {
self.getDeviceList(deviceManager);
console.info("dmsClient: got deviceManager: " + deviceManager);
let deviceId = deviceList[0].networkId;
console.info("dmsClient: deviceid : " + deviceId);
console.info("dmsClient: online deviceList id: " + JSON.stringify(deviceList));
let want = {
"bundleName": bundleName,
"abilityName": abilityName,
"deviceId": deviceId,
"flags": 256
try {
dmInstance = deviceManager.createDeviceManager('ohos.dms.test');
console.log('get deviceManager is success')
} catch (error) {
console.log('get deviceManager is failed' + JSON.stringify(error))
}
self.getDeviceList(dmInstance);
console.info("dmsClient: got deviceManager: " + dmInstance);
let deviceId = deviceList[0].networkId;
console.info("dmsClient: deviceid : " + deviceId);
console.info("dmsClient: online deviceList id: " + JSON.stringify(deviceList));
let want = {
"bundleName": bundleName,
"abilityName": abilityName,
"deviceId": deviceId,
"flags": 256
}
let connect = {
onConnect: function (elementName, remoteProxy) {
console.log('dmsClient: onConnect called, remoteProxy: ' + remoteProxy);
resolve(remoteProxy);
},
onDisconnect: function (elementName) {
console.log("dmsClient: onDisconnect");
},
onFailed: function () {
console.log("dmsClient: onFailed");
}
let connect = {
onConnect: function (elementName, remoteProxy) {
console.log('dmsClient: onConnect called, remoteProxy: ' + remoteProxy);
resolve(remoteProxy);
},
onDisconnect: function (elementName) {
console.log("dmsClient: onDisconnect");
},
onFailed: function () {
console.log("dmsClient: onFailed");
}
}
let connectId = featureAbility.connectAbility(want, connect);
console.info("connect ability got id: " + connectId);
})
}
let connectId = featureAbility.connectAbility(want, connect);
console.info("connect ability got id: " + connectId);
})
}

View File

@ -15,7 +15,7 @@
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import rpc from "@ohos.rpc";
import deviceManager from '@ohos.distributedHardware.deviceManager';
import deviceManager from '@ohos.distributedDeviceManager';
import featureAbility from "@ohos.ability.featureAbility";
import { UiDriver, BY } from '@ohos.UiTest';
import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
@ -24,10 +24,27 @@ let connectId = null;
let dvList = [];
let dvId = null;
let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator();
let dmInstance
export default function DmsFwkFaTest() {
describe('DmsFwkFaTest', function () {
async function getDeviceId() {
console.log('getDeviceId is begin')
try {
dmInstance = deviceManager.createDeviceManager('com.acts.example.dmsfwkstageservert');
console.log('get deviceManager is success')
} catch (error) {
console.log('get deviceManager is failed' + JSON.stringify(error))
}
let localDeviceId = dmInstance.getLocalDeviceNetworkId();
console.info("local device id is: " + localDeviceId);
let deviceList = dmInstance.getAvailableDeviceListSync();
dvList = deviceList;
let deviceId = deviceList[0].networkId;
dvId = deviceId;
console.info("deviceid is: " + deviceId);
console.info("deviceList is: " + JSON.stringify(deviceList));
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
@ -52,6 +69,7 @@ export default function DmsFwkFaTest() {
console.info(`button is ${JSON.stringify(button)}`);
sleep(5000);
await button.click();
sleep(5000);
} catch (err) {
console.info('err is ' + err);
return;
@ -76,22 +94,14 @@ export default function DmsFwkFaTest() {
beforeAll(async function (done) {
console.info('beforeAll called dms')
getDeviceId()
await getPermission();
sleep(5000);
await driveFn();
sleep(100);
function deviceManagerCallback(error, deviceManagers) {
console.info("got deviceManager: " + deviceManagers + ", error: " + error)
let deviceList = deviceManagers.getTrustedDeviceListSync()
let deviceId = deviceList[0].networkId
dvList = deviceList;
dvId = deviceId;
console.info("online device id: " + deviceId)
done()
}
deviceManager.createDeviceManager('com.acts.example.dmsfwkstageserver', deviceManagerCallback)
console.info("beforeAll done")
sleep(5000);
await getDeviceId()
sleep(5000);
done()
})
beforeEach(async function (done) {
@ -1369,8 +1379,8 @@ export default function DmsFwkFaTest() {
* @tc.desc Function test
* @tc.level 0
*/
it("SUB_DMS_ConnectAbility_0140", 0, async function (done) {
console.info("-----------------SUB_DMS_ConnectAbility_0140 start------------------------");
it("SUB_DMS_StandardOs_stability_StabilityTest_0100", 0, async function (done) {
console.info("-----------------SUB_DMS_StandardOs_stability_StabilityTest_0100 start------------------------");
let connectId;
try {
for (let i = 0; i < 10; i++) {
@ -1388,7 +1398,7 @@ export default function DmsFwkFaTest() {
proxy.sendRequest(1, data, reply, option).then((result) => {
console.log('sendRequest success');
let msg = result.reply.readInt();
console.info(' SUB_DMS_ConnectAbility_0140 msg: ' + msg)
console.info(' SUB_DMS_StandardOs_stability_StabilityTest_0100 msg: ' + msg)
expect(msg == 100).assertTrue();
done();
}).catch((e) => {
@ -1398,32 +1408,32 @@ export default function DmsFwkFaTest() {
});
},
onDisConnect: (elementName) => {
console.info('SUB_DMS_ConnectAbility_0140 onDisConnect: ' + JSON.stringify(elementName));
console.info('SUB_DMS_StandardOs_stability_StabilityTest_0100 onDisConnect: ' + JSON.stringify(elementName));
expect().assertFail();
done();
},
onFailed: (code) => {
console.info('SUB_DMS_ConnectAbility_0140 onFailed: ' + code);
console.info('SUB_DMS_StandardOs_stability_StabilityTest_0100 onFailed: ' + code);
expect().assertFail();
done();
}
});
featureAbility.disconnectAbility(connectId, (err, data) => {
console.info('SUB_DMS_ConnectAbility_0140 disconnectAbility err: ' + err.code);
console.info('SUB_DMS_ConnectAbility_0140 disconnectAbilityerr: ' + err.message);
console.info('SUB_DMS_StandardOs_stability_StabilityTest_0100 disconnectAbility err: ' + err.code);
console.info('SUB_DMS_StandardOs_stability_StabilityTest_0100 disconnectAbilityerr: ' + err.message);
expect(err.code).assertEqual(0);
done();
})
console.info("SUB_DMS_ConnectAbility_0140 running at : " + i + ",here");
console.info("SUB_DMS_StandardOs_stability_StabilityTest_0100 running at : " + i + ",here");
}
} catch (err) {
console.info('SUB_DMS_ConnectAbility_0140 catch: ' + err.code);
console.info('SUB_DMS_ConnectAbility_0140 catch: ' + err.message);
console.info('SUB_DMS_StandardOs_stability_StabilityTest_0100 catch: ' + err.code);
console.info('SUB_DMS_ConnectAbilitySUB_DMS_StandardOs_stability_StabilityTest_0100_0140 catch: ' + err.message);
expect().assertFail();
done();
}
await sleep(1000);
console.info("-----------------SUB_DMS_ConnectAbility_0140 end------------------------");
console.info("-----------------SUB_DMS_StandardOs_stability_StabilityTest_0100 end------------------------");
});
})
}

View File

@ -13,27 +13,39 @@
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"
import deviceManager from '@ohos.distributedHardware.deviceManager';
import deviceManager from '@ohos.distributedDeviceManager';
import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import commonEvent from '@ohos.commonEvent';
import rpc from '@ohos.rpc';
import { UiDriver, BY } from '@ohos.UiTest';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
let atManager = abilityAccessCtrl.createAtManager();
let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator();
let dvList;
let dvId;
let localDeviceId;
let connectId;
let connectId2;
let subscriber
let subscribeInfo = {
events: ["DmsFwkService_ConnectAbility"]
}
let dvList: Array<deviceManager.DeviceBasicInfo>
let dvId: string;
let localDeviceId: string;
let dmInstance : deviceManager.DeviceManager
let TAG:string;
export default function DmsFwkStageTest() {
describe('DmsFwkStageTest', function () {
async function getDeviceId() {
console.log('getDeviceId is begin')
try {
dmInstance = deviceManager.createDeviceManager('com.acts.example.dmsfwkstageserver');
console.log('get deviceManager is success')
} catch (error) {
console.log('get deviceManager is failed' + JSON.stringify(error))
}
localDeviceId = dmInstance.getLocalDeviceNetworkId();
console.info("local device id is: " + localDeviceId);
let deviceList : Array<deviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
dvList= deviceList;
let deviceId : string= deviceList[0].networkId;
dvId = deviceId;
console.info("deviceid is: " + deviceId);
console.info("deviceList is: " + JSON.stringify(deviceList));
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
@ -56,6 +68,7 @@ export default function DmsFwkStageTest() {
console.info('button is ${JSON.stringify(button)}');
sleep(5000);
await button.click();
sleep(5000);
} catch (err) {
console.info('err is ' + err);
return;
@ -63,21 +76,13 @@ export default function DmsFwkStageTest() {
}
beforeAll(async function (done) {
console.log('DMS before began')
await getPermission();
sleep(5000);
await driveFn();
sleep(1000);
function deviceManagerCallback(error, deviceManager) {
console.info('LifeCycleTest before each called');
let deviceList = deviceManager.getTrustedDeviceListSync();
let deviceId = deviceList[0].networkId;
dvList = deviceList;
dvId = deviceId;
localDeviceId = deviceManager.getLocalDeviceInfoSync().networkId;
}
deviceManager.createDeviceManager('com.acts.example.dmsfwkstageserver', deviceManagerCallback)
await sleep(1000);
sleep(5000);
await getDeviceId();
sleep(5000);
done()
});
@ -93,9 +98,7 @@ export default function DmsFwkStageTest() {
done();
});
var TAG;
var listKeyTemp = [];
var listKeyTemp1 = [];
/*
* @tc.number SUB_DMS_StandardOs_collaboration_connectAbility_connectRemoteServiceAbility_0100

View File

@ -13,6 +13,12 @@
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"metadata": [
{
"name": "ExecuteArkTSLinter",
"value": "false"
}
],
"abilities": [
{
"name": "com.example.lifecycletest.MainAbility",

View File

@ -1,4 +1,4 @@
import ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
import rpc from '@ohos.rpc';
import commonEvent from '@ohos.commonEventManager';
class StubTest extends rpc.RemoteObject {
@ -22,7 +22,7 @@ class StubTest extends rpc.RemoteObject {
return true
}
}
export default class ServiceAbility extends ServiceExtension {
export default class ServiceAbility extends UIAbility {
onCreate(want) {
// Called to return a FormBindingData object.
console.info("DmsFwkStageServer ServiceAbility onCreate")

View File

@ -1,4 +1,4 @@
import ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
import rpc from '@ohos.rpc';
import commonEvent from '@ohos.commonEvent';
class StubTest extends rpc.RemoteObject {
@ -15,7 +15,7 @@ class StubTest extends rpc.RemoteObject {
return true
}
}
export default class ServiceAbility extends ServiceExtension {
export default class ServiceAbility extends UIAbility {
onCreate(want) {
// Called to return a FormBindingData object.
console.info("DmsFwkStageServer ServiceAbility2 onCreate")

View File

@ -15,20 +15,65 @@
import Ability from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import wantConstant from '@ohos.app.ability.wantConstant';
import rpc from '@ohos.rpc';
import commonEvent from '@ohos.commonEvent';
class StubTest extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor)
}
onRemoteRequest(code, data, reply, option) {
console.info("onRemoteRequest: " + code)
let tmp1 = data.readInt();
let tmp2 = data.readInt();
let tmp3 = tmp1 + tmp2;
let result = reply.writeInt(tmp3);
console.info("The server's writeInt result is " + result);
commonEvent.publish("DmsFwkService_RemoteObject", {
parameters:{
"msg":"receiveMessage = " + data.readInt()
}
}, (err, data) => {
console.info("DmsFwkService_ConnectAbility onCreate");
});
return true
}
}
export default class MainAbility extends Ability {
localStorage: LocalStorage;
onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate")
console.log("[Demo] MainAbility onCreate");
globalThis.abilityWant = want;
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
this.localStorage = new LocalStorage();
this.context.restoreWindowStage(this.localStorage);
}
}
onConnect(want) {
console.info("DmsFwkStageServer ServiceAbility onConnect")
let CommonEventPublishData = {
parameters: {
"life": "onConnect"
}
}
commonEvent.publish("DmsFwkService_ConnectAbility", CommonEventPublishData, (err) => {
console.info("DmsFwkService_ConnectAbility onCreate");
});
return new StubTest("test");
}
onDisconnect(want) {
console.info("DmsFwkStageServer ServiceAbility onDisconnect")
}
onNewWant(want, launchParam) {
console.log("[Demo] MainAbility onNewWant")
globalThis.abilityWant = want;
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
@ -42,31 +87,26 @@ export default class MainAbility extends Ability {
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context;
windowStage.setUIContent(this.context, "MainAbility/pages/MainAbility_pages", null)
}
onWindowStageRestore(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageRestore")
globalThis.abilityContext = this.context;
windowStage.setUIContent(this.context, "MainAbility/pages/MainAbility_pages", null)
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}

View File

@ -13,6 +13,12 @@
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"metadata": [
{
"name": "ExecuteArkTSLinter",
"value": "false"
}
],
"abilities": [
{
"continuable":true,
@ -35,16 +41,6 @@
]
}
],
"extensionAbilities": [
{
"name": "ServiceAbility",
"srcEntrance": "./ets/serviceability/ServiceAbility.ts",
"label": "$string:entry_label",
"description": "$string:phone_entry_main",
"type": "service",
"visible": true
}
],
"requestPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO"
@ -57,9 +53,6 @@
},
{
"name": "ohos.permission.ACCESS_SERVICE_DM"
},
{
"name": "ohos.permission.MANAGE_MISSIONS"
}
]
}

View File

@ -1,4 +1,4 @@
import ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
import rpc from '@ohos.rpc';
import commonEvent from '@ohos.commonEvent';
class StubTest extends rpc.RemoteObject {
@ -22,7 +22,7 @@ class StubTest extends rpc.RemoteObject {
return true
}
}
export default class ServiceAbility extends ServiceExtension {
export default class ServiceAbility extends UIAbility {
onCreate(want) {
// Called to return a FormBindingData object.
console.info("DmsFwkStageServer ServiceAbility onCreate")

View File

@ -1,4 +1,4 @@
import ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
import rpc from '@ohos.rpc';
import commonEvent from '@ohos.commonEvent';
class StubTest extends rpc.RemoteObject {
@ -15,7 +15,7 @@ class StubTest extends rpc.RemoteObject {
return true
}
}
export default class ServiceAbility extends ServiceExtension {
export default class ServiceAbility extends UIAbility {
onCreate(want) {
// Called to return a FormBindingData object.
console.info("DmsFwkStageServer ServiceAbility2 onCreate")

View File

@ -65,9 +65,6 @@
},
{
"name": "ohos.permission.ACCESS_SERVICE_DM"
},
{
"name": "ohos.permission.MANAGE_MISSIONS"
}
]
}