mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 14:30:21 +00:00
Modify the arkts codex(dmsDemo, continuationManagerTestSuite, continuationManualTestSuite)
issue:https://gitee.com/openharmony/ability_dmsfwk/issues/I8L7UA Signed-off-by: hunili <lihucheng2@huawei.com>
This commit is contained in:
parent
76d22d4ba6
commit
dfaf6921f2
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -12,12 +12,12 @@
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
|
class LocalAbility {
|
||||||
export default {
|
|
||||||
onCreate() {
|
onCreate() {
|
||||||
console.info('Application onCreate')
|
console.info('Application onCreate')
|
||||||
},
|
}
|
||||||
onDestroy() {
|
onDestroy() {
|
||||||
console.info('Application onDestroy')
|
console.info('Application onDestroy')
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
export default new LocalAbility();
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -13,26 +13,28 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default {
|
class RemoteAbility {
|
||||||
onCreate() {
|
onCreate() {
|
||||||
console.info('Application onCreate')
|
console.info('Application onCreate')
|
||||||
},
|
}
|
||||||
onDestroy() {
|
onDestroy() {
|
||||||
console.info('Application onDestroy')
|
console.info('Application onDestroy')
|
||||||
},
|
}
|
||||||
onStartContinuation() {
|
onStartContinuation() {
|
||||||
console.info('onStartContinuation');
|
console.info('onStartContinuation');
|
||||||
return true;
|
return true;
|
||||||
},
|
}
|
||||||
onRestoreData(data) {
|
onRestoreData(data: string) {
|
||||||
console.info('onRestoreData' + data);
|
console.info('onRestoreData' + data);
|
||||||
return true;
|
return true;
|
||||||
},
|
}
|
||||||
onSaveData(data) {
|
onSaveData(data: string) {
|
||||||
console.info('onSaveData');
|
console.info('onSaveData');
|
||||||
return true;
|
return true;
|
||||||
},
|
}
|
||||||
onCompleteContinuation(result) {
|
onCompleteContinuation(result: string) {
|
||||||
console.info('onCompleteContinuation:' + result);
|
console.info('onCompleteContinuation:' + result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default new RemoteAbility();
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -16,15 +16,17 @@
|
|||||||
import featureAbility from '@ohos.ability.featureAbility';
|
import featureAbility from '@ohos.ability.featureAbility';
|
||||||
import prompt from '@system.prompt';
|
import prompt from '@system.prompt';
|
||||||
import rpc from "@ohos.rpc";
|
import rpc from "@ohos.rpc";
|
||||||
import RemoteDeviceModel from '../../model/RemoteDeviceModel.ets';
|
import RemoteDeviceModel from '../../model/RemoteDeviceModel';
|
||||||
|
import Want from '@ohos.app.ability.Want';
|
||||||
|
|
||||||
var connectedAbility;
|
let connectedAbility: number|null;
|
||||||
var localDeviceId = "";
|
let localDeviceId = "";
|
||||||
var mRemote;
|
let mRemote: rpc.IRemoteObject;
|
||||||
var remoteDeviceModel = new RemoteDeviceModel;
|
let remoteDeviceModel = new RemoteDeviceModel;
|
||||||
var mIndex;
|
let mIndex: number;
|
||||||
var mDiscoveredSize = 0;
|
let mValue: string;
|
||||||
var mDeviceSize = 0;
|
let mDiscoveredSize = 0;
|
||||||
|
let mDeviceSize = 0;
|
||||||
|
|
||||||
enum Operation {
|
enum Operation {
|
||||||
AuthDeviceOperation,
|
AuthDeviceOperation,
|
||||||
@ -65,7 +67,7 @@ function registerDeviceListCallback() {
|
|||||||
console.info('[dmsDemo] registerDeviceListCallback end');
|
console.info('[dmsDemo] registerDeviceListCallback end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function authDevice(index) {
|
function authDevice(index: number) {
|
||||||
console.info('[dmsDemo] authDevice begin');
|
console.info('[dmsDemo] authDevice begin');
|
||||||
if (remoteDeviceModel.deviceList.length >= 1 && remoteDeviceModel.discoverList.length == 0) {
|
if (remoteDeviceModel.deviceList.length >= 1 && remoteDeviceModel.discoverList.length == 0) {
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
@ -97,7 +99,7 @@ function unregisterDeviceListCallback() {
|
|||||||
function onStartLocalAbility() {
|
function onStartLocalAbility() {
|
||||||
console.info('[dmsDemo] onStartLocalAbility begin');
|
console.info('[dmsDemo] onStartLocalAbility begin');
|
||||||
console.info('[dmsDemo] onStartLocalAbility deviceId is ' + localDeviceId);
|
console.info('[dmsDemo] onStartLocalAbility deviceId is ' + localDeviceId);
|
||||||
var wantValue = {
|
let wantValue: Want = {
|
||||||
deviceId: localDeviceId,
|
deviceId: localDeviceId,
|
||||||
bundleName: 'ohos.dms.etsDemo',
|
bundleName: 'ohos.dms.etsDemo',
|
||||||
abilityName: 'ohos.dms.etsDemo.LocalAbility',
|
abilityName: 'ohos.dms.etsDemo.LocalAbility',
|
||||||
@ -110,7 +112,7 @@ function onStartLocalAbility() {
|
|||||||
console.info('[dmsDemo] onStartLocalAbility end');
|
console.info('[dmsDemo] onStartLocalAbility end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function onStartRemoteAbility(index) {
|
function onStartRemoteAbility(index: number) {
|
||||||
console.info('[dmsDemo] onStartRemoteAbility begin');
|
console.info('[dmsDemo] onStartRemoteAbility begin');
|
||||||
let numDevices = remoteDeviceModel.deviceList.length;
|
let numDevices = remoteDeviceModel.deviceList.length;
|
||||||
if (numDevices === 0) {
|
if (numDevices === 0) {
|
||||||
@ -119,14 +121,12 @@ function onStartRemoteAbility(index) {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let deviceIdForStart = remoteDeviceModel.deviceList[index - 1].deviceId;
|
let deviceIdForStart: string = remoteDeviceModel.deviceList[index - 1].deviceId;
|
||||||
console.info('[dmsDemo] onStartRemoteAbility deviceId is ' + deviceIdForStart);
|
console.info('[dmsDemo] onStartRemoteAbility deviceId is ' + deviceIdForStart);
|
||||||
var params;
|
let wantValue: Want = {
|
||||||
var wantValue = {
|
|
||||||
bundleName: 'ohos.dms.etsDemo',
|
bundleName: 'ohos.dms.etsDemo',
|
||||||
abilityName: 'ohos.dms.etsDemo.RemoteAbility',
|
abilityName: 'ohos.dms.etsDemo.RemoteAbility',
|
||||||
deviceId: deviceIdForStart,
|
deviceId: deviceIdForStart
|
||||||
parameters: params
|
|
||||||
};
|
};
|
||||||
console.info('[dmsDemo] onStartRemoteAbility want=' + JSON.stringify(wantValue));
|
console.info('[dmsDemo] onStartRemoteAbility want=' + JSON.stringify(wantValue));
|
||||||
featureAbility.startAbility({
|
featureAbility.startAbility({
|
||||||
@ -137,80 +137,9 @@ function onStartRemoteAbility(index) {
|
|||||||
console.info('[dmsDemo] onStartRemoteAbility end');
|
console.info('[dmsDemo] onStartRemoteAbility end');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onContinueLocalAbility() {
|
|
||||||
console.info('[dmsDemo] onContinueLocalAbility begin');
|
|
||||||
console.info('[dmsDemo] onContinueLocalAbility deviceId is ' + localDeviceId);
|
|
||||||
let continueAbilityOptions = {
|
|
||||||
reversible: false,
|
|
||||||
deviceId: localDeviceId,
|
|
||||||
};
|
|
||||||
function ContinueAbilityCallback(err, data) {
|
|
||||||
console.info("[dmsDemo] onContinueLocalAbility ContinueAbilityCallback, result err = " + JSON.stringify(err));
|
|
||||||
console.info("[dmsDemo] onContinueLocalAbility ContinueAbilityCallback, result data= " + JSON.stringify(data));
|
|
||||||
};
|
|
||||||
await featureAbility.continueAbility(continueAbilityOptions, ContinueAbilityCallback);
|
|
||||||
console.info('[dmsDemo] onContinueLocalAbility end');
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onContinueAbility(index) {
|
|
||||||
console.info('[dmsDemo] onContinueAbility begin');
|
|
||||||
let numDevices = remoteDeviceModel.deviceList.length;
|
|
||||||
if (numDevices === 0) {
|
|
||||||
prompt.showToast({
|
|
||||||
message: "onContinueAbility no device found"
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let deviceIdForContinue = remoteDeviceModel.deviceList[index - 1].deviceId;
|
|
||||||
console.info('[dmsDemo] onContinueAbility deviceId is ' + deviceIdForContinue);
|
|
||||||
let continueAbilityOptions = {
|
|
||||||
reversible: false,
|
|
||||||
deviceId: deviceIdForContinue,
|
|
||||||
};
|
|
||||||
function ContinueAbilityCallback(err, data) {
|
|
||||||
console.info("[dmsDemo] onContinueAbility ContinueAbilityCallback, result err = " + JSON.stringify(err));
|
|
||||||
console.info("[dmsDemo] onContinueAbility ContinueAbilityCallback, result data= " + JSON.stringify(data));
|
|
||||||
};
|
|
||||||
await featureAbility.continueAbility(continueAbilityOptions, ContinueAbilityCallback);
|
|
||||||
console.info('[dmsDemo] onContinueAbility end');
|
|
||||||
}
|
|
||||||
|
|
||||||
function onConnectLocalService() {
|
function onConnectLocalService() {
|
||||||
console.info('[dmsDemo] onConnectLocalService begin');
|
console.info('[dmsDemo] onConnectLocalService begin');
|
||||||
console.info('[dmsDemo] onConnectLocalService deviceId is ' + localDeviceId);
|
console.info('[dmsDemo] onConnectLocalService deviceId is ' + localDeviceId);
|
||||||
async function onConnectCallback(element, remote) {
|
|
||||||
console.log('[dmsDemo] onConnectLocalService onConnectDone element: ' + element);
|
|
||||||
console.log('[dmsDemo] onConnectLocalService onConnectDone remote: ' + remote);
|
|
||||||
mRemote = remote;
|
|
||||||
if (mRemote == null) {
|
|
||||||
prompt.showToast({
|
|
||||||
message: "onConnectLocalService not connected yet"
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let option = new rpc.MessageOption();
|
|
||||||
let data = new rpc.MessageParcel();
|
|
||||||
let reply = new rpc.MessageParcel();
|
|
||||||
data.writeInt(1);
|
|
||||||
data.writeInt(99);
|
|
||||||
await mRemote.sendRequest(1, data, reply, option);
|
|
||||||
let msg = reply.readInt();
|
|
||||||
prompt.showToast({
|
|
||||||
message: "onConnectLocalService connect result: " + msg,
|
|
||||||
duration: 3000
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onDisconnectCallback(element) {
|
|
||||||
console.log('[dmsDemo] onConnectLocalService onDisconnectDone element: ' + element);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onFailedCallback(code) {
|
|
||||||
console.log('[dmsDemo] onConnectLocalService onFailed errCode: ' + code)
|
|
||||||
prompt.showToast({
|
|
||||||
message: "onConnectLocalService onFailed: " + code
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
connectedAbility = featureAbility.connectAbility(
|
connectedAbility = featureAbility.connectAbility(
|
||||||
{
|
{
|
||||||
@ -219,49 +148,44 @@ function onConnectLocalService() {
|
|||||||
abilityName: "ohos.dms.js.ServiceAbility",
|
abilityName: "ohos.dms.js.ServiceAbility",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onConnect: onConnectCallback,
|
onConnect: async (element, remote) => {
|
||||||
onDisconnect: onDisconnectCallback,
|
console.log('[dmsDemo] onConnectLocalService onConnectDone element: ' + element);
|
||||||
onFailed: onFailedCallback,
|
console.log('[dmsDemo] onConnectLocalService onConnectDone remote: ' + remote);
|
||||||
|
mRemote = remote;
|
||||||
|
if (mRemote == null) {
|
||||||
|
prompt.showToast({
|
||||||
|
message: "onConnectLocalService not connected yet"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let option = new rpc.MessageOption();
|
||||||
|
let data = new rpc.MessageSequence();
|
||||||
|
let reply = new rpc.MessageSequence();
|
||||||
|
data.writeInt(1);
|
||||||
|
data.writeInt(99);
|
||||||
|
await mRemote.sendMessageRequest(1, data, reply, option);
|
||||||
|
let msg = reply.readInt();
|
||||||
|
prompt.showToast({
|
||||||
|
message: "onConnectLocalService connect result: " + msg,
|
||||||
|
duration: 3000
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onDisconnect: (element) => {
|
||||||
|
console.log('[dmsDemo] onConnectLocalService onDisconnectDone element: ' + element);
|
||||||
|
},
|
||||||
|
onFailed: (code) => {
|
||||||
|
console.log('[dmsDemo] onConnectLocalService onFailed errCode: ' + code)
|
||||||
|
prompt.showToast({
|
||||||
|
message: "onConnectLocalService onFailed: " + code
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
console.log('[dmsDemo] onConnectLocalService connectedAbility: ' + connectedAbility)
|
console.log('[dmsDemo] onConnectLocalService connectedAbility: ' + connectedAbility)
|
||||||
}
|
}
|
||||||
|
|
||||||
function onConnectRemoteService(index) {
|
function onConnectRemoteService(index: number) {
|
||||||
console.info('[dmsDemo] onConnectRemoteService begin');
|
console.info('[dmsDemo] onConnectRemoteService begin');
|
||||||
async function onConnectCallback(element, remote) {
|
|
||||||
console.log('[dmsDemo] onConnectRemoteService onConnectDone element: ' + element);
|
|
||||||
console.log('[dmsDemo] onConnectRemoteService onConnectDone remote: ' + remote);
|
|
||||||
mRemote = remote;
|
|
||||||
if (mRemote == null) {
|
|
||||||
prompt.showToast({
|
|
||||||
message: "onConnectRemoteService not connected yet"
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let option = new rpc.MessageOption();
|
|
||||||
let data = new rpc.MessageParcel();
|
|
||||||
let reply = new rpc.MessageParcel();
|
|
||||||
data.writeInt(1);
|
|
||||||
data.writeInt(99);
|
|
||||||
await mRemote.sendRequest(1, data, reply, option);
|
|
||||||
let msg = reply.readInt();
|
|
||||||
prompt.showToast({
|
|
||||||
message: "onConnectRemoteService connect result: " + msg,
|
|
||||||
duration: 3000
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onDisconnectCallback(element) {
|
|
||||||
console.log('[dmsDemo] onConnectRemoteService onDisconnectDone element: ' + element);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onFailedCallback(code) {
|
|
||||||
console.log('[dmsDemo] onConnectRemoteService onFailed errCode: ' + code)
|
|
||||||
prompt.showToast({
|
|
||||||
message: "onConnectRemoteService onFailed: " + code
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let numDevices = remoteDeviceModel.deviceList.length;
|
let numDevices = remoteDeviceModel.deviceList.length;
|
||||||
if (numDevices === 0) {
|
if (numDevices === 0) {
|
||||||
@ -270,20 +194,53 @@ function onConnectRemoteService(index) {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let deviceIdForConnect = remoteDeviceModel.deviceList[index - 1].deviceId;
|
let networkId = remoteDeviceModel.deviceList[index - 1].networkId;
|
||||||
console.info('[dmsDemo] onConnectRemoteService deviceId is ' + deviceIdForConnect);
|
|
||||||
connectedAbility = featureAbility.connectAbility(
|
if (networkId) {
|
||||||
{
|
console.info('[dmsDemo] onConnectRemoteService networkId is ' + networkId);
|
||||||
deviceId: deviceIdForConnect,
|
connectedAbility = featureAbility.connectAbility(
|
||||||
bundleName: "ohos.dms.js",
|
{
|
||||||
abilityName: "ohos.dms.js.ServiceAbility",
|
deviceId: networkId,
|
||||||
},
|
bundleName: "ohos.dms.js",
|
||||||
{
|
abilityName: "ohos.dms.js.ServiceAbility",
|
||||||
onConnect: onConnectCallback,
|
},
|
||||||
onDisconnect: onDisconnectCallback,
|
{
|
||||||
onFailed: onFailedCallback,
|
onConnect: async (element, remote) => {
|
||||||
},
|
console.log('[dmsDemo] onConnectRemoteService onConnectDone element: ' + element);
|
||||||
);
|
console.log('[dmsDemo] onConnectRemoteService onConnectDone remote: ' + remote);
|
||||||
|
mRemote = remote;
|
||||||
|
if (mRemote == null) {
|
||||||
|
prompt.showToast({
|
||||||
|
message: "onConnectRemoteService not connected yet"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let option = new rpc.MessageOption();
|
||||||
|
let data = new rpc.MessageSequence();
|
||||||
|
let reply = new rpc.MessageSequence();
|
||||||
|
data.writeInt(1);
|
||||||
|
data.writeInt(99);
|
||||||
|
await mRemote.sendMessageRequest(1, data, reply, option);
|
||||||
|
let msg = reply.readInt();
|
||||||
|
prompt.showToast({
|
||||||
|
message: "onConnectRemoteService connect result: " + msg,
|
||||||
|
duration: 3000
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onDisconnect: (element) => {
|
||||||
|
console.log('[dmsDemo] onConnectRemoteService onDisconnectDone element: ' + element);
|
||||||
|
},
|
||||||
|
onFailed: (code) => {
|
||||||
|
console.log('[dmsDemo] onConnectRemoteService onFailed errCode: ' + code)
|
||||||
|
prompt.showToast({
|
||||||
|
message: "onConnectRemoteService onFailed: " + code
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.error('[dmsDemo] onConnectRemoteService get networkId error');
|
||||||
|
}
|
||||||
console.log('[dmsDemo] onConnectRemoteService connectedAbility: ' + connectedAbility)
|
console.log('[dmsDemo] onConnectRemoteService connectedAbility: ' + connectedAbility)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,8 +262,8 @@ async function onDisconnectService() {
|
|||||||
@CustomDialog
|
@CustomDialog
|
||||||
struct CustomDialogExample {
|
struct CustomDialogExample {
|
||||||
controller: CustomDialogController
|
controller: CustomDialogController
|
||||||
cancel: () => void
|
cancel: () => void = ()=>{}
|
||||||
confirm: () => void
|
confirm: () => void = ()=>{}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Column() {
|
Column() {
|
||||||
@ -315,7 +272,7 @@ struct CustomDialogExample {
|
|||||||
.enterKeyType(EnterKeyType.Send)
|
.enterKeyType(EnterKeyType.Send)
|
||||||
.onChange((value) => {
|
.onChange((value) => {
|
||||||
console.log('[dmsDemo] TextInput onChange:' + value);
|
console.log('[dmsDemo] TextInput onChange:' + value);
|
||||||
mIndex = value;
|
mValue = value;
|
||||||
}).onSubmit((enterKey) => {
|
}).onSubmit((enterKey) => {
|
||||||
console.log('[dmsDemo] TextInput onSubmit:' + enterKey);
|
console.log('[dmsDemo] TextInput onSubmit:' + enterKey);
|
||||||
}).onEditChanged((isEditing) => {
|
}).onEditChanged((isEditing) => {
|
||||||
@ -375,15 +332,6 @@ struct Index {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onStartRemoteAbility(mIndex);
|
onStartRemoteAbility(mIndex);
|
||||||
} else if (mOperation === Operation.ContinueAbilityOperation) {
|
|
||||||
console.info('[dmsDemo] call onContinueAbility, device index: ' + mIndex);
|
|
||||||
if (mIndex > mDeviceSize) {
|
|
||||||
prompt.showToast({
|
|
||||||
message: "Please input correct device index."
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
onContinueAbility(mIndex);
|
|
||||||
} else if (mOperation === Operation.ConnectRemoteServiceOperation){
|
} else if (mOperation === Operation.ConnectRemoteServiceOperation){
|
||||||
console.info('[dmsDemo] call onConnectRemoteService, device index: ' + mIndex);
|
console.info('[dmsDemo] call onConnectRemoteService, device index: ' + mIndex);
|
||||||
if (mIndex > mDeviceSize) {
|
if (mIndex > mDeviceSize) {
|
||||||
@ -469,19 +417,6 @@ struct Index {
|
|||||||
this.dialogController.open();
|
this.dialogController.open();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
|
||||||
Text('ContinueLocalAbility')
|
|
||||||
.fontSize(20)
|
|
||||||
.fontWeight(FontWeight.Bold)
|
|
||||||
}.type(ButtonType.Capsule)
|
|
||||||
.margin({
|
|
||||||
top: 20
|
|
||||||
})
|
|
||||||
.backgroundColor('#0D9FFB')
|
|
||||||
.onClick(() => {
|
|
||||||
onContinueLocalAbility();
|
|
||||||
})
|
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
Text('ContinueAbility')
|
Text('ContinueAbility')
|
||||||
.fontSize(20)
|
.fontSize(20)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -13,50 +13,48 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import deviceManager from '@ohos.distributedHardware.deviceManager';
|
import distributedDeviceManager from '@ohos.distributedDeviceManager';
|
||||||
|
import { Callback } from '@ohos.base';
|
||||||
|
|
||||||
var SUBSCRIBE_ID = 100;
|
let SUBSCRIBE_ID = 100;
|
||||||
|
let BundleName = 'com.ohos.distributedmusicplayer';
|
||||||
|
|
||||||
export default class RemoteDeviceModel {
|
export default class RemoteDeviceModel {
|
||||||
deviceList = [];
|
deviceList: distributedDeviceManager.DeviceBasicInfo[] = [];
|
||||||
discoverList = [];
|
discoverList: distributedDeviceManager.DeviceBasicInfo[] = [];
|
||||||
callback;
|
callback: Callback<void> = ()=>{};
|
||||||
authCallback = null;
|
authCallback: Callback<void>| null = null;
|
||||||
#deviceManager;
|
deviceManager = distributedDeviceManager.createDeviceManager(BundleName);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
registerDeviceListCallback(callback) {
|
registerDeviceListCallback(callback: Callback<void>) {
|
||||||
if (typeof (this.#deviceManager) === 'undefined') {
|
if (typeof (this.deviceManager) === 'undefined') {
|
||||||
|
this.deviceManager = distributedDeviceManager.createDeviceManager(BundleName);
|
||||||
|
if (this.deviceManager) {
|
||||||
|
console.info('create DeviceManager success');
|
||||||
|
this.registerDeviceListCallback_(callback);
|
||||||
|
} else {
|
||||||
|
console.error('create DeviceManager error');
|
||||||
|
}
|
||||||
console.log('[dmsDemo] deviceManager.createDeviceManager begin');
|
console.log('[dmsDemo] deviceManager.createDeviceManager begin');
|
||||||
let self = this;
|
|
||||||
deviceManager.createDeviceManager('com.ohos.distributedmusicplayer', (error, value) => {
|
|
||||||
if (error) {
|
|
||||||
console.error('createDeviceManager failed.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.#deviceManager = value;
|
|
||||||
self.registerDeviceListCallback_(callback);
|
|
||||||
console.log('[dmsDemo] createDeviceManager callback returned, error=' + error + ' value=' + value);
|
|
||||||
});
|
|
||||||
console.log('[dmsDemo] deviceManager.createDeviceManager end');
|
|
||||||
} else {
|
} else {
|
||||||
this.registerDeviceListCallback_(callback);
|
this.registerDeviceListCallback_(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerDeviceListCallback_(callback) {
|
registerDeviceListCallback_(callback: Callback<void>) {
|
||||||
console.info('[dmsDemo] registerDeviceListCallback');
|
console.info('[dmsDemo] registerDeviceListCallback');
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
if (this.#deviceManager == undefined) {
|
if (this.deviceManager == undefined) {
|
||||||
console.error('[dmsDemo] deviceManager has not initialized');
|
console.error('[dmsDemo] deviceManager has not initialized');
|
||||||
this.callback();
|
this.callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info('[dmsDemo] getTrustedDeviceListSync begin');
|
console.info('[dmsDemo] getTrustedDeviceListSync begin');
|
||||||
var list = this.#deviceManager.getTrustedDeviceListSync();
|
let list = this.deviceManager.getAvailableDeviceListSync();
|
||||||
console.info('[dmsDemo] getTrustedDeviceListSync end, deviceList=' + JSON.stringify(list));
|
console.info('[dmsDemo] getTrustedDeviceListSync end, deviceList=' + JSON.stringify(list));
|
||||||
if (typeof (list) != 'undefined' && typeof (list.length) != 'undefined') {
|
if (typeof (list) != 'undefined' && typeof (list.length) != 'undefined') {
|
||||||
this.deviceList = list;
|
this.deviceList = list;
|
||||||
@ -64,13 +62,14 @@ export default class RemoteDeviceModel {
|
|||||||
this.callback();
|
this.callback();
|
||||||
console.info('[dmsDemo] callback finished');
|
console.info('[dmsDemo] callback finished');
|
||||||
|
|
||||||
registerDeviceStateChangeCallback();
|
this.registerDeviceStateChangeCallback();
|
||||||
registerDeviceFoundCallback();
|
this.registerDeviceFoundCallback();
|
||||||
registerDiscoverFailCallback();
|
this.registerDiscoverFailCallback();
|
||||||
registerServiceDieCallback();
|
this.registerServiceDieCallback();
|
||||||
|
|
||||||
SUBSCRIBE_ID = Math.floor(65536 * Math.random());
|
SUBSCRIBE_ID = Math.floor(65536 * Math.random());
|
||||||
var info = {
|
console.info('[dmsDemo] startDeviceDiscovery ' + SUBSCRIBE_ID);
|
||||||
|
this.deviceManager.startDiscovering({
|
||||||
subscribeId: SUBSCRIBE_ID,
|
subscribeId: SUBSCRIBE_ID,
|
||||||
mode: 0xAA,
|
mode: 0xAA,
|
||||||
medium: 2,
|
medium: 2,
|
||||||
@ -78,49 +77,46 @@ export default class RemoteDeviceModel {
|
|||||||
isSameAccount: false,
|
isSameAccount: false,
|
||||||
isWakeRemote: true,
|
isWakeRemote: true,
|
||||||
capability: 0
|
capability: 0
|
||||||
};
|
})
|
||||||
console.info('[dmsDemo] startDeviceDiscovery ' + SUBSCRIBE_ID);
|
|
||||||
this.#deviceManager.startDeviceDiscovery(info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerDeviceStateChangeCallback() {
|
registerDeviceStateChangeCallback() {
|
||||||
let self = this;
|
this.deviceManager.on('deviceStateChange', (data) => {
|
||||||
this.#deviceManager.on('deviceStateChange', (data) => {
|
|
||||||
console.info('[dmsDemo] deviceStateChange data=' + JSON.stringify(data));
|
console.info('[dmsDemo] deviceStateChange data=' + JSON.stringify(data));
|
||||||
switch (data.action) {
|
switch (data.action) {
|
||||||
case 0:
|
case 0:
|
||||||
self.deviceList[self.deviceList.length] = data.device;
|
this.deviceList[this.deviceList.length] = data.device;
|
||||||
console.info('[dmsDemo] online, updated device list=' + JSON.stringify(self.deviceList));
|
console.info('[dmsDemo] online, updated device list=' + JSON.stringify(this.deviceList));
|
||||||
self.callback();
|
this.callback();
|
||||||
if (self.authCallback != null) {
|
if (this.authCallback != null) {
|
||||||
self.authCallback();
|
this.authCallback();
|
||||||
self.authCallback = null;
|
this.authCallback = null;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (self.deviceList.length > 0) {
|
if (this.deviceList.length > 0) {
|
||||||
for (var i = 0; i < self.deviceList.length; i++) {
|
for (let i = 0; i < this.deviceList.length; i++) {
|
||||||
if (self.deviceList[i].deviceId === data.device.deviceId) {
|
if (this.deviceList[i].deviceId === data.device.deviceId) {
|
||||||
self.deviceList[i] = data.device;
|
this.deviceList[i] = data.device;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.info('[dmsDemo] change, updated device list=' + JSON.stringify(self.deviceList));
|
console.info('[dmsDemo] change, updated device list=' + JSON.stringify(this.deviceList));
|
||||||
self.callback();
|
this.callback();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (self.deviceList.length > 0) {
|
if (this.deviceList.length > 0) {
|
||||||
var list = [];
|
let list: distributedDeviceManager.DeviceBasicInfo[] = [];
|
||||||
for (var i = 0; i < self.deviceList.length; i++) {
|
for (let i = 0; i < this.deviceList.length; i++) {
|
||||||
if (self.deviceList[i].deviceId != data.device.deviceId) {
|
if (this.deviceList[i].networkId != data.device.networkId) {
|
||||||
list[i] = data.device;
|
list[i] = data.device as distributedDeviceManager.DeviceBasicInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.deviceList = list;
|
this.deviceList = list;
|
||||||
}
|
}
|
||||||
console.info('[dmsDemo] offline, updated device list=' + JSON.stringify(data.device));
|
console.info('[dmsDemo] offline, updated device list=' + JSON.stringify(data.device));
|
||||||
self.callback();
|
this.callback();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -129,72 +125,70 @@ export default class RemoteDeviceModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerDeviceFoundCallback() {
|
registerDeviceFoundCallback() {
|
||||||
this.#deviceManager.on('deviceFound', (data) => {
|
this.deviceManager.on('discoverSuccess', (data) => {
|
||||||
console.info('[dmsDemo] deviceFound data=' + JSON.stringify(data));
|
console.info('[dmsDemo] deviceFound data=' + JSON.stringify(data));
|
||||||
console.info('[dmsDemo] deviceFound self.deviceList=' + self.deviceList);
|
console.info('[dmsDemo] deviceFound this.deviceList=' + this.deviceList);
|
||||||
console.info('[dmsDemo] deviceFound self.deviceList.length=' + self.deviceList.length);
|
console.info('[dmsDemo] deviceFound this.deviceList.length=' + this.deviceList.length);
|
||||||
for (var i = 0; i < self.discoverList.length; i++) {
|
for (let i = 0; i < this.discoverList.length; i++) {
|
||||||
if (self.discoverList[i].deviceId === data.device.deviceId) {
|
if (this.discoverList[i].deviceId === data.device.deviceId) {
|
||||||
console.info('[dmsDemo] device founded, ignored');
|
console.info('[dmsDemo] device founded, ignored');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.discoverList[self.discoverList.length] = data.device;
|
this.discoverList[this.discoverList.length] = data.device;
|
||||||
self.callback();
|
this.callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
registerDiscoverFailCallback() {
|
registerDiscoverFailCallback() {
|
||||||
this.#deviceManager.on('discoverFail', (data) => {
|
this.deviceManager.on('discoverFailure', (data) => {
|
||||||
console.info('[dmsDemo] discoverFail data=' + JSON.stringify(data));
|
console.info('[dmsDemo] discoverFail data=' + JSON.stringify(data));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
registerServiceDieCallback() {
|
registerServiceDieCallback() {
|
||||||
this.#deviceManager.on('serviceDie', () => {
|
this.deviceManager.on('serviceDie', () => {
|
||||||
console.error('[dmsDemo] serviceDie');
|
console.error('[dmsDemo] serviceDie');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
authDevice(deviceId, callback) {
|
authDevice(deviceId: string, callback: Callback<void>) {
|
||||||
console.info('[dmsDemo] authDevice ' + deviceId);
|
console.info('[dmsDemo] authDevice ' + deviceId);
|
||||||
for (var i = 0; i < this.discoverList.length; i++) {
|
for (let i = 0; i < this.discoverList.length; i++) {
|
||||||
if (this.discoverList[i].deviceId === deviceId) {
|
if (this.discoverList[i].deviceId === deviceId) {
|
||||||
console.info('[dmsDemo] device founded, ignored');
|
console.info('[dmsDemo] device founded, ignored');
|
||||||
let extraInfo = {
|
|
||||||
"targetPkgName": 'com.ohos.distributedmusicplayer',
|
|
||||||
"appName": 'Music',
|
|
||||||
"appDescription": 'Music player application',
|
|
||||||
"business": '0'
|
|
||||||
};
|
|
||||||
let authParam = {
|
|
||||||
"authType": 1,
|
|
||||||
"appIcon": '',
|
|
||||||
"appThumbnail": '',
|
|
||||||
"extraInfo": extraInfo
|
|
||||||
};
|
|
||||||
console.info('[dmsDemo] authenticateDevice ' + JSON.stringify(this.discoverList[i]));
|
console.info('[dmsDemo] authenticateDevice ' + JSON.stringify(this.discoverList[i]));
|
||||||
let self = this;
|
this.deviceManager.bindTarget(this.discoverList[i].networkId,
|
||||||
this.#deviceManager.authenticateDevice(this.discoverList[i], authParam, (err, data) => {
|
{
|
||||||
if (err) {
|
"authType": 1,
|
||||||
console.info('[dmsDemo] authenticateDevice failed, err=' + JSON.stringify(err));
|
"appIcon": '',
|
||||||
self.authCallback = null;
|
"appThumbnail": '',
|
||||||
} else {
|
"extraInfo": {
|
||||||
console.info('[dmsDemo] authenticateDevice succeed, data=' + JSON.stringify(data));
|
"targetPkgName": 'com.ohos.distributedmusicplayer',
|
||||||
self.authCallback = callback;
|
"appName": 'Music',
|
||||||
}
|
"appDescription": 'Music player application',
|
||||||
});
|
"business": '0'
|
||||||
|
}
|
||||||
|
}, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
console.info('[dmsDemo] authenticateDevice failed, err=' + JSON.stringify(err));
|
||||||
|
this.authCallback = null;
|
||||||
|
} else {
|
||||||
|
console.info('[dmsDemo] authenticateDevice succeed, data=' + JSON.stringify(data));
|
||||||
|
this.authCallback = callback;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unregisterDeviceListCallback() {
|
unregisterDeviceListCallback() {
|
||||||
console.info('[dmsDemo] stopDeviceDiscovery ' + SUBSCRIBE_ID);
|
console.info('[dmsDemo] stopDeviceDiscovery ');
|
||||||
this.#deviceManager.stopDeviceDiscovery(SUBSCRIBE_ID);
|
this.deviceManager.stopDiscovering();
|
||||||
this.#deviceManager.off('deviceStateChange');
|
this.deviceManager.off('deviceStateChange');
|
||||||
this.#deviceManager.off('deviceFound');
|
this.deviceManager.off('discoverSuccess');
|
||||||
this.#deviceManager.off('discoverFail');
|
this.deviceManager.off('discoverFailure');
|
||||||
this.#deviceManager.off('serviceDie');
|
this.deviceManager.off('serviceDie');
|
||||||
this.deviceList = [];
|
this.deviceList = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"color": [
|
||||||
|
{
|
||||||
|
"name": "start_window_background",
|
||||||
|
"value": "#FFFFFF"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
|
@ -14,11 +14,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Ability from '@ohos.app.ability.UIAbility'
|
import Ability from '@ohos.app.ability.UIAbility'
|
||||||
import abilityAccessCtrl from "@ohos.abilityAccessCtrl";
|
import abilityAccessCtrl, { Permissions } from "@ohos.abilityAccessCtrl";
|
||||||
import bundle from '@ohos.bundle';
|
import bundle from '@ohos.bundle';
|
||||||
import continuationManager from '@ohos.continuation.continuationManager';
|
import continuationManager from '@ohos.continuation.continuationManager';
|
||||||
import prompt from '@system.prompt';
|
import prompt from '@system.prompt';
|
||||||
import rpc from '@ohos.rpc'
|
import rpc from '@ohos.rpc'
|
||||||
|
import bundleManager from '@ohos.bundle.bundleManager';
|
||||||
|
import Want from '@ohos.app.ability.Want';
|
||||||
|
|
||||||
const SHOW_TOAST_TIME = 3000; // ms
|
const SHOW_TOAST_TIME = 3000; // ms
|
||||||
const DEVICE_TYPE = "00E";
|
const DEVICE_TYPE = "00E";
|
||||||
@ -30,62 +32,30 @@ let mRemote;
|
|||||||
let connectedAbility;
|
let connectedAbility;
|
||||||
let token = -1;
|
let token = -1;
|
||||||
|
|
||||||
async function requestPermission() {
|
|
||||||
let permissions: Array<string> = [
|
|
||||||
"ohos.permission.DISTRIBUTED_DATASYNC"
|
|
||||||
];
|
|
||||||
let needGrantPermission = false;
|
|
||||||
let accessManger = abilityAccessCtrl.createAtManager();
|
|
||||||
|
|
||||||
let bundleInfo = await bundle.getApplicationInfo('ohos.samples.continuationmanager', 0, 100)
|
|
||||||
for (const permission of permissions) {
|
|
||||||
console.info('[Demo]app permission query grant status' + permission);
|
|
||||||
try {
|
|
||||||
let grantStatus = await accessManger.verifyAccessToken(bundleInfo.accessTokenId, permission);
|
|
||||||
if (grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_DENIED) {
|
|
||||||
needGrantPermission = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('[Demo]app permission query grant status error' + JSON.stringify(err));
|
|
||||||
needGrantPermission = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (needGrantPermission) {
|
|
||||||
console.info('[Demo]app permission needGrantPermission');
|
|
||||||
try {
|
|
||||||
await globalThis.context.requestPermissionsFromUser(permissions);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('[Demo]app permission' + JSON.stringify(err));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.info('[Demo]app permission already granted');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function register() {
|
function registerContinuation(): void {
|
||||||
console.info('[Demo]register begin');
|
console.info('[Demo]registerContinuation begin');
|
||||||
continuationManager.register()
|
continuationManager.registerContinuation()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]register finished, ' + JSON.stringify(data));
|
console.info('[Demo]registerContinuation finished, ' + JSON.stringify(data));
|
||||||
token = data;
|
token = data;
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
message: "[Demo]register token: " + JSON.stringify(data),
|
message: "[Demo]registerContinuation token: " + JSON.stringify(data),
|
||||||
duration: SHOW_TOAST_TIME
|
duration: SHOW_TOAST_TIME
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('[Demo]register failed, cause: ' + JSON.stringify(err));
|
console.error('[Demo]registerContinuation failed, cause: ' + JSON.stringify(err));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
message: "[Demo]register err: " + err,
|
message: "[Demo]registerContinuation err: " + err,
|
||||||
duration: SHOW_TOAST_TIME
|
duration: SHOW_TOAST_TIME
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
console.info('[Demo]register end');
|
console.info('[Demo]registerContinuation end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerWithExtraParams() {
|
function registerWithExtraParams(): void {
|
||||||
console.info('[Demo]registerWithExtraParams begin');
|
console.info('[Demo]registerWithExtraParams begin');
|
||||||
let continuationExtraParams = {
|
let continuationExtraParams = {
|
||||||
deviceType: [DEVICE_TYPE],
|
deviceType: [DEVICE_TYPE],
|
||||||
@ -95,7 +65,7 @@ function registerWithExtraParams() {
|
|||||||
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
||||||
authInfo: {"name": "authInfo", "length": 8}
|
authInfo: {"name": "authInfo", "length": 8}
|
||||||
};
|
};
|
||||||
continuationManager.register(continuationExtraParams)
|
continuationManager.registerContinuation(continuationExtraParams)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]registerWithExtraParams finished, ' + JSON.stringify(data));
|
console.info('[Demo]registerWithExtraParams finished, ' + JSON.stringify(data));
|
||||||
token = data;
|
token = data;
|
||||||
@ -114,7 +84,7 @@ function registerWithExtraParams() {
|
|||||||
console.info('[Demo]registerWithExtraParams end');
|
console.info('[Demo]registerWithExtraParams end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerWithInvalidFilter() {
|
function registerWithInvalidFilter(): void {
|
||||||
console.info('[Demo]registerWithInvalidFilter begin');
|
console.info('[Demo]registerWithInvalidFilter begin');
|
||||||
let continuationExtraParams = {
|
let continuationExtraParams = {
|
||||||
deviceType: [DEVICE_TYPE],
|
deviceType: [DEVICE_TYPE],
|
||||||
@ -124,7 +94,7 @@ function registerWithInvalidFilter() {
|
|||||||
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
||||||
authInfo: {"name": "authInfo", "length": 8}
|
authInfo: {"name": "authInfo", "length": 8}
|
||||||
};
|
};
|
||||||
continuationManager.register(continuationExtraParams)
|
continuationManager.registerContinuation(continuationExtraParams)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]registerWithInvalidFilter finished, ' + JSON.stringify(data));
|
console.info('[Demo]registerWithInvalidFilter finished, ' + JSON.stringify(data));
|
||||||
token = data;
|
token = data;
|
||||||
@ -143,7 +113,7 @@ function registerWithInvalidFilter() {
|
|||||||
console.info('[Demo]registerWithInvalidFilter end');
|
console.info('[Demo]registerWithInvalidFilter end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerWithoutFilter() {
|
function registerWithoutFilter(): void {
|
||||||
console.info('[Demo]registerWithoutFilter begin');
|
console.info('[Demo]registerWithoutFilter begin');
|
||||||
let continuationExtraParams = {
|
let continuationExtraParams = {
|
||||||
deviceType: [DEVICE_TYPE],
|
deviceType: [DEVICE_TYPE],
|
||||||
@ -152,7 +122,7 @@ function registerWithoutFilter() {
|
|||||||
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
||||||
authInfo: {"name": "authInfo", "length": 8}
|
authInfo: {"name": "authInfo", "length": 8}
|
||||||
};
|
};
|
||||||
continuationManager.register(continuationExtraParams)
|
continuationManager.registerContinuation(continuationExtraParams)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]registerWithoutFilter finished, ' + JSON.stringify(data));
|
console.info('[Demo]registerWithoutFilter finished, ' + JSON.stringify(data));
|
||||||
token = data;
|
token = data;
|
||||||
@ -171,7 +141,7 @@ function registerWithoutFilter() {
|
|||||||
console.info('[Demo]registerWithoutFilter end');
|
console.info('[Demo]registerWithoutFilter end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerWithInvalidContinuationMode() {
|
function registerWithInvalidContinuationMode(): void {
|
||||||
console.info('[Demo]registerWithInvalidContinuationMode begin');
|
console.info('[Demo]registerWithInvalidContinuationMode begin');
|
||||||
let continuationExtraParams = {
|
let continuationExtraParams = {
|
||||||
deviceType: [DEVICE_TYPE],
|
deviceType: [DEVICE_TYPE],
|
||||||
@ -181,7 +151,7 @@ function registerWithInvalidContinuationMode() {
|
|||||||
continuationMode: INVALID_CONTINUATION_MODE,
|
continuationMode: INVALID_CONTINUATION_MODE,
|
||||||
authInfo: {"name": "authInfo", "length": 8}
|
authInfo: {"name": "authInfo", "length": 8}
|
||||||
};
|
};
|
||||||
continuationManager.register(continuationExtraParams)
|
continuationManager.registerContinuation(continuationExtraParams)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]registerWithInvalidContinuationMode finished, ' + JSON.stringify(data));
|
console.info('[Demo]registerWithInvalidContinuationMode finished, ' + JSON.stringify(data));
|
||||||
token = data;
|
token = data;
|
||||||
@ -200,9 +170,9 @@ function registerWithInvalidContinuationMode() {
|
|||||||
console.info('[Demo]registerWithInvalidContinuationMode end');
|
console.info('[Demo]registerWithInvalidContinuationMode end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDeviceConnect() {
|
function onDeviceConnect() : void{
|
||||||
console.info('[Demo]onDeviceConnect begin');
|
console.info('[Demo]onDeviceConnect begin');
|
||||||
continuationManager.on("deviceConnect", token, (data) => {
|
continuationManager.on("deviceSelected", token, (data) => {
|
||||||
console.info('[Demo]onDeviceConnect len: ' + data.length);
|
console.info('[Demo]onDeviceConnect len: ' + data.length);
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
console.info('[Demo]onDeviceConnect deviceId: ' + JSON.stringify(data[i].id));
|
console.info('[Demo]onDeviceConnect deviceId: ' + JSON.stringify(data[i].id));
|
||||||
@ -218,9 +188,9 @@ function onDeviceConnect() {
|
|||||||
console.info('[Demo]onDeviceConnect end');
|
console.info('[Demo]onDeviceConnect end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDeviceConnectWithInvalidToken() {
|
function onDeviceConnectWithInvalidToken(): void {
|
||||||
console.info('[Demo]onDeviceConnectWithInvalidToken begin');
|
console.info('[Demo]onDeviceConnectWithInvalidToken begin');
|
||||||
continuationManager.on("deviceConnect", INVALID_TOKEN, (data) => {
|
continuationManager.on("deviceSelected", INVALID_TOKEN, (data) => {
|
||||||
console.info('[Demo]onDeviceConnectWithInvalidToken len: ' + data.length);
|
console.info('[Demo]onDeviceConnectWithInvalidToken len: ' + data.length);
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
console.info('[Demo]onDeviceConnectWithInvalidToken deviceId: ' + JSON.stringify(data[i].id));
|
console.info('[Demo]onDeviceConnectWithInvalidToken deviceId: ' + JSON.stringify(data[i].id));
|
||||||
@ -236,9 +206,9 @@ function onDeviceConnectWithInvalidToken() {
|
|||||||
console.info('[Demo]onDeviceConnectWithInvalidToken end');
|
console.info('[Demo]onDeviceConnectWithInvalidToken end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDeviceDisconnect() {
|
function onDeviceDisconnect(): void {
|
||||||
console.info('[Demo]onDeviceDisconnect begin');
|
console.info('[Demo]onDeviceDisconnect begin');
|
||||||
continuationManager.on("deviceDisconnect", token, (data) => {
|
continuationManager.on("deviceUnselected", token, (data) => {
|
||||||
console.info('[Demo]onDeviceDisconnect len: ' + data.length);
|
console.info('[Demo]onDeviceDisconnect len: ' + data.length);
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
console.info('[Demo]onDeviceDisconnect deviceId: ' + JSON.stringify(data[i]));
|
console.info('[Demo]onDeviceDisconnect deviceId: ' + JSON.stringify(data[i]));
|
||||||
@ -252,9 +222,9 @@ function onDeviceDisconnect() {
|
|||||||
console.info('[Demo]onDeviceDisconnect end');
|
console.info('[Demo]onDeviceDisconnect end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDeviceDisconnectWithInvalidToken() {
|
function onDeviceDisconnectWithInvalidToken(): void {
|
||||||
console.info('[Demo]onDeviceDisconnectWithInvalidToken begin');
|
console.info('[Demo]onDeviceDisconnectWithInvalidToken begin');
|
||||||
continuationManager.on("deviceDisconnect", INVALID_TOKEN, (data) => {
|
continuationManager.on("deviceUnselected", INVALID_TOKEN, (data) => {
|
||||||
console.info('[Demo]onDeviceDisconnectWithInvalidToken len: ' + data.length);
|
console.info('[Demo]onDeviceDisconnectWithInvalidToken len: ' + data.length);
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
console.info('[Demo]onDeviceDisconnectWithInvalidToken deviceId: ' + JSON.stringify(data[i]));
|
console.info('[Demo]onDeviceDisconnectWithInvalidToken deviceId: ' + JSON.stringify(data[i]));
|
||||||
@ -268,27 +238,27 @@ function onDeviceDisconnectWithInvalidToken() {
|
|||||||
console.info('[Demo]onDeviceDisconnectWithInvalidToken end');
|
console.info('[Demo]onDeviceDisconnectWithInvalidToken end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function startDeviceManager() {
|
function startContinuationDeviceManager(): void {
|
||||||
console.info('[Demo]startDeviceManager begin');
|
console.info('[Demo]startContinuationDeviceManager begin');
|
||||||
continuationManager.startDeviceManager(token)
|
continuationManager.startContinuationDeviceManager(token)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]startDeviceManager finished, ' + JSON.stringify(data));
|
console.info('[Demo]startContinuationDeviceManager finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
message: "[Demo]startDeviceManager data: " + JSON.stringify(data),
|
message: "[Demo]startContinuationDeviceManager data: " + JSON.stringify(data),
|
||||||
duration: SHOW_TOAST_TIME
|
duration: SHOW_TOAST_TIME
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('[Demo]startDeviceManager failed, cause: ' + JSON.stringify(err));
|
console.error('[Demo]startContinuationDeviceManager failed, cause: ' + JSON.stringify(err));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
message: "[Demo]startDeviceManager err: " + err,
|
message: "[Demo]startContinuationDeviceManager err: " + err,
|
||||||
duration: SHOW_TOAST_TIME
|
duration: SHOW_TOAST_TIME
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
console.info('[Demo]startDeviceManager end');
|
console.info('[Demo]startContinuationDeviceManager end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function startDeviceManagerWithExtraParam() {
|
function startDeviceManagerWithExtraParam(): void {
|
||||||
console.info('[Demo]startDeviceManagerWithExtraParam begin');
|
console.info('[Demo]startDeviceManagerWithExtraParam begin');
|
||||||
let continuationExtraParams = {
|
let continuationExtraParams = {
|
||||||
deviceType: [DEVICE_TYPE],
|
deviceType: [DEVICE_TYPE],
|
||||||
@ -298,7 +268,7 @@ function startDeviceManagerWithExtraParam() {
|
|||||||
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
||||||
authInfo: {"name": "authInfo", "length": 8}
|
authInfo: {"name": "authInfo", "length": 8}
|
||||||
};
|
};
|
||||||
continuationManager.startDeviceManager(token, continuationExtraParams)
|
continuationManager.startContinuationDeviceManager(token, continuationExtraParams)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]startDeviceManagerWithExtraParam finished, ' + JSON.stringify(data));
|
console.info('[Demo]startDeviceManagerWithExtraParam finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
@ -316,9 +286,9 @@ function startDeviceManagerWithExtraParam() {
|
|||||||
console.info('[Demo]startDeviceManagerWithExtraParam end');
|
console.info('[Demo]startDeviceManagerWithExtraParam end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function startDeviceManagerWithInvalidToken() {
|
function startDeviceManagerWithInvalidToken(): void {
|
||||||
console.info('[Demo]startDeviceManagerWithInvalidToken begin');
|
console.info('[Demo]startDeviceManagerWithInvalidToken begin');
|
||||||
continuationManager.startDeviceManager(INVALID_TOKEN)
|
continuationManager.startContinuationDeviceManager(INVALID_TOKEN)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]startDeviceManagerWithInvalidToken finished, ' + JSON.stringify(data));
|
console.info('[Demo]startDeviceManagerWithInvalidToken finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
@ -336,7 +306,7 @@ function startDeviceManagerWithInvalidToken() {
|
|||||||
console.info('[Demo]startDeviceManagerWithInvalidToken end');
|
console.info('[Demo]startDeviceManagerWithInvalidToken end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function startDeviceManagerWithInvalidFilter() {
|
function startDeviceManagerWithInvalidFilter(): void {
|
||||||
console.info('[Demo]startDeviceManagerWithInvalidFilter begin');
|
console.info('[Demo]startDeviceManagerWithInvalidFilter begin');
|
||||||
let continuationExtraParams = {
|
let continuationExtraParams = {
|
||||||
deviceType: [DEVICE_TYPE],
|
deviceType: [DEVICE_TYPE],
|
||||||
@ -346,7 +316,7 @@ function startDeviceManagerWithInvalidFilter() {
|
|||||||
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
||||||
authInfo: {"name": "authInfo", "length": 8}
|
authInfo: {"name": "authInfo", "length": 8}
|
||||||
};
|
};
|
||||||
continuationManager.startDeviceManager(token, continuationExtraParams)
|
continuationManager.startContinuationDeviceManager(token, continuationExtraParams)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]startDeviceManagerWithInvalidFilter finished, ' + JSON.stringify(data));
|
console.info('[Demo]startDeviceManagerWithInvalidFilter finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
@ -364,7 +334,7 @@ function startDeviceManagerWithInvalidFilter() {
|
|||||||
console.info('[Demo]startDeviceManagerWithInvalidFilter end');
|
console.info('[Demo]startDeviceManagerWithInvalidFilter end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function startDeviceManagerWithoutFilter() {
|
function startDeviceManagerWithoutFilter(): void {
|
||||||
console.info('[Demo]startDeviceManagerWithoutFilter begin');
|
console.info('[Demo]startDeviceManagerWithoutFilter begin');
|
||||||
let continuationExtraParams = {
|
let continuationExtraParams = {
|
||||||
deviceType: [DEVICE_TYPE],
|
deviceType: [DEVICE_TYPE],
|
||||||
@ -373,7 +343,7 @@ function startDeviceManagerWithoutFilter() {
|
|||||||
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
continuationMode: continuationManager.ContinuationMode.COLLABORATION_MULTIPLE,
|
||||||
authInfo: {"name": "authInfo", "length": 8}
|
authInfo: {"name": "authInfo", "length": 8}
|
||||||
};
|
};
|
||||||
continuationManager.startDeviceManager(token, continuationExtraParams)
|
continuationManager.startContinuationDeviceManager(token, continuationExtraParams)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]startDeviceManagerWithoutFilter finished, ' + JSON.stringify(data));
|
console.info('[Demo]startDeviceManagerWithoutFilter finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
@ -391,7 +361,7 @@ function startDeviceManagerWithoutFilter() {
|
|||||||
console.info('[Demo]startDeviceManagerWithoutFilter end');
|
console.info('[Demo]startDeviceManagerWithoutFilter end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function startDeviceManagerWithInvalidContinuationMode() {
|
function startDeviceManagerWithInvalidContinuationMode(): void {
|
||||||
console.info('[Demo]startDeviceManagerWithInvalidContinuationMode begin');
|
console.info('[Demo]startDeviceManagerWithInvalidContinuationMode begin');
|
||||||
let continuationExtraParams = {
|
let continuationExtraParams = {
|
||||||
deviceType: [DEVICE_TYPE],
|
deviceType: [DEVICE_TYPE],
|
||||||
@ -401,7 +371,7 @@ function startDeviceManagerWithInvalidContinuationMode() {
|
|||||||
continuationMode: INVALID_CONTINUATION_MODE,
|
continuationMode: INVALID_CONTINUATION_MODE,
|
||||||
authInfo: {"name": "authInfo", "length": 8}
|
authInfo: {"name": "authInfo", "length": 8}
|
||||||
};
|
};
|
||||||
continuationManager.startDeviceManager(token, continuationExtraParams)
|
continuationManager.startContinuationDeviceManager(token, continuationExtraParams)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]startDeviceManagerWithInvalidContinuationMode finished, ' + JSON.stringify(data));
|
console.info('[Demo]startDeviceManagerWithInvalidContinuationMode finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
@ -419,33 +389,33 @@ function startDeviceManagerWithInvalidContinuationMode() {
|
|||||||
console.info('[Demo]startDeviceManagerWithInvalidContinuationMode end');
|
console.info('[Demo]startDeviceManagerWithInvalidContinuationMode end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateConnectStatus() {
|
function updateContinuationState(): void {
|
||||||
console.info('[Demo]updateConnectStatus begin');
|
console.info('[Demo]updateContinuationState begin');
|
||||||
let deviceId: string = "test deviceId";
|
let deviceId: string = "test deviceId";
|
||||||
let deviceConnectStatus = continuationManager.DeviceConnectState.CONNECTED;
|
let deviceConnectStatus = continuationManager.DeviceConnectState.CONNECTED;
|
||||||
continuationManager.updateConnectStatus(token, deviceId, deviceConnectStatus)
|
continuationManager.updateContinuationState(token, deviceId, deviceConnectStatus)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]updateConnectStatus finished, ' + JSON.stringify(data));
|
console.info('[Demo]updateContinuationState finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
message: "[Demo]updateConnectStatus data: " + JSON.stringify(data),
|
message: "[Demo]updateContinuationState data: " + JSON.stringify(data),
|
||||||
duration: SHOW_TOAST_TIME
|
duration: SHOW_TOAST_TIME
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('[Demo]updateConnectStatus failed, cause: ' + JSON.stringify(err));
|
console.error('[Demo]updateContinuationState failed, cause: ' + JSON.stringify(err));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
message: "[Demo]updateConnectStatus err: " + err,
|
message: "[Demo]updateContinuationState err: " + err,
|
||||||
duration: SHOW_TOAST_TIME
|
duration: SHOW_TOAST_TIME
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
console.info('[Demo]updateConnectStatus end');
|
console.info('[Demo]updateContinuationState end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateConnectStatusWithInvalidToken() {
|
function updateConnectStatusWithInvalidToken(): void {
|
||||||
console.info('[Demo]updateConnectStatusWithInvalidToken begin');
|
console.info('[Demo]updateConnectStatusWithInvalidToken begin');
|
||||||
let deviceId: string = "test deviceId";
|
let deviceId: string = "test deviceId";
|
||||||
let deviceConnectStatus = continuationManager.DeviceConnectState.CONNECTED;
|
let deviceConnectStatus = continuationManager.DeviceConnectState.CONNECTED;
|
||||||
continuationManager.updateConnectStatus(INVALID_TOKEN, deviceId, deviceConnectStatus)
|
continuationManager.updateContinuationState(INVALID_TOKEN, deviceId, deviceConnectStatus)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]updateConnectStatusWithInvalidToken finished, ' + JSON.stringify(data));
|
console.info('[Demo]updateConnectStatusWithInvalidToken finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
@ -463,11 +433,11 @@ function updateConnectStatusWithInvalidToken() {
|
|||||||
console.info('[Demo]updateConnectStatusWithInvalidToken end');
|
console.info('[Demo]updateConnectStatusWithInvalidToken end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateConnectStatusWithInvalidDeviceId() {
|
function updateConnectStatusWithInvalidDeviceId(): void {
|
||||||
console.info('[Demo]updateConnectStatusWithInvalidDeviceId begin');
|
console.info('[Demo]updateConnectStatusWithInvalidDeviceId begin');
|
||||||
let deviceId: string = "";
|
let deviceId: string = "";
|
||||||
let deviceConnectStatus = continuationManager.DeviceConnectState.CONNECTED;
|
let deviceConnectStatus = continuationManager.DeviceConnectState.CONNECTED;
|
||||||
continuationManager.updateConnectStatus(token, deviceId, deviceConnectStatus)
|
continuationManager.updateContinuationState(token, deviceId, deviceConnectStatus)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]updateConnectStatusWithInvalidDeviceId finished, ' + JSON.stringify(data));
|
console.info('[Demo]updateConnectStatusWithInvalidDeviceId finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
@ -485,11 +455,11 @@ function updateConnectStatusWithInvalidDeviceId() {
|
|||||||
console.info('[Demo]updateConnectStatusWithInvalidDeviceId end');
|
console.info('[Demo]updateConnectStatusWithInvalidDeviceId end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateConnectStatusWithInvalidConnectStatus() {
|
function updateConnectStatusWithInvalidConnectStatus(): void {
|
||||||
console.info('[Demo]updateConnectStatusWithInvalidConnectStatus begin');
|
console.info('[Demo]updateConnectStatusWithInvalidConnectStatus begin');
|
||||||
let deviceId: string = "test deviceId";
|
let deviceId: string = "test deviceId";
|
||||||
let deviceConnectStatus = INVALID_CONNECT_STATUS;
|
let deviceConnectStatus = INVALID_CONNECT_STATUS;
|
||||||
continuationManager.updateConnectStatus(token, deviceId, deviceConnectStatus)
|
continuationManager.updateContinuationState(token, deviceId, deviceConnectStatus)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]updateConnectStatusWithInvalidConnectStatus finished, ' + JSON.stringify(data));
|
console.info('[Demo]updateConnectStatusWithInvalidConnectStatus finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
@ -507,53 +477,53 @@ function updateConnectStatusWithInvalidConnectStatus() {
|
|||||||
console.info('[Demo]updateConnectStatusWithInvalidConnectStatus end');
|
console.info('[Demo]updateConnectStatusWithInvalidConnectStatus end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function offDeviceConnect() {
|
function offDeviceConnect(): void {
|
||||||
console.info('[Demo]offDeviceConnect begin');
|
console.info('[Demo]offDeviceConnect begin');
|
||||||
continuationManager.off("deviceConnect", token);
|
continuationManager.off("deviceSelected", token);
|
||||||
console.info('[Demo]offDeviceConnect end');
|
console.info('[Demo]offDeviceConnect end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function offDeviceConnectWithInvalidToken() {
|
function offDeviceConnectWithInvalidToken(): void {
|
||||||
console.info('[Demo]offDeviceConnectWithInvalidToken begin');
|
console.info('[Demo]offDeviceConnectWithInvalidToken begin');
|
||||||
continuationManager.off("deviceConnect", INVALID_TOKEN);
|
continuationManager.off("deviceSelected", INVALID_TOKEN);
|
||||||
console.info('[Demo]offDeviceConnectWithInvalidToken end');
|
console.info('[Demo]offDeviceConnectWithInvalidToken end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function offDeviceDisconnect() {
|
function offDeviceDisconnect(): void {
|
||||||
console.info('[Demo]offDeviceDisconnect begin');
|
console.info('[Demo]offDeviceDisconnect begin');
|
||||||
continuationManager.off("deviceDisconnect", token);
|
continuationManager.off("deviceUnselected", token);
|
||||||
console.info('[Demo]offDeviceDisconnect end');
|
console.info('[Demo]offDeviceDisconnect end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function offDeviceDisconnectWithInvalidToken() {
|
function offDeviceDisconnectWithInvalidToken(): void {
|
||||||
console.info('[Demo]offDeviceDisconnectWithInvalidToken begin');
|
console.info('[Demo]offDeviceDisconnectWithInvalidToken begin');
|
||||||
continuationManager.off("deviceDisconnect", INVALID_TOKEN);
|
continuationManager.off("deviceUnselected", INVALID_TOKEN);
|
||||||
console.info('[Demo]offDeviceDisconnectWithInvalidToken end');
|
console.info('[Demo]offDeviceDisconnectWithInvalidToken end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function unregister() {
|
function unregisterContinuation(): void {
|
||||||
console.info('[Demo]unregister begin');
|
console.info('[Demo]unregisterContinuation begin');
|
||||||
continuationManager.unregister(token)
|
continuationManager.unregisterContinuation(token)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]unregister finished, ' + JSON.stringify(data));
|
console.info('[Demo]unregisterContinuation finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
message: "[Demo]unregister data: " + JSON.stringify(data),
|
message: "[Demo]unregisterContinuation data: " + JSON.stringify(data),
|
||||||
duration: SHOW_TOAST_TIME
|
duration: SHOW_TOAST_TIME
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('[Demo]unregister failed, cause: ' + JSON.stringify(err));
|
console.error('[Demo]unregisterContinuation failed, cause: ' + JSON.stringify(err));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
message: "[Demo]unregister err: " + err,
|
message: "[Demo]unregisterContinuation err: " + err,
|
||||||
duration: SHOW_TOAST_TIME
|
duration: SHOW_TOAST_TIME
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
console.info('[Demo]unregister end');
|
console.info('[Demo]unregisterContinuation end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function unregisterWithInvalidToken() {
|
function unregisterWithInvalidToken(): void {
|
||||||
console.info('[Demo]unregisterWithInvalidToken begin');
|
console.info('[Demo]unregisterWithInvalidToken begin');
|
||||||
continuationManager.unregister(INVALID_TOKEN)
|
continuationManager.unregisterContinuation(INVALID_TOKEN)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]unregisterWithInvalidToken finished, ' + JSON.stringify(data));
|
console.info('[Demo]unregisterWithInvalidToken finished, ' + JSON.stringify(data));
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
@ -571,15 +541,15 @@ function unregisterWithInvalidToken() {
|
|||||||
console.info('[Demo]unregisterWithInvalidToken end');
|
console.info('[Demo]unregisterWithInvalidToken end');
|
||||||
}
|
}
|
||||||
|
|
||||||
function startRemoteAbility() {
|
function startRemoteAbility(): void {
|
||||||
let token = -1;
|
let token = -1;
|
||||||
continuationManager.register()
|
continuationManager.registerContinuation()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]register finished, ' + JSON.stringify(data));
|
console.info('[Demo]registerContinuation finished, ' + JSON.stringify(data));
|
||||||
token = data;
|
token = data;
|
||||||
globalThis.token = data;
|
globalThis.token = data;
|
||||||
console.info('[Demo]startRemoteAbility register token = ' + globalThis.token);
|
console.info('[Demo]startRemoteAbility registerContinuation token = ' + globalThis.token);
|
||||||
continuationManager.on("deviceConnect", token, (data) => {
|
continuationManager.on("deviceSelected", token, (data) => {
|
||||||
console.info('[Demo]registerDeviceConnectCallback len: ' + data.length);
|
console.info('[Demo]registerDeviceConnectCallback len: ' + data.length);
|
||||||
if (data.length <= 0) {
|
if (data.length <= 0) {
|
||||||
console.info('[Demo]no selected device');
|
console.info('[Demo]no selected device');
|
||||||
@ -589,22 +559,22 @@ function startRemoteAbility() {
|
|||||||
startRemoteAbilityWithDeviceId(data[i].id);
|
startRemoteAbilityWithDeviceId(data[i].id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
continuationManager.startDeviceManager(token)
|
continuationManager.startContinuationDeviceManager(token)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]startDeviceManager finished, ' + JSON.stringify(data));
|
console.info('[Demo]startContinuationDeviceManager finished, ' + JSON.stringify(data));
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('[Demo]startDeviceManager failed, cause: ' + JSON.stringify(err));
|
console.error('[Demo]startContinuationDeviceManager failed, cause: ' + JSON.stringify(err));
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('[Demo]register failed, cause: ' + JSON.stringify(err));
|
console.error('[Demo]registerContinuation failed, cause: ' + JSON.stringify(err));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function startRemoteAbilityWithDeviceId(remoteDeviceId) {
|
function startRemoteAbilityWithDeviceId(remoteDeviceId): void {
|
||||||
console.info('[Demo]startRemoteAbilityWithDeviceId remoteDeviceId = ' + remoteDeviceId);
|
console.info('[Demo]startRemoteAbilityWithDeviceId remoteDeviceId = ' + remoteDeviceId);
|
||||||
let want = {
|
let want: Want = {
|
||||||
deviceId: remoteDeviceId,
|
deviceId: remoteDeviceId,
|
||||||
bundleName: 'ohos.samples.continuationmanager',
|
bundleName: 'ohos.samples.continuationmanager',
|
||||||
abilityName: 'MainAbility'
|
abilityName: 'MainAbility'
|
||||||
@ -614,15 +584,15 @@ function startRemoteAbilityWithDeviceId(remoteDeviceId) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function connectRemoteAbility() {
|
function connectRemoteAbility(): void {
|
||||||
let token = -1;
|
let token = -1;
|
||||||
continuationManager.register()
|
continuationManager.registerContinuation()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]register finished, ' + JSON.stringify(data));
|
console.info('[Demo]registerContinuation finished, ' + JSON.stringify(data));
|
||||||
token = data;
|
token = data;
|
||||||
globalThis.token = data;
|
globalThis.token = data;
|
||||||
console.info('[Demo]connectRemoteAbility register token = ' + globalThis.token);
|
console.info('[Demo]connectRemoteAbility registerContinuation token = ' + globalThis.token);
|
||||||
continuationManager.on("deviceConnect", token, (data) => {
|
continuationManager.on("deviceSelected", token, (data) => {
|
||||||
console.info('[Demo]registerDeviceConnectCallback len: ' + data.length);
|
console.info('[Demo]registerDeviceConnectCallback len: ' + data.length);
|
||||||
if (data.length <= 0) {
|
if (data.length <= 0) {
|
||||||
console.info('[Demo]no selected device');
|
console.info('[Demo]no selected device');
|
||||||
@ -632,20 +602,20 @@ function connectRemoteAbility() {
|
|||||||
connectRemoteAbilityWithDeviceId(data[i].id);
|
connectRemoteAbilityWithDeviceId(data[i].id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
continuationManager.startDeviceManager(token)
|
continuationManager.startContinuationDeviceManager(token)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]startDeviceManager finished, ' + JSON.stringify(data));
|
console.info('[Demo]startContinuationDeviceManager finished, ' + JSON.stringify(data));
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('[Demo]startDeviceManager failed, cause: ' + JSON.stringify(err));
|
console.error('[Demo]startContinuationDeviceManager failed, cause: ' + JSON.stringify(err));
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('[Demo]register failed, cause: ' + JSON.stringify(err));
|
console.error('[Demo]registerContinuation failed, cause: ' + JSON.stringify(err));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function connectRemoteAbilityWithDeviceId(remoteDeviceId) {
|
function connectRemoteAbilityWithDeviceId(remoteDeviceId): void {
|
||||||
console.info('[Demo]connectRemoteAbilityWithDeviceId remoteDeviceId = ' + remoteDeviceId);
|
console.info('[Demo]connectRemoteAbilityWithDeviceId remoteDeviceId = ' + remoteDeviceId);
|
||||||
async function onConnectCallback(element, remote) {
|
async function onConnectCallback(element, remote) {
|
||||||
console.log('[Demo]connectRemoteAbilityWithDeviceId onConnectDone element: ' + element);
|
console.log('[Demo]connectRemoteAbilityWithDeviceId onConnectDone element: ' + element);
|
||||||
@ -658,8 +628,8 @@ function connectRemoteAbilityWithDeviceId(remoteDeviceId) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let option = new rpc.MessageOption();
|
let option = new rpc.MessageOption();
|
||||||
let data = new rpc.MessageParcel();
|
let data = new rpc.MessageSequence();
|
||||||
let reply = new rpc.MessageParcel();
|
let reply = new rpc.MessageSequence();
|
||||||
data.writeInt(1);
|
data.writeInt(1);
|
||||||
data.writeInt(99);
|
data.writeInt(99);
|
||||||
await mRemote.sendRequest(1, data, reply, option);
|
await mRemote.sendRequest(1, data, reply, option);
|
||||||
@ -669,10 +639,10 @@ function connectRemoteAbilityWithDeviceId(remoteDeviceId) {
|
|||||||
duration: SHOW_TOAST_TIME
|
duration: SHOW_TOAST_TIME
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function onDisconnectCallback(element) {
|
function onDisconnectCallback(element): void {
|
||||||
console.log('[Demo]connectRemoteAbilityWithDeviceId onDisconnectDone element: ' + element);
|
console.log('[Demo]connectRemoteAbilityWithDeviceId onDisconnectDone element: ' + element);
|
||||||
}
|
}
|
||||||
function onFailedCallback(code) {
|
function onFailedCallback(code): void {
|
||||||
console.log('[Demo]connectRemoteAbilityWithDeviceId onFailed errCode: ' + code);
|
console.log('[Demo]connectRemoteAbilityWithDeviceId onFailed errCode: ' + code);
|
||||||
}
|
}
|
||||||
connectedAbility = globalThis.context.connectAbility(
|
connectedAbility = globalThis.context.connectAbility(
|
||||||
@ -690,6 +660,53 @@ function connectRemoteAbilityWithDeviceId(remoteDeviceId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class MainAbility extends Ability {
|
export default class MainAbility extends Ability {
|
||||||
|
//获取当前应用的权限的授予状态:grantStatus(授予返回:0,未授予:-1)
|
||||||
|
async getGrantStatus(permission: Permissions): Promise<abilityAccessCtrl.GrantStatus>{
|
||||||
|
let atManager = abilityAccessCtrl.createAtManager();
|
||||||
|
let grantStatus : abilityAccessCtrl.GrantStatus = -1;
|
||||||
|
|
||||||
|
//获取tokenId:
|
||||||
|
let tokenId :number = 0;
|
||||||
|
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){
|
||||||
|
console.info('Failed to get bundle info for self,cause ${public}s' ,JSON.stringify(err)??'');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检验应用是否被授予此权限,授予返回:PERMISSION_GRANTED = 0,未授予:PERMISSION_DENIED = -1
|
||||||
|
try {
|
||||||
|
grantStatus = await atManager.checkAccessToken(tokenId,permission);
|
||||||
|
}catch (err){
|
||||||
|
console.info('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.getGrantStatus(permissions[0]);
|
||||||
|
// 检验权限授予情况
|
||||||
|
if(grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED){
|
||||||
|
//已授予
|
||||||
|
console.info('Permission already granted.');
|
||||||
|
}else{
|
||||||
|
//未授予,向用户弹框动态申请授权
|
||||||
|
let atManager = abilityAccessCtrl.createAtManager();
|
||||||
|
try {
|
||||||
|
atManager.requestPermissionsFromUser(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC'], (err, data) => {
|
||||||
|
console.info('data: ' + JSON.stringify(data));
|
||||||
|
});
|
||||||
|
}catch (err){
|
||||||
|
console.info('catch err ,' + JSON.stringify(err)??'');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
onCreate(want, launchParam) {
|
onCreate(want, launchParam) {
|
||||||
console.log("[Demo] MainAbility onCreate")
|
console.log("[Demo] MainAbility onCreate")
|
||||||
globalThis.abilityWant = want;
|
globalThis.abilityWant = want;
|
||||||
@ -703,9 +720,9 @@ export default class MainAbility extends Ability {
|
|||||||
onWindowStageCreate(windowStage) {
|
onWindowStageCreate(windowStage) {
|
||||||
// Main window is created, set main page for this ability
|
// Main window is created, set main page for this ability
|
||||||
console.log("[Demo] MainAbility onWindowStageCreate")
|
console.log("[Demo] MainAbility onWindowStageCreate")
|
||||||
requestPermission();
|
this.checkPermissions();
|
||||||
|
|
||||||
globalThis.register = (()=>{ register(); })
|
globalThis.registerContinuation = (()=>{ registerContinuation(); })
|
||||||
globalThis.registerWithExtraParams = (()=>{ registerWithExtraParams(); })
|
globalThis.registerWithExtraParams = (()=>{ registerWithExtraParams(); })
|
||||||
globalThis.registerWithInvalidFilter = (()=>{ registerWithInvalidFilter(); })
|
globalThis.registerWithInvalidFilter = (()=>{ registerWithInvalidFilter(); })
|
||||||
globalThis.registerWithoutFilter = (()=>{ registerWithoutFilter(); })
|
globalThis.registerWithoutFilter = (()=>{ registerWithoutFilter(); })
|
||||||
@ -714,13 +731,13 @@ export default class MainAbility extends Ability {
|
|||||||
globalThis.onDeviceConnectWithInvalidToken = (()=>{ onDeviceConnectWithInvalidToken(); })
|
globalThis.onDeviceConnectWithInvalidToken = (()=>{ onDeviceConnectWithInvalidToken(); })
|
||||||
globalThis.onDeviceDisconnect = (()=>{ onDeviceDisconnect(); })
|
globalThis.onDeviceDisconnect = (()=>{ onDeviceDisconnect(); })
|
||||||
globalThis.onDeviceDisconnectWithInvalidToken = (()=>{ onDeviceDisconnectWithInvalidToken(); })
|
globalThis.onDeviceDisconnectWithInvalidToken = (()=>{ onDeviceDisconnectWithInvalidToken(); })
|
||||||
globalThis.startDeviceManager = (()=>{ startDeviceManager(); })
|
globalThis.startContinuationDeviceManager = (()=>{ startContinuationDeviceManager(); })
|
||||||
globalThis.startDeviceManagerWithExtraParam = (()=>{ startDeviceManagerWithExtraParam(); })
|
globalThis.startDeviceManagerWithExtraParam = (()=>{ startDeviceManagerWithExtraParam(); })
|
||||||
globalThis.startDeviceManagerWithInvalidToken = (()=>{ startDeviceManagerWithInvalidToken(); })
|
globalThis.startDeviceManagerWithInvalidToken = (()=>{ startDeviceManagerWithInvalidToken(); })
|
||||||
globalThis.startDeviceManagerWithInvalidFilter = (()=>{ startDeviceManagerWithInvalidFilter(); })
|
globalThis.startDeviceManagerWithInvalidFilter = (()=>{ startDeviceManagerWithInvalidFilter(); })
|
||||||
globalThis.startDeviceManagerWithoutFilter = (()=>{ startDeviceManagerWithoutFilter(); })
|
globalThis.startDeviceManagerWithoutFilter = (()=>{ startDeviceManagerWithoutFilter(); })
|
||||||
globalThis.startDeviceManagerWithInvalidContinuationMode = (()=>{ startDeviceManagerWithInvalidContinuationMode(); })
|
globalThis.startDeviceManagerWithInvalidContinuationMode = (()=>{ startDeviceManagerWithInvalidContinuationMode(); })
|
||||||
globalThis.updateConnectStatus = (()=>{ updateConnectStatus(); })
|
globalThis.updateContinuationState = (()=>{ updateContinuationState(); })
|
||||||
globalThis.updateConnectStatusWithInvalidToken = (()=>{ updateConnectStatusWithInvalidToken(); })
|
globalThis.updateConnectStatusWithInvalidToken = (()=>{ updateConnectStatusWithInvalidToken(); })
|
||||||
globalThis.updateConnectStatusWithInvalidDeviceId = (()=>{ updateConnectStatusWithInvalidDeviceId(); })
|
globalThis.updateConnectStatusWithInvalidDeviceId = (()=>{ updateConnectStatusWithInvalidDeviceId(); })
|
||||||
globalThis.updateConnectStatusWithInvalidConnectStatus = (()=>{ updateConnectStatusWithInvalidConnectStatus(); })
|
globalThis.updateConnectStatusWithInvalidConnectStatus = (()=>{ updateConnectStatusWithInvalidConnectStatus(); })
|
||||||
@ -728,7 +745,7 @@ export default class MainAbility extends Ability {
|
|||||||
globalThis.offDeviceConnectWithInvalidToken = (()=>{ offDeviceConnectWithInvalidToken(); })
|
globalThis.offDeviceConnectWithInvalidToken = (()=>{ offDeviceConnectWithInvalidToken(); })
|
||||||
globalThis.offDeviceDisconnect = (()=>{ offDeviceDisconnect(); })
|
globalThis.offDeviceDisconnect = (()=>{ offDeviceDisconnect(); })
|
||||||
globalThis.offDeviceDisconnectWithInvalidToken = (()=>{ offDeviceDisconnectWithInvalidToken(); })
|
globalThis.offDeviceDisconnectWithInvalidToken = (()=>{ offDeviceDisconnectWithInvalidToken(); })
|
||||||
globalThis.unregister = (()=>{ unregister(); })
|
globalThis.unregisterContinuation = (()=>{ unregisterContinuation(); })
|
||||||
globalThis.unregisterWithInvalidToken = (()=>{ unregisterWithInvalidToken(); })
|
globalThis.unregisterWithInvalidToken = (()=>{ unregisterWithInvalidToken(); })
|
||||||
globalThis.startRemoteAbility = (()=>{ startRemoteAbility(); })
|
globalThis.startRemoteAbility = (()=>{ startRemoteAbility(); })
|
||||||
globalThis.connectRemoteAbility = (()=>{ connectRemoteAbility(); })
|
globalThis.connectRemoteAbility = (()=>{ connectRemoteAbility(); })
|
||||||
@ -749,13 +766,13 @@ export default class MainAbility extends Ability {
|
|||||||
onBackground() {
|
onBackground() {
|
||||||
// Ability has back to background
|
// Ability has back to background
|
||||||
console.log("[Demo] MainAbility onBackground")
|
console.log("[Demo] MainAbility onBackground")
|
||||||
console.info('[Demo]onBackground unregister, token = ' + globalThis.token);
|
console.info('[Demo]onBackground unregisterContinuation, token = ' + globalThis.token);
|
||||||
continuationManager.unregister(globalThis.token)
|
continuationManager.unregisterContinuation(globalThis.token)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.info('[Demo]unregister finished, ' + JSON.stringify(data));
|
console.info('[Demo]unregisterContinuation finished, ' + JSON.stringify(data));
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('[Demo]unregister failed, cause: ' + JSON.stringify(err));
|
console.error('[Demo]unregisterContinuation failed, cause: ' + JSON.stringify(err));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
import Extension from '@ohos.app.ability.ServiceExtensionAbility'
|
import Extension from '@ohos.app.ability.ServiceExtensionAbility'
|
||||||
import rpc from '@ohos.rpc'
|
import rpc from '@ohos.rpc'
|
||||||
|
|
||||||
|
const START_DEVICE_MANAGER = 505;
|
||||||
class StubTest extends rpc.RemoteObject {
|
class StubTest extends rpc.RemoteObject {
|
||||||
constructor(des) {
|
constructor(des) {
|
||||||
super(des);
|
super(des);
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
export const GlobalThis = globalThis;
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -14,13 +14,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import prompt from '@system.prompt';
|
import prompt from '@system.prompt';
|
||||||
|
import { GlobalThis } from './GlobalThis';
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct Index {
|
struct Index {
|
||||||
private scroller: Scroller = new Scroller();
|
scroller: Scroller = new Scroller();
|
||||||
|
|
||||||
private aboutToAppear() {
|
aboutToAppear() {
|
||||||
prompt.showToast({
|
prompt.showToast({
|
||||||
message: "MainAbility aboutToAppear"
|
message: "MainAbility aboutToAppear"
|
||||||
});
|
});
|
||||||
@ -46,7 +47,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.register();
|
GlobalThis.register();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -62,7 +63,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.registerWithExtraParams();
|
GlobalThis.registerWithExtraParams();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -78,7 +79,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.registerWithInvalidFilter();
|
GlobalThis.registerWithInvalidFilter();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -94,7 +95,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.registerWithoutFilter();
|
GlobalThis.registerWithoutFilter();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -110,7 +111,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.registerWithInvalidContinuationMode();
|
GlobalThis.registerWithInvalidContinuationMode();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -126,7 +127,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.onDeviceConnect();
|
GlobalThis.onDeviceConnect();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -142,7 +143,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.onDeviceConnectWithInvalidToken();
|
GlobalThis.onDeviceConnectWithInvalidToken();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -158,7 +159,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.onDeviceDisconnect();
|
GlobalThis.onDeviceDisconnect();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -174,7 +175,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.onDeviceDisconnectWithInvalidToken();
|
GlobalThis.onDeviceDisconnectWithInvalidToken();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -190,7 +191,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.startDeviceManager();
|
GlobalThis.startDeviceManager();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -206,7 +207,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.startDeviceManagerWithExtraParam();
|
GlobalThis.startDeviceManagerWithExtraParam();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -222,7 +223,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.startDeviceManagerWithInvalidToken();
|
GlobalThis.startDeviceManagerWithInvalidToken();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -238,7 +239,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.startDeviceManagerWithInvalidFilter();
|
GlobalThis.startDeviceManagerWithInvalidFilter();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -254,7 +255,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.startDeviceManagerWithoutFilter();
|
GlobalThis.startDeviceManagerWithoutFilter();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -270,7 +271,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.startDeviceManagerWithInvalidContinuationMode();
|
GlobalThis.startDeviceManagerWithInvalidContinuationMode();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -286,7 +287,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.updateConnectStatus();
|
GlobalThis.updateConnectStatus();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -302,7 +303,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.updateConnectStatusWithInvalidToken();
|
GlobalThis.updateConnectStatusWithInvalidToken();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -318,7 +319,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.updateConnectStatusWithInvalidDeviceId();
|
GlobalThis.updateConnectStatusWithInvalidDeviceId();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -334,7 +335,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.updateConnectStatusWithInvalidConnectStatus();
|
GlobalThis.updateConnectStatusWithInvalidConnectStatus();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -350,7 +351,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.offDeviceConnect();
|
GlobalThis.offDeviceConnect();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -366,7 +367,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.offDeviceConnectWithInvalidToken();
|
GlobalThis.offDeviceConnectWithInvalidToken();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -382,7 +383,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.offDeviceDisconnect();
|
GlobalThis.offDeviceDisconnect();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -398,7 +399,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.offDeviceDisconnectWithInvalidToken();
|
GlobalThis.offDeviceDisconnectWithInvalidToken();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -414,7 +415,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.unregister();
|
GlobalThis.unregister();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -430,7 +431,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.unregisterWithInvalidToken();
|
GlobalThis.unregisterWithInvalidToken();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -446,7 +447,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.startRemoteAbility();
|
GlobalThis.startRemoteAbility();
|
||||||
})
|
})
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
@ -462,7 +463,7 @@ struct Index {
|
|||||||
.width(350)
|
.width(350)
|
||||||
.height(30)
|
.height(30)
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
globalThis.connectRemoteAbility();
|
GlobalThis.connectRemoteAbility();
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -17,7 +17,7 @@
|
|||||||
"module": {
|
"module": {
|
||||||
"name": "entry",
|
"name": "entry",
|
||||||
"type": "entry",
|
"type": "entry",
|
||||||
"srcEntrance": "./ets/Application/AbilityStage.ts",
|
"srcEntry": "./ets/Application/AbilityStage.ts",
|
||||||
"description": "$string:entry_desc",
|
"description": "$string:entry_desc",
|
||||||
"mainElement": "MainAbility",
|
"mainElement": "MainAbility",
|
||||||
"deviceTypes": [
|
"deviceTypes": [
|
||||||
@ -28,15 +28,16 @@
|
|||||||
"deliveryWithInstall": true,
|
"deliveryWithInstall": true,
|
||||||
"installationFree": false,
|
"installationFree": false,
|
||||||
"pages": "$profile:main_pages",
|
"pages": "$profile:main_pages",
|
||||||
"uiSyntax": "ets",
|
|
||||||
"abilities": [
|
"abilities": [
|
||||||
{
|
{
|
||||||
"name": "MainAbility",
|
"name": "MainAbility",
|
||||||
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
|
"srcEntry": "./ets/MainAbility/MainAbility.ts",
|
||||||
"description": "$string:MainAbility_desc",
|
"description": "$string:MainAbility_desc",
|
||||||
"icon": "$media:icon",
|
"icon": "$media:icon",
|
||||||
"label": "$string:MainAbility_label",
|
"label": "$string:MainAbility_label",
|
||||||
"visible": true,
|
"startWindowIcon": "$media:icon",
|
||||||
|
"startWindowBackground": "$color:start_window_background",
|
||||||
|
"exported": true,
|
||||||
"launchType": "standard",
|
"launchType": "standard",
|
||||||
"skills": [
|
"skills": [
|
||||||
{
|
{
|
||||||
@ -56,8 +57,8 @@
|
|||||||
"icon": "$media:icon",
|
"icon": "$media:icon",
|
||||||
"description": "service",
|
"description": "service",
|
||||||
"type": "service",
|
"type": "service",
|
||||||
"visible": true,
|
"exported": true,
|
||||||
"srcEntrance": "./ets/ServiceExtAbility/ServiceExtAbility.ts"
|
"srcEntry": "./ets/ServiceExtAbility/ServiceExtAbility.ts"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"requestPermissions": [
|
"requestPermissions": [
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"color": [
|
||||||
|
{
|
||||||
|
"name": "start_window_background",
|
||||||
|
"value": "#FFFFFF"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -13,12 +13,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Ability from '@ohos.app.ability.UIAbility'
|
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||||
import AbilityConstant from '@ohos.app.ability.AbilityConstant'
|
import AbilityConstant from '@ohos.app.ability.AbilityConstant'
|
||||||
import accessControl from "@ohos.abilityAccessCtrl";
|
import accessControl, { Permissions } from "@ohos.abilityAccessCtrl";
|
||||||
import bundle from '@ohos.bundle';
|
import bundle from '@ohos.bundle';
|
||||||
import distributedObject from '@ohos.data.distributedDataObject';
|
import distributedObject from '@ohos.data.distributedDataObject';
|
||||||
import Logger from './Logger';
|
import Logger from './Logger';
|
||||||
|
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
|
||||||
|
import bundleManager from '@ohos.bundle.bundleManager';
|
||||||
|
import window from '@ohos.window';
|
||||||
|
|
||||||
const BUNDLE_NAME = "com.ohos.continuationManualTestSuite.hmservice"
|
const BUNDLE_NAME = "com.ohos.continuationManualTestSuite.hmservice"
|
||||||
const PERMISSION_REJECT = -1
|
const PERMISSION_REJECT = -1
|
||||||
@ -26,62 +29,69 @@ const PERMISSION_REJECT = -1
|
|||||||
class ContentStorage {
|
class ContentStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
const g_object = distributedObject.createDistributedObject({name: undefined});
|
|
||||||
|
|
||||||
export default class MainAbility extends Ability {
|
export default class MainAbility extends UIAbility {
|
||||||
|
|
||||||
contentStorage : ContentStorage
|
contentStorage : LocalStorage
|
||||||
sessionId : string
|
sessionId : string
|
||||||
|
g_object: distributedObject.DataObject|null = null;
|
||||||
|
|
||||||
handleParam(want, launchParam) {
|
async handleParam(want) {
|
||||||
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
|
this.g_object = distributedObject.create(this.context, {data:undefined});
|
||||||
this.sessionId = want.parameters.session
|
if (this.g_object) {
|
||||||
Logger.info(`continuation sessionId: ${this.sessionId}`)
|
this.g_object = undefined;
|
||||||
|
|
||||||
g_object.name = undefined;
|
|
||||||
Logger.info(`set g_object.name undefined`)
|
|
||||||
|
|
||||||
g_object.setSessionId(this.sessionId); // set session id, so it will sync data from remote device
|
|
||||||
Logger.info(`g_object_name = ${g_object.name}`);
|
|
||||||
|
|
||||||
AppStorage.SetOrCreate<string>('ContinueStudy', g_object.name)
|
|
||||||
let workInput = want.parameters.work // get user data from want params
|
|
||||||
Logger.info(`work input ${workInput}`)
|
|
||||||
AppStorage.SetOrCreate<string>('ContinueWork', workInput)
|
|
||||||
this.contentStorage = new ContentStorage();
|
|
||||||
Logger.info('ready to restore');
|
|
||||||
this.context.restoreWindowStage(this.contentStorage);
|
|
||||||
}
|
}
|
||||||
|
if (!this.g_object) {
|
||||||
|
this.g_object = distributedObject.create(this.context, {name: undefined});
|
||||||
|
}
|
||||||
|
this.sessionId = want.parameters.session
|
||||||
|
Logger.info(`continuation sessionId: ${this.sessionId}`)
|
||||||
|
|
||||||
|
|
||||||
|
await this.g_object.setSessionId(this.sessionId); // set session id, so it will sync data from remote device
|
||||||
|
Logger.info(`this.g_object_name = ${this.g_object['name']}`);
|
||||||
|
|
||||||
|
AppStorage.setOrCreate<string>('ContinueStudy', this.g_object['name'])
|
||||||
|
let workInput = want.parameters.work // get user data from want params
|
||||||
|
Logger.info(`work input ${workInput}`)
|
||||||
|
AppStorage.setOrCreate<string>('ContinueWork', workInput)
|
||||||
|
this.contentStorage = new LocalStorage();
|
||||||
|
Logger.info('ready to restore');
|
||||||
|
this.context.restoreWindowStage(this.contentStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
onCreate(want, launchParam) {
|
onCreate(want, launchParam: AbilityConstant.LaunchParam) {
|
||||||
Logger.info("[Demo] MainAbility onCreate")
|
Logger.info("[Demo] MainAbility onCreate")
|
||||||
globalThis.abilityWant = want;
|
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
|
||||||
this.handleParam(want, launchParam)
|
this.handleParam(want);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onContinue(wantParam : {[key: string]: any}) {
|
onContinue(wantParam : {[key: string]: any}) {
|
||||||
Logger.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`)
|
Logger.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`)
|
||||||
let workInput = AppStorage.Get<string>('ContinueWork');
|
let workInput = AppStorage.get<string>('ContinueWork');
|
||||||
Logger.info(`onContinue work input = ${workInput}`);
|
Logger.info(`onContinue work input = ${workInput}`);
|
||||||
|
if (this.g_object) {
|
||||||
if (g_object.__sessionId === undefined) {
|
this.g_object = undefined;
|
||||||
this.sessionId = distributedObject.genSessionId()
|
|
||||||
Logger.info(`onContinue generate new sessionId`)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.sessionId = g_object.__sessionId;
|
|
||||||
}
|
}
|
||||||
|
this.g_object = distributedObject.create(this.context, {name: undefined});
|
||||||
|
|
||||||
wantParam["session"] = this.sessionId
|
this.sessionId = distributedObject.genSessionId();
|
||||||
g_object.name = AppStorage.Get<string>('ContinueStudy');
|
wantParam['session'] = this.sessionId;
|
||||||
Logger.info(`onContinue sessionId = ${this.sessionId}, name = ${g_object.name}`)
|
if (this.g_object != null) {
|
||||||
g_object.setSessionId(this.sessionId);
|
// 分布式对象设置 sessionId
|
||||||
g_object.save(wantParam.targetDevice, (result, data)=>{
|
this.g_object.setSessionId(this.sessionId, () => {
|
||||||
Logger.info("save callback");
|
Logger.info("join session");
|
||||||
Logger.info("save sessionId " + data.sessionId);
|
})
|
||||||
Logger.info("save version " + data.version);
|
}
|
||||||
Logger.info("save deviceId " + data.deviceId);
|
this.g_object['name'] = AppStorage.get<string>('ContinueStudy');
|
||||||
|
Logger.info(`onContinue sessionId = ${this.sessionId}, name = ${this.g_object['name']}`)
|
||||||
|
this.g_object.save(wantParam.targetDevice, (err, result)=>{
|
||||||
|
if (err) {
|
||||||
|
Logger.info(" save callback err: ", JSON.stringify(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Logger.info('save callback,result = ', JSON.stringify(result));
|
||||||
});
|
});
|
||||||
wantParam["work"] = workInput // set user input data into want params
|
wantParam["work"] = workInput // set user input data into want params
|
||||||
return 0;
|
return 0;
|
||||||
@ -89,41 +99,56 @@ export default class MainAbility extends Ability {
|
|||||||
|
|
||||||
onNewWant(want, launchParam) {
|
onNewWant(want, launchParam) {
|
||||||
Logger.info("MainAbility onNewWant")
|
Logger.info("MainAbility onNewWant")
|
||||||
this.handleParam(want, launchParam)
|
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
|
||||||
|
this.handleParam(want);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
requestPermissions = async () => {
|
//获取当前应用的权限的授予状态:grantStatus(授予返回:0,未授予:-1)
|
||||||
let permissions: Array<string> = [
|
async getGrantStatus(permission: Permissions): Promise<abilityAccessCtrl.GrantStatus>{
|
||||||
"ohos.permission.DISTRIBUTED_DATASYNC"
|
let atManager = abilityAccessCtrl.createAtManager();
|
||||||
];
|
let grantStatus : abilityAccessCtrl.GrantStatus = -1;
|
||||||
let needGrantPermission = false
|
|
||||||
let accessManger = accessControl.createAtManager()
|
//获取tokenId:
|
||||||
Logger.info("app permission get bundle info")
|
let tokenId :number = 0;
|
||||||
let bundleInfo = await bundle.getApplicationInfo(BUNDLE_NAME, 0, 100)
|
try {
|
||||||
Logger.info(`app permission query permission ${bundleInfo.accessTokenId.toString()}`)
|
let bundleInfo: bundleManager.BundleInfo = await bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION);
|
||||||
for (const permission of permissions) {
|
let appInfo: bundleManager.ApplicationInfo = bundleInfo.appInfo;
|
||||||
Logger.info(`app permission query grant status ${permission}`)
|
tokenId = appInfo.accessTokenId;
|
||||||
try {
|
}catch (err){
|
||||||
let grantStatus = await accessManger.verifyAccessToken(bundleInfo.accessTokenId, permission)
|
Logger.info('Failed to get bundle info for self,cause ${public}s' ,JSON.stringify(err)??'');
|
||||||
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")
|
// 检验应用是否被授予此权限,授予返回:PERMISSION_GRANTED = 0,未授予:PERMISSION_DENIED = -1
|
||||||
|
try {
|
||||||
|
grantStatus = await atManager.checkAccessToken(tokenId,permission);
|
||||||
|
}catch (err){
|
||||||
|
Logger.info('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.getGrantStatus(permissions[0]);
|
||||||
|
// 检验权限授予情况
|
||||||
|
if(grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED){
|
||||||
|
//已授予
|
||||||
|
Logger.info('Permission already granted.');
|
||||||
|
}else{
|
||||||
|
//未授予,向用户弹框动态申请授权
|
||||||
|
let atManager = abilityAccessCtrl.createAtManager();
|
||||||
try {
|
try {
|
||||||
await this.context.requestPermissionsFromUser(permissions)
|
atManager.requestPermissionsFromUser(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC'], (err, data) => {
|
||||||
} catch (err) {
|
Logger.info('data: ' + JSON.stringify(data));
|
||||||
Logger.error(`app permission ${JSON.stringify(err)}`)
|
});
|
||||||
|
}catch (err){
|
||||||
|
Logger.info('catch err ,' + JSON.stringify(err)??'');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Logger.info("app permission already granted")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,16 +156,22 @@ export default class MainAbility extends Ability {
|
|||||||
Logger.info("MainAbility onDestroy")
|
Logger.info("MainAbility onDestroy")
|
||||||
}
|
}
|
||||||
|
|
||||||
onWindowStageCreate(windowStage) {
|
onWindowStageCreate(windowStage: window.WindowStage) {
|
||||||
// Main window is created, set main page for this ability
|
// Main window is created, set main page for this ability
|
||||||
Logger.info("MainAbility onWindowStageCreate")
|
Logger.info("MainAbility onWindowStageCreate");
|
||||||
this.requestPermissions()
|
this.checkPermissions()
|
||||||
windowStage.setUIContent(this.context, "pages/index", null)
|
windowStage.loadContent('pages/Index', (err, data) => {
|
||||||
|
if (err.code) {
|
||||||
|
Logger.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Logger.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onWindowStageRestore(windowStage) {
|
onWindowStageRestore(windowStage: window.WindowStage) {
|
||||||
Logger.info("MainAbility onWindowStageRestore")
|
Logger.info("MainAbility onWindowStageRestore");
|
||||||
this.requestPermissions()
|
this.checkPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
onWindowStageDestroy() {
|
onWindowStageDestroy() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -13,19 +13,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import router from '@system.router';
|
import router from '@ohos.router';
|
||||||
import pageName from '../MainAbility/stringConst';
|
import pageName from '../MainAbility/stringConst';
|
||||||
import Logger from '../MainAbility/Logger';
|
import Logger from '../MainAbility/Logger';
|
||||||
|
|
||||||
async function routePage(pageIndex) {
|
async function routePage(pageIndex: string) : Promise<void> {
|
||||||
Logger.info("routePage");
|
Logger.info("routePage");
|
||||||
let options = {
|
|
||||||
uri: pageIndex
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
await router.push(options)
|
await router.pushUrl({ url: pageIndex });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Logger.error(`fail callback, code: ${err.code}, msg: ${err.msg}`)
|
Logger.error(`fail callback err ${JSON.stringify(err)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import router from '@system.router';
|
import router from '@ohos.router';
|
||||||
import pageName from '../MainAbility/stringConst';
|
import pageName from '../MainAbility/stringConst';
|
||||||
import Logger from '../MainAbility/Logger';
|
import Logger from '../MainAbility/Logger';
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ struct Study {
|
|||||||
.onChange((value) => {
|
.onChange((value) => {
|
||||||
Logger.info(`TextInput onChange: ${value}`);
|
Logger.info(`TextInput onChange: ${value}`);
|
||||||
this.inputTxt2 = value;
|
this.inputTxt2 = value;
|
||||||
AppStorage.Set('ContinueStudy', value);
|
AppStorage.set('ContinueStudy', value);
|
||||||
})
|
})
|
||||||
.width('50%')
|
.width('50%')
|
||||||
.height(50)
|
.height(50)
|
||||||
@ -50,7 +50,7 @@ struct Study {
|
|||||||
})
|
})
|
||||||
.backgroundColor('#0D9FFB')
|
.backgroundColor('#0D9FFB')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
router.back()
|
router.back();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import router from '@system.router';
|
import router from '@ohos.router';
|
||||||
import pageName from '../MainAbility/stringConst';
|
import pageName from '../MainAbility/stringConst';
|
||||||
import Logger from '../MainAbility/Logger';
|
import Logger from '../MainAbility/Logger';
|
||||||
|
|
||||||
@ -23,9 +23,7 @@ struct Work {
|
|||||||
private content: string = pageName.page1;
|
private content: string = pageName.page1;
|
||||||
@StorageLink('ContinueWork') inputTxt: string = '';
|
@StorageLink('ContinueWork') inputTxt: string = '';
|
||||||
|
|
||||||
controller: CustomDialogController
|
controller: CustomDialogController|null = null;
|
||||||
cancel: () => void
|
|
||||||
confirm: () => void
|
|
||||||
build() {
|
build() {
|
||||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||||
Text(`${this.content}`)
|
Text(`${this.content}`)
|
||||||
@ -37,7 +35,7 @@ struct Work {
|
|||||||
.onChange((value) => {
|
.onChange((value) => {
|
||||||
Logger.info(`TextInput onChange: ${value}`);
|
Logger.info(`TextInput onChange: ${value}`);
|
||||||
this.inputTxt = value;
|
this.inputTxt = value;
|
||||||
AppStorage.Set('ContinueWork', value);
|
AppStorage.set('ContinueWork', value);
|
||||||
})
|
})
|
||||||
.width('50%')
|
.width('50%')
|
||||||
.height(50)
|
.height(50)
|
||||||
@ -53,7 +51,7 @@ struct Work {
|
|||||||
})
|
})
|
||||||
.backgroundColor('#0D9FFB')
|
.backgroundColor('#0D9FFB')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
router.back()
|
router.back();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
"module": {
|
"module": {
|
||||||
"name": "entry",
|
"name": "entry",
|
||||||
"type": "entry",
|
"type": "entry",
|
||||||
"srcEntrance": "./ets/Application/AbilityStage.ts",
|
"srcEntry": "./ets/Application/AbilityStage.ts",
|
||||||
"description": "$string:entry_desc",
|
"description": "$string:entry_desc",
|
||||||
"mainElement": "MainAbility",
|
"mainElement": "MainAbility",
|
||||||
"deviceTypes": [
|
"deviceTypes": [
|
||||||
@ -26,18 +26,18 @@
|
|||||||
"2in1"
|
"2in1"
|
||||||
],
|
],
|
||||||
"deliveryWithInstall": true,
|
"deliveryWithInstall": true,
|
||||||
"installationFree": true,
|
|
||||||
"pages": "$profile:main_pages",
|
"pages": "$profile:main_pages",
|
||||||
"uiSyntax": "ets",
|
|
||||||
"abilities": [
|
"abilities": [
|
||||||
{
|
{
|
||||||
"name": "MainAbility",
|
"name": "MainAbility",
|
||||||
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
|
"srcEntry": "./ets/MainAbility/MainAbility.ts",
|
||||||
"description": "$string:MainAbility_desc",
|
"description": "$string:MainAbility_desc",
|
||||||
"icon": "$media:icon",
|
"icon": "$media:icon",
|
||||||
"label": "$string:MainAbility_label",
|
"label": "$string:MainAbility_label",
|
||||||
"visible": true,
|
"exported": true,
|
||||||
"continuable": true,
|
"continuable": true,
|
||||||
|
"startWindowIcon": "$media:icon",
|
||||||
|
"startWindowBackground": "$color:start_window_background",
|
||||||
"launchType": "singleton",
|
"launchType": "singleton",
|
||||||
"skills": [
|
"skills": [
|
||||||
{
|
{
|
||||||
@ -54,7 +54,7 @@
|
|||||||
"requestPermissions": [
|
"requestPermissions": [
|
||||||
{
|
{
|
||||||
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
|
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"color": [
|
||||||
|
{
|
||||||
|
"name": "start_window_background",
|
||||||
|
"value": "#FFFFFF"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user