mirror of
https://gitee.com/openharmony/xts_dcts
synced 2024-11-30 03:10:49 +00:00
rdb_store 配置长时任务
Signed-off-by: yuxiaoya2 <yuxiaoya@huawei.com> Change-Id: I231363837cf2cc547430ae966d2ad73835933eca
This commit is contained in:
parent
1aa7729596
commit
71cac6608d
@ -14,25 +14,71 @@
|
||||
*/
|
||||
|
||||
import Stub from '../../../../../../../../../testtools/disjsTest/server/service.js'
|
||||
import backgroundTaskManager from '@ohos.backgroundTaskManager';
|
||||
import wantAgent from '@ohos.wantAgent';
|
||||
import featureAbility from '@ohos.ability.featureAbility';
|
||||
|
||||
|
||||
function startContinuousTask() {
|
||||
let wantAgentInfo = {
|
||||
wants: [
|
||||
{
|
||||
bundleName: "com.ohos.distributerdbdisjs",
|
||||
abilityName: "com.ohos.distributerdbdisjs.ServiceAbility"
|
||||
}
|
||||
],
|
||||
operationType: wantAgent.OperationType.START_SERVICE,
|
||||
requestCode: 0,
|
||||
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
|
||||
};
|
||||
|
||||
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
|
||||
try{
|
||||
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
|
||||
backgroundTaskManager.BackgroundMode.MULTI_DEVICE_CONNECTION, wantAgentObj).then(() => {
|
||||
console.info("Operation startBackgroundRunning succeeded");
|
||||
}).catch((err) => {
|
||||
console.error("Operation startBackgroundRunning failed Cause: " + err);
|
||||
});
|
||||
}catch(error){
|
||||
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function stopContinuousTask() {
|
||||
try{
|
||||
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => {
|
||||
console.info("Operation stopBackgroundRunning succeeded");
|
||||
}).catch((err) => {
|
||||
console.error("Operation stopBackgroundRunning failed Cause: " + err);
|
||||
});
|
||||
}catch(error){
|
||||
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
|
||||
}
|
||||
}
|
||||
export default {
|
||||
onStart() {
|
||||
console.log('RpcServer: onStart')
|
||||
console.log('RDBServer: onStart')
|
||||
startContinuousTask();
|
||||
console.info('RDBServer: startContinuousTask');
|
||||
},
|
||||
onStop() {
|
||||
console.log('RpcServer: onStop')
|
||||
console.log('RDBServer: onStop')
|
||||
stopContinuousTask();
|
||||
console.info('RDBServer: stopContinuousTask');
|
||||
},
|
||||
onCommand(want, startId) {
|
||||
console.log('RpcServer: onCommand, want: ' + JSON.stringify(want) + ', startId: ' + startId)
|
||||
console.log('RDBServer: onCommand, want: ' + JSON.stringify(want) + ', startId: ' + startId)
|
||||
},
|
||||
onConnect(want) {
|
||||
console.log('RpcServer: service onConnect called.')
|
||||
console.log('RDBServer: service onConnect called.')
|
||||
return new Stub("disjsAbility")
|
||||
},
|
||||
onDisconnect(want) {
|
||||
console.log('RpcServer: service onDisConnect called.')
|
||||
console.log('RDBServer: service onDisConnect called.')
|
||||
},
|
||||
onReconnect(want) {
|
||||
console.log('RpcServer: service onReConnect called.')
|
||||
console.log('RDBServer: service onReConnect called.')
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user