!680 MissionCenter_Demo

Merge pull request !680 from liuxiaowei42/master
This commit is contained in:
openharmony_ci 2023-07-27 07:31:46 +00:00 committed by Gitee
commit 627e057def
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 994 additions and 0 deletions

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2023 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 missionManager from '@ohos.application.missionManager'
import DeviceManager from './DeviceManager'
import LocalMissionManager from './LocalMissionManager'
import Mission from './Mission'
import RemoteMissionManager from './RemoteMissionManager'
import Logger from './Logger'
const NUM_MAX: number = 20
export default class Device{
isLocal: boolean = true
color: Color = Color.Gray
deviceInfo
missionList: Mission[] = [];
constructor(deviceInfo, isLocal: boolean) {
Logger.info('Device construct');
this.deviceInfo = deviceInfo
this.isLocal = isLocal
this.initMissionInfos()
}
initMissionInfos(){
if (this.isLocal) {
LocalMissionManager.registerMissionListener(this)
} else {
RemoteMissionManager.registerMissionListener(this)
}
}
updateMissionInfos(){
let self = this;
Logger.info('get MissionInfos begin, device = ' + this.deviceInfo.networkId);
var promise = missionManager.getMissionInfos(this.deviceInfo.networkId, NUM_MAX).catch(function(error){
Logger.info('get MissionInfos failed, error.code = ' + error.code);
})
promise.then(missions => {
if (typeof (missions) == 'undefined' || typeof (missions.length) == 'undefined') {
Logger.info('missionInfos is null');
return
}
Logger.info('get MissionInfos success, mission size = ' + missions?.length);
self.missionList = []
let writeList:Set<string> = new Set();
writeList.add("com.ohos.settings")
writeList.add("com.ohos.note")
writeList.add("com.huawei.himovie")
writeList.add("ohos.samples.distributedcalc")
for (var i = 0; i < missions.length; i++) {
Logger.info('update mission = ' + JSON.stringify(missions[i]));
self.missionList.push(new Mission(missions[i]))
}
DeviceManager.update()
})
}
}

View File

@ -0,0 +1,172 @@
/*
* Copyright (c) 2023 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 Mission from './Mission';
import deviceManager from '@ohos.distributedHardware.deviceManager';
import distributedMissionManager from '@ohos.distributedMissionManager'
import Logger from './Logger'
import Device from './Device';
const BUNDLE_NAME = "com.example.mission_center"
class DeviceManager {
private myDeviceManager: deviceManager.DeviceManager
toDeviceId: string = ''
fromDeviceId: string = ''
fromMissionId: number = -1
isFreeInstall: boolean = true
localDevice: Device
trustedDeviceList: Device[] = []
currentDevice: Device
constructor() {
Logger.info('create DeviceManager begin');
let self = this;
deviceManager.createDeviceManager(BUNDLE_NAME, (error, value) => {
if (error) {
Logger.error('create DeviceManager failed');
return;
}
self.myDeviceManager = value;
Logger.info('create DeviceManager success');
self.initTrustedDeviceMissionList()
self.initLocalDeviceMission()
Logger.info('lxw success' + JSON.stringify(self.localDevice));
self.fromDeviceId = self.localDevice.deviceInfo.networkId
self.currentDevice = self.localDevice
self.ready()
});
Logger.info('create DeviceManager end');
this.update()
AppStorage.SetOrCreate<DeviceManager>('DeviceManager', this)
}
private initTrustedDeviceMissionList() {
Logger.info('init TrustedDeviceMissionList begin');
if (typeof (this.myDeviceManager) === 'undefined') {
Logger.error('DeviceManager not initialized');
return
}
var trustedDeviceList = this.myDeviceManager.getTrustedDeviceListSync();
Logger.info('init TrustedDeviceMissionList end, deviceList = ' + JSON.stringify(trustedDeviceList));
if (typeof (trustedDeviceList) == 'undefined' || typeof (trustedDeviceList.length) == 'undefined') {
Logger.info('TrustedDeviceMissionList is null');
} else {
for (var i = 0; i < trustedDeviceList.length; i++) {
var device = new Device(trustedDeviceList[i], false)
this.trustedDeviceList[this.trustedDeviceList.length] = device
}
}
Logger.info('TrustedDeviceMissionList size = ' + this.trustedDeviceList.length);
this.update()
}
private initLocalDeviceMission() {
Logger.info('init LocalDeviceMission begin');
if (typeof (this.myDeviceManager) === 'undefined') {
Logger.error('DeviceManager not initialized');
return
}
var deviceInfo = this.myDeviceManager.getLocalDeviceInfoSync();
Logger.info('init LocalDeviceMission end, device = ' + JSON.stringify(deviceInfo));
if (typeof (deviceInfo) != 'undefined') {
this.localDevice = new Device(deviceInfo, true)
} else {
Logger.error('LocalDeviceMission is null');
}
this.update()
}
update() {
Logger.info('update begin');
AppStorage.Set('isUpdate',!AppStorage.Get('isUpdate'))
Logger.info('update end');
}
ready() {
Logger.info('update begin');
AppStorage.Set('isReady', true)
Logger.info('update end');
}
onSelectToDevice(toDeviceId: string) {
this.toDeviceId = toDeviceId
}
onSelectFromMission(fromDeviceId: string, fromMissionId: number) {
this.fromDeviceId = fromDeviceId
this.fromMissionId = fromMissionId
}
onContinueAbility() {
Logger.info('toDeviceId = ' + this.toDeviceId);
Logger.info('fromDeviceId = ' + this.fromDeviceId);
Logger.info('fromMissionId = ' + this.fromMissionId);
if (this.enableContinue()) {
Logger.info('continue mission start');
AppStorage.SetOrCreate<string>('continueResult', '等待迁移结果...')
function OnContinueDone(resultCode) {
Logger.info('OnContinueDone resultCode: ' + JSON.stringify(resultCode));
AppStorage.SetOrCreate<string>('continueResult', JSON.stringify(resultCode))
}
try {
distributedMissionManager.continueMission({
srcDeviceId: this.fromDeviceId,
dstDeviceId: this.toDeviceId,
missionId: this.fromMissionId,
wantParam: { "isFreeInstall": this.isFreeInstall }
}, {onContinueDone: OnContinueDone })
.then(data => {
Logger.info('continueMission start success');
AppStorage.SetOrCreate<string>('continueResult', '0')
})
.catch(error => {
Logger.info('continueMission failed result ' + JSON.stringify(error));
Logger.info('continueMission failed info ' + JSON.stringify(error.message));
AppStorage.SetOrCreate<string>('continueResult', JSON.stringify(error))
})
} catch (error) {
Logger.info('continueMission failed result ' + JSON.stringify(error));
AppStorage.SetOrCreate<string>('continueResult', JSON.stringify(error))
}
Logger.info('continue mission end');
}
}
enableContinue(): boolean {
return true
if (this.toDeviceId.length == 0 || this.fromDeviceId.length == 0 || this.fromMissionId <= 0) {
Logger.error('not select mission');
return false
}
if (this.fromDeviceId == this.toDeviceId) {
Logger.error('same device can not continue');
return false
}
if (this.toDeviceId == this.localDevice.deviceInfo.networkId) {
Logger.error('same device can not continue');
return false
}
if (this.fromDeviceId != this.localDevice.deviceInfo.networkId
&& this.toDeviceId != this.localDevice.deviceInfo.networkId) {
Logger.error('need select a local device');
return false
}
return true
}
}
export default new DeviceManager

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2023 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 missionManager from '@ohos.application.missionManager'
import Device from './Device';
import Logger from './Logger'
class LocalMissionManager{
constructor() {
Logger.info('LocalMissionManager construct');
}
registerMissionListener(Device: Device){
var listener = {
onMissionCreated: async function(mission){
Logger.info('onMissionCreated mission = ' + mission);
Device.updateMissionInfos()
},
onMissionDestroyed: async function(mission){
Logger.info('onMissionDestroyed mission = ' + mission);
Device.updateMissionInfos()
},
onMissionSnapshotChanged: async function(mission){
Logger.info('onMissionSnapshotChanged mission = ' + mission);
Device.updateMissionInfos()
},
onMissionMovedToFront: async function(mission){
Logger.info('onMissionMovedToFront mission = ' + mission);
Device.updateMissionInfos()
},onMissionIconUpdated : async function(mission){
},onMissionClosed : async function(mission){
}
}
// @ts-ignore
missionManager.registerMissionListener(listener)
Device.updateMissionInfos()
}
}
export default new LocalMissionManager

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2023 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.
*/
class Logger {
private prefix: string;
constructor(prefix: string) {
this.prefix = prefix;
}
debug(...args: any[]) {
console.debug(`[${this.prefix}] ${args.join('')}`);
}
info(...args: any[]) {
console.log(`[${this.prefix}] ${args.join('')}`);
}
error(...args: any[]) {
console.error(`[${this.prefix}] ${args.join('')}`);
}
}
export default new Logger('MissionCenter');

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 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 Logger from './Logger'
import missionManager from '@ohos.application.missionManager'
export default class Mission{
visibility: Visibility = Visibility.Visible
missionInfo
snapshot
constructor(missionInfo) {
this.missionInfo = missionInfo
}
}

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2023 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 accessControl from "@ohos.abilityAccessCtrl";
import bundle from '@ohos.bundle';
import Logger from './Logger'
const BUNDLE_NAME = "com.example.mission_center"
const PERMISSION_REJECT = -1
class Permission{
async requestPermissions(context){
let permissions: Array<string> = [
"ohos.permission.DISTRIBUTED_DATASYNC"
];
let needGrantPermission = false
let accessManager = accessControl.createAtManager()
Logger.info("app permission get bundle info")
let bundleInfo = await bundle.getApplicationInfo(BUNDLE_NAME, 0, 100)
Logger.info(`app permission query permission ${bundleInfo.accessTokenId.toString()}`)
for (const permission of permissions) {
Logger.info(`app permission query grant status ${permission}`)
try {
let grantStatus = await accessManager.verifyAccessToken(bundleInfo.accessTokenId, permission)
if (grantStatus === PERMISSION_REJECT) {
needGrantPermission = true
break;
}
} catch (err) {
Logger.error(`app permission query grant status error ${permission} ${JSON.stringify(err)}`)
needGrantPermission = true
break;
}
}
if (needGrantPermission) {
Logger.info("app permission needGrantPermission")
try {
await context.requestPermissionsFromUser(permissions)
} catch (err) {
Logger.error(`app permission ${JSON.stringify(err)}`)
}
} else {
Logger.info("app permission already granted")
}
}
}
export default new Permission()

View File

@ -0,0 +1,68 @@
/*
* Copyright (c) 2023 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 distributedMissionManager from '@ohos.distributedMissionManager'
import Device from './Device';
import Logger from './Logger'
class RemoteMissionManager{
constructor() {
Logger.info('RemoteMissionManager construct');
}
startSyncRemoteMissions(Device: Device){
Logger.info("sync RemoteMissions start")
var device = {
deviceId: Device.deviceInfo.networkId,
fixConflict: false,
tag: 0
};
distributedMissionManager.startSyncRemoteMissions(device)
.then(data => {
Logger.info("sync RemoteMissions success, data = " + data)
Device.updateMissionInfos()
}).catch(error => {
Logger.error('sync RemoteMissions failed, error = ' + error);
})
}
registerMissionListener(Device: Device){
Logger.info("register MissionListener start")
var MissionCallback = {
notifyMissionsChanged: async function(deviceId){
Logger.info('notifyMissionsChanged deviceId = ' + deviceId);
Device.updateMissionInfos()
},
notifySnapshot: async function(deviceId, missionId){
Logger.info('notifySnapshot missionId = ' + missionId);
},
notifyNetDisconnect: async function(deviceId, state){
Logger.info('notifyNetDisconnect deviceId = ' + deviceId);
},
}
var device = {
deviceId:Device.deviceInfo.networkId
}
let self = this
distributedMissionManager.registerMissionListener(device, MissionCallback).then(data => {
Logger.info("register MissionListener success")
self.startSyncRemoteMissions(Device)
}).catch(error => {
Logger.info("register MissionListener failed, error = " + error)
})
}
}
export default new RemoteMissionManager

View File

@ -0,0 +1,97 @@
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
import Permission from '../Util/Permission'
import bundleManager from '@ohos.bundle.bundleManager';
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
export default class EntryAbility extends UIAbility {
async checkAccessToken(permission: Permissions): Promise<abilityAccessCtrl.GrantStatus> {
let atManager = abilityAccessCtrl.createAtManager();
let grantStatus: abilityAccessCtrl.GrantStatus;
let tokenId: number;
try {
let bundleInfo: bundleManager.BundleInfo = await bundleManager.getBundleInfoForSelf
(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION);
let appInfo: bundleManager.ApplicationInfo = bundleInfo.appInfo;
tokenId = appInfo.accessTokenId;
} catch (err) {
hilog.error(0x0000, 'testTag', 'Failed to get bundle info for self, cause %{public}s',
JSON.stringify(err) ?? '');
}
try {
grantStatus = await atManager.checkAccessToken(tokenId, permission);
} catch (err) {
hilog.error(0x0000, 'testTag', 'Failed to check access token, cause %{public}s',
JSON.stringify(err) ?? '');
}
return grantStatus;
}
async checkPermissions(): Promise<void> {
const permissions: Array<Permissions> = ['ohos.permission.DISTRIBUTED_DATASYNC'];
let grantStatus: abilityAccessCtrl.GrantStatus = await this.checkAccessToken(permissions[0]);
if (grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Permission already granted.');
} else {
let atManager = abilityAccessCtrl.createAtManager();
try {
atManager.requestPermissionsFromUser(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC'], (err, data)=>{
hilog.info(0x0000, 'testTag', 'data: %{public}s', JSON.stringify(data));
hilog.info(0x0000, 'testTag', 'data permissions: %{public}s', data.permissions);
hilog.info(0x0000, 'testTag', 'data authResults: %{public}s', data.authResults);
});
} catch (err) {
hilog.error(0x0000, 'testTag', 'catch err-> %{public}s', JSON.stringify(err) ?? '');
return;
}
}
}
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
globalThis.abilityWant = want;
this.checkPermissions();
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
Permission.requestPermissions(this.context)
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s',
JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
/* Main window is destroyed, release UI related resources */
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
/* Ability has brought to foreground */
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
/* Ability has back to background */
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
}

View File

@ -0,0 +1,193 @@
/*
* Copyright (c) 2023 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 Logger from '../Util/Logger'
import DeviceManager from '../Util/DeviceManager';
import router from '@ohos.router';
if(!AppStorage.Has('isReady')){
AppStorage.Set('isReady',false)
}
if(!AppStorage.Has('isUpdate')){
AppStorage.Set('isUpdate', false)
}
@Entry
@Component
struct Index {
@State deviceManager: typeof DeviceManager = DeviceManager
@StorageLink('isReady') isReady: boolean = false
@StorageLink('isUpdate') isUpdate: boolean = false
@StorageLink('continueResult') continueResult: string = '0'
scroller: Scroller = new Scroller()
build() {
Row() {
Column() {
Button("faultCase")
.fontSize('25fp')
.width('80%')
.height('5%')
.onClick(() => {
router.push({ url: 'pages/faultCase' })
})
Blank().height('2.5%')
Row() {
Text("Continuation")
.fontSize('40fp')
.fontWeight(FontWeight.Bold)
}
Blank().height('2.5%')
if (this.isUpdate||true) {
if (this.isReady) {
Scroll(this.scroller){
Row(){
Text("本机:"+this.deviceManager.localDevice.deviceInfo.deviceName)
.textAlign(TextAlign.Center)
.fontColor(Color.Black)
.backgroundColor(this.deviceManager.localDevice.color)
.fontSize('20fp')
.width(100)
.height(60)
.borderRadius(20)
.onClick(() => {
this.deviceManager.fromDeviceId=this.deviceManager.localDevice.deviceInfo.networkId
this.deviceManager.currentDevice=this.deviceManager.localDevice
this.deviceManager.update()
})
.onDragEnter((event: DragEvent) => {
this.deviceManager.localDevice.color=Color.Blue
this.deviceManager.update()
})
.onDragLeave((event: DragEvent) => {
this.deviceManager.localDevice.color=Color.Grey
this.deviceManager.update()
})
.onDrop((event: DragEvent, extraParams: string) => {
if(this.deviceManager.fromDeviceId!=this.deviceManager.localDevice.deviceInfo.networkId){
this.deviceManager.toDeviceId=this.deviceManager.localDevice.deviceInfo.networkId
Logger.info("fromDeviceId: "+this.deviceManager.fromDeviceId)
Logger.info("missionId: "+this.deviceManager.fromMissionId.toString())
Logger.info("toDeviceId: "+this.deviceManager.toDeviceId)
this.deviceManager.localDevice.color = Color.Green
this.deviceManager.onSelectToDevice(this.deviceManager.localDevice.deviceInfo.networkId)
this.deviceManager.onContinueAbility()
}
else{
Logger.info("the same device")
this.deviceManager.localDevice.color = Color.Grey
this.deviceManager.update()
}
})
Blank().width(10)
ForEach(this.deviceManager.trustedDeviceList, item => {
Text(item.deviceInfo.deviceName)
.textAlign(TextAlign.Center)
.fontColor(Color.Black)
.backgroundColor(item.color)
.fontSize('20fp')
.width(100)
.height(60)
.borderRadius(20)
.onClick(() => {
this.deviceManager.fromDeviceId=item.deviceInfo.networkId
this.deviceManager.currentDevice=item
this.deviceManager.update()
})
.onDragEnter((event: DragEvent) => {
item.color=Color.Blue
this.deviceManager.update()
})
.onDragLeave((event: DragEvent) => {
item.color=Color.Grey
this.deviceManager.update()
})
.onDrop((event: DragEvent, extraParams: string) => {
if (this.deviceManager.fromDeviceId == this.deviceManager.localDevice.deviceInfo.networkId) {
this.deviceManager.toDeviceId = item.deviceInfo.networkId
Logger.info("fromDeviceId: "+this.deviceManager.fromDeviceId)
Logger.info("missionId: "+this.deviceManager.fromMissionId.toString())
Logger.info("toDeviceId: "+this.deviceManager.toDeviceId)
item.color = Color.Green
this.deviceManager.onSelectToDevice(item.deviceInfo.networkId)
this.deviceManager.onContinueAbility()
}
else{
Logger.info("must to local")
this.deviceManager.localDevice.color = Color.Grey
this.deviceManager.update()
}
})
Blank().width(10)
})
}
}
Blank().height(20)
Text(this.deviceManager.currentDevice.deviceInfo.deviceName)
.textAlign(TextAlign.Center)
.fontColor(Color.Black)
.backgroundColor("")
.fontSize('20fp')
Blank().height(50)
List({ space: 20, initialIndex: 0 }) {
ForEach(this.deviceManager.currentDevice.missionList, item => {
ListItem() {
Row() {
Text(item.missionInfo.want.bundleName.split(".")[2])
.width(200)
.height(300)
.fontSize('30fp')
.textAlign(TextAlign.Center)
.borderRadius(10)
.backgroundColor(Color.Grey)
}
}
.onDragStart(() => {
this.deviceManager.fromMissionId=item.missionInfo.missionId
Logger.info("onDragStart")
return this.pixelMapBuilder
})
})
}
.listDirection(Axis.Horizontal)
.height('70%')
}
}
}
.width('100%')
}
.height('100%')
}
@Builder pixelMapBuilder() {
Column() {
Text(this.deviceManager.fromMissionId.toString())
.width('100%').height('100%').fontSize("30fp").borderRadius(10)
.textAlign(TextAlign.Center).backgroundColor(Color.Grey)
.opacity(0.5)
}
.width(200)
.height(300)
}
}
class TrustedDevice {
localDeviceId: string
localMission: number[]
constructor(deviceid: string, mission: number[]) {
this.localDeviceId = deviceid
this.localMission = mission
}
}

View File

@ -0,0 +1,154 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import DeviceManager from '../Util/DeviceManager';
import router from '@ohos.router';
import Logger from '../Util/Logger'
@Entry
@Component
struct Index {
@State deviceManager: typeof DeviceManager = AppStorage.Get<typeof DeviceManager>('DeviceManager')
@State dstDeviceId: string = ''
@State srcDeviceId: string = ''
@State missionId: string = ''
@State isFreeInstall: boolean = true
@StorageLink('continueResult') continueResult: string = '0'
build() {
Column() {
Blank().height('5%')
Row() {
Button() {
Text(" < Back ")
.fontSize('30fp')
.fontWeight(FontWeight.Bold)
.fontColor(Color.Blue)
}
.backgroundColor("")
.onClick(() => {
router.back()
})
Blank().width('80%')
}
Text("异常场景用例")
.fontSize('40fp')
.fontWeight(FontWeight.Bold)
Blank().height('5%')
Row() {
Text("dstDeviceId:")
.fontSize('20fp')
.width('40%')
Column() {
TextInput({text: this.dstDeviceId})
.borderStyle(BorderStyle.Solid)
.type(InputType.Normal)
.onChange((value: string) => {
Logger.info("select toDeviceId: " + value)
})
Blank().height('2%')
Button() {
Text("add remote deviceId")
.fontSize('20fp')
}
.height('5%')
.width('100%')
.onClick(() => {
if (this.deviceManager.trustedDeviceList.length > 0) {
this.dstDeviceId = this.deviceManager.trustedDeviceList[0].deviceInfo.networkId
}
})
}.width('60%')
}
Blank().height('5%')
Row() {
Text("srcDeviceId:")
.fontSize('20fp')
.width('40%')
Column() {
TextInput({text: this.srcDeviceId})
.borderStyle(BorderStyle.Solid)
.type(InputType.Normal)
.onChange((value: string) => {
Logger.info("select fromDeviceId: " + value)
})
Blank().height('2%')
Button() {
Text("add local deviceId")
.fontSize('20fp')
}
.height('5%')
.width('100%')
.onClick(() => {
this.srcDeviceId = this.deviceManager.localDevice.deviceInfo.deviceId
})
}.width('60%')
}
Blank().height('5%')
Row() {
Text("missionId:")
.fontSize('20fp')
.width('40%')
TextInput({text: this.missionId})
.width('60%')
.borderStyle(BorderStyle.Solid)
.type(InputType.Normal)
.onChange((value: string) => {
Logger.info("select fromMissionId: " + value)
this.missionId = value
})
}
Blank().height('5%')
Row() {
Text("isFreeInstall:")
.fontSize('20fp')
.width('40%')
Checkbox()
.select(this.isFreeInstall)
.selectedColor(0x39a2db)
.onChange((value: boolean) => {
Logger.info("select isFreeInstall: " + value)
this.isFreeInstall = value
})
}
Blank().height('5%')
Button() {
Text("Continue Mission")
.fontSize('20fp')
}
.width('80%')
.height('7%')
.onClick(() => {
this.deviceManager.toDeviceId = this.dstDeviceId
this.deviceManager.fromDeviceId = this.srcDeviceId
this.deviceManager.fromMissionId = Number(this.missionId)
this.deviceManager.isFreeInstall = this.isFreeInstall
Logger.info("toDeviceId: " + this.deviceManager.toDeviceId)
Logger.info("fromDeviceId: " + this.deviceManager.fromDeviceId)
Logger.info("fromMissionId: " + this.deviceManager.fromMissionId)
Logger.info("isFreeInstall: " + this.deviceManager.isFreeInstall)
this.deviceManager.onContinueAbility()
})
Blank().height('5%')
Row() {
Text('迁移错误码: ' + this.continueResult)
.fontSize('20fp')
.width('90%')
}
}
}
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntrance": "./ets/entryability/EntryAbility.ts",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
},
{
"name": "ohos.permission.GET_DISTRIBUTED_DEVICE_INFO"
},
{
"name": "ohos.permission.ACCESS_SERVICE_DM"
},
{
"name": "ohos.permission.MANAGE_MISSIONS"
}
]
}
}

View File

@ -0,0 +1 @@
include ':entry'