未验证 提交 fcadd824 编写于 作者: O openharmony_ci 提交者: Gitee

!4063 add lifecycle xts

Merge pull request !4063 from dy/monthly_20220614
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -40,6 +40,12 @@ export default class Hap2MainAbility8 extends Ability {
// Ability has brought to foreground
console.log("[Demo] Hap2MainAbility8 onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] Hap2MainAbility8 onBackground")
setTimeout(() => {
this.context.terminateSelf().then((data) => {
console.log("Hap2MainAbility8 EventTest terminateSelf data: " + JSON.stringify(data));
......@@ -48,9 +54,4 @@ export default class Hap2MainAbility8 extends Ability {
})
}, 500)
}
onBackground() {
// Ability has back to background
console.log("[Demo] Hap2MainAbility8 onBackground")
}
};
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -15,7 +15,6 @@
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -24,62 +24,65 @@ export default class MainAbility1 extends Ability {
let AbilityLifecycleCallback = {
onAbilityCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityCreate")
listKey.push(abilityName +" onAbilityCreate");
console.log(abilityName + " onAbilityCreate")
listKey.push(abilityName + " onAbilityCreate");
console.log("listKey is :" + listKey);
},
onAbilityWindowStageCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityWindowStageCreate")
listKey.push(abilityName +" onAbilityWindowStageCreate");
console.log(abilityName + " onAbilityWindowStageCreate")
listKey.push(abilityName + " onAbilityWindowStageCreate");
console.log("listKey is :" + listKey);
},
onAbilityForeground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityForeground")
listKey.push(abilityName +" onAbilityForeground");
console.log(abilityName + " onAbilityForeground")
listKey.push(abilityName + " onAbilityForeground");
console.log("listKey is :" + listKey);
},
onAbilityBackground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityBackground")
listKey.push(abilityName +" onAbilityBackground");
console.log(abilityName + " onAbilityBackground")
listKey.push(abilityName + " onAbilityBackground");
console.log("listKey is :" + listKey);
},
onAbilityWindowStageDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityWindowStageDestroy")
listKey.push(abilityName +" onAbilityWindowStageDestroy");
console.log(abilityName + " onAbilityWindowStageDestroy")
listKey.push(abilityName + " onAbilityWindowStageDestroy");
console.log("listKey is :" + listKey);
},
onAbilityDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityDestroy")
listKey.push(abilityName +" onAbilityDestroy");
console.log(abilityName + " onAbilityDestroy")
listKey.push(abilityName + " onAbilityDestroy");
console.log("listKey is :" + listKey);
},
onAbilityContinue(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityContinue")
listKey.push(abilityName +" onAbilityContinue");
console.log(abilityName + " onAbilityContinue")
listKey.push(abilityName + " onAbilityContinue");
console.log("listKey is :" + listKey);
}
}
globalThis.mainAbility1ListKey = listKey
var callBackId = this.context.getApplicationContext().registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.ApplicationContext1 = this.context.getApplicationContext();
var callBackId = globalThis.ApplicationContext1.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.mainAbility1CallBackId = callBackId
setTimeout(() => {
console.log("listKey is :" + listKey);
console.log("callBackId is :" + callBackId);
this.context.getApplicationContext().unregisterAbilityLifecycleCallback (callBackId, (error, data)=> {
console.log("unRegisterAbilityLifecycleCallback err is :" +
JSON.stringify(error) + ",data is : " + JSON.stringify(data))
});
globalThis.ApplicationContext1
.unregisterAbilityLifecycleCallback(callBackId, (error, data) => {
console.log("unRegisterAbilityLifecycleCallback err is :" +
JSON.stringify(error) + ",data is : " + JSON.stringify(data))
});
}, 4000)
setTimeout(()=>{
setTimeout(() => {
this.context.terminateSelf().then((data) => {
console.log("[Demo] MainAbility1 terminateSelf windowStage data: " + JSON.stringify(data))
}).catch((error) => {
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -24,49 +24,50 @@ export default class MainAbility2 extends Ability {
let AbilityLifecycleCallback = {
onAbilityCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityCreate")
listKey.push(abilityName +" onAbilityCreate");
console.log(abilityName + " onAbilityCreate")
listKey.push(abilityName + " onAbilityCreate");
console.log("listKey is :" + listKey);
},
onAbilityWindowStageCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityWindowStageCreate")
listKey.push(abilityName +" onAbilityWindowStageCreate");
console.log(abilityName + " onAbilityWindowStageCreate")
listKey.push(abilityName + " onAbilityWindowStageCreate");
console.log("listKey is :" + listKey);
},
onAbilityForeground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityForeground")
listKey.push(abilityName +" onAbilityForeground");
console.log(abilityName + " onAbilityForeground")
listKey.push(abilityName + " onAbilityForeground");
console.log("listKey is :" + listKey);
},
onAbilityBackground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityBackground")
listKey.push(abilityName +" onAbilityBackground");
console.log(abilityName + " onAbilityBackground")
listKey.push(abilityName + " onAbilityBackground");
console.log("listKey is :" + listKey);
},
onAbilityWindowStageDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityWindowStageDestroy")
listKey.push(abilityName +" onAbilityWindowStageDestroy");
console.log(abilityName + " onAbilityWindowStageDestroy")
listKey.push(abilityName + " onAbilityWindowStageDestroy");
console.log("listKey is :" + listKey);
},
onAbilityDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityDestroy")
listKey.push(abilityName +" onAbilityDestroy");
console.log(abilityName + " onAbilityDestroy")
listKey.push(abilityName + " onAbilityDestroy");
console.log("listKey is :" + listKey);
},
onAbilityContinue(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityContinue")
listKey.push(abilityName +" onAbilityContinue");
console.log(abilityName + " onAbilityContinue")
listKey.push(abilityName + " onAbilityContinue");
console.log("listKey is :" + listKey);
}
}
var callBackId = this.context.getApplicationContext().registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.ApplicationContext2 = this.context.getApplicationContext();
var callBackId = globalThis.ApplicationContext2.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
setTimeout(() => {
globalThis.mainAbility2ListKey = listKey
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -26,11 +26,12 @@ export default class MainAbility3 extends Ability {
var a;
function SubscribeCallBackContext(err, data) {
console.log(" Subscribe CallBack data:" + JSON.stringify(data));
a = data.parameters;
if(data.event != ""){
for (var key in data.parameters){
if (data.event != "") {
for (var key in data.parameters) {
console.log("data.parameters[key] is :" + data.parameters[key])
}
}
......@@ -47,44 +48,44 @@ export default class MainAbility3 extends Ability {
let AbilityLifecycleCallback = {
onAbilityCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityCreate")
listKey.push(abilityName +" onAbilityCreate");
console.log(abilityName + " onAbilityCreate")
listKey.push(abilityName + " onAbilityCreate");
console.log("listKey is :" + listKey);
},
onAbilityWindowStageCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityWindowStageCreate")
listKey.push(abilityName +" onAbilityWindowStageCreate");
console.log(abilityName + " onAbilityWindowStageCreate")
listKey.push(abilityName + " onAbilityWindowStageCreate");
console.log("listKey is :" + listKey);
},
onAbilityForeground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityForeground")
listKey.push(abilityName +" onAbilityForeground");
console.log(abilityName + " onAbilityForeground")
listKey.push(abilityName + " onAbilityForeground");
console.log("listKey is :" + listKey);
},
onAbilityBackground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityBackground")
listKey.push(abilityName +" onAbilityBackground");
console.log(abilityName + " onAbilityBackground")
listKey.push(abilityName + " onAbilityBackground");
console.log("listKey is :" + listKey);
},
onAbilityWindowStageDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityWindowStageDestroy")
listKey.push(abilityName +" onAbilityWindowStageDestroy");
console.log(abilityName + " onAbilityWindowStageDestroy")
listKey.push(abilityName + " onAbilityWindowStageDestroy");
console.log("listKey is :" + listKey);
},
onAbilityDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityDestroy")
listKey.push(abilityName +" onAbilityDestroy");
console.log(abilityName + " onAbilityDestroy")
listKey.push(abilityName + " onAbilityDestroy");
console.log("listKey is :" + listKey);
},
onAbilityContinue(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName +" onAbilityContinue")
listKey.push(abilityName +" onAbilityContinue");
console.log(abilityName + " onAbilityContinue")
listKey.push(abilityName + " onAbilityContinue");
console.log("listKey is :" + listKey);
}
}
......@@ -92,8 +93,8 @@ export default class MainAbility3 extends Ability {
setTimeout(() => {
console.log("mainAbility3ListKey a is : " + JSON.stringify(a))
//TODO:
var callBackId = a.auxMainAbilityContext.getApplicationContext().
registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.ApplicationContext3 = this.context.getApplicationContext();
var callBackId = globalThis.ApplicationContext3.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("mainAbility3ListKey callBackId is : " + callBackId)
globalThis.mainAbility3ListKey = listKey
console.log("mainAbility3ListKey mainAbility3ListKey is : " + globalThis.mainAbility3ListKey)
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -18,69 +18,48 @@ export default class MainAbility4 extends Ability {
onCreate(want, launchParam) {
console.log("[Demo] MainAbility4 onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
console.log("[Demo] MainAbility4 onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility4 onWindowStageCreate")
windowStage.setUIContent(this.context, "pages/MainAbility4_pages", null)
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility4 onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility4 onForeground")
var listKey = [];
var abilityName = "";
let AbilityLifecycleCallback = {
onAbilityCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityCreate")
listKey.push(abilityName+" onAbilityCreate");
console.log(abilityName + " onAbilityCreate")
listKey.push(abilityName + " onAbilityCreate");
},
onAbilityWindowStageCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityWindowStageCreate")
listKey.push(abilityName+" onAbilityWindowStageCreate");
console.log(abilityName + " onAbilityWindowStageCreate")
listKey.push(abilityName + " onAbilityWindowStageCreate");
},
onAbilityForeground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityForeground")
listKey.push(abilityName+" onAbilityForeground");
console.log(abilityName + " onAbilityForeground")
listKey.push(abilityName + " onAbilityForeground");
},
onAbilityBackground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityBackground")
listKey.push(abilityName+" onAbilityBackground");
console.log(abilityName + " onAbilityBackground")
listKey.push(abilityName + " onAbilityBackground");
},
onAbilityWindowStageDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityWindowStageDestroy")
listKey.push(abilityName+" onAbilityWindowStageDestroy");
console.log(abilityName + " onAbilityWindowStageDestroy")
listKey.push(abilityName + " onAbilityWindowStageDestroy");
},
onAbilityDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityDestroy")
listKey.push(abilityName+" onAbilityDestroy");
console.log(abilityName + " onAbilityDestroy")
listKey.push(abilityName + " onAbilityDestroy");
},
onAbilityContinue(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityContinue")
listKey.push(abilityName+" onAbilityContinue");
console.log(abilityName + " onAbilityContinue")
listKey.push(abilityName + " onAbilityContinue");
}
}
var callBackId = this.context.getApplicationContext().registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.abilityContext111 = this.context;
globalThis.ApplicationContext4 = this.context.getApplicationContext();
var callBackId = globalThis.ApplicationContext4.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("callBackId is aaa :" + callBackId);
setTimeout(() => {
globalThis.mainAbility4ListKey = listKey
......@@ -88,6 +67,29 @@ export default class MainAbility4 extends Ability {
console.log("listKey is :" + listKey);
console.log("callBackId is :" + callBackId);
}, 3000)
}
onDestroy() {
console.log("[Demo] MainAbility4 onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility4 onWindowStageCreate")
globalThis.ability4context = this.context;
windowStage.setUIContent(this.context, "pages/MainAbility4_pages", null)
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility4 onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility4 onForeground")
}
onBackground() {
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -25,41 +25,42 @@ export default class MainAbility5 extends Ability {
let AbilityLifecycleCallback = {
onAbilityCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityCreate")
listKey.push(abilityName+" onAbilityCreate");
console.log(abilityName + " onAbilityCreate")
listKey.push(abilityName + " onAbilityCreate");
},
onAbilityWindowStageCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityWindowStageCreate")
listKey.push(abilityName+" onAbilityWindowStageCreate");
console.log(abilityName + " onAbilityWindowStageCreate")
listKey.push(abilityName + " onAbilityWindowStageCreate");
},
onAbilityForeground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityForeground")
listKey.push(abilityName+" onAbilityForeground");
console.log(abilityName + " onAbilityForeground")
listKey.push(abilityName + " onAbilityForeground");
},
onAbilityBackground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityBackground")
listKey.push(abilityName+" onAbilityBackground");
console.log(abilityName + " onAbilityBackground")
listKey.push(abilityName + " onAbilityBackground");
},
onAbilityWindowStageDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityWindowStageDestroy")
listKey.push(abilityName+" onAbilityWindowStageDestroy");
console.log(abilityName + " onAbilityWindowStageDestroy")
listKey.push(abilityName + " onAbilityWindowStageDestroy");
},
onAbilityDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityDestroy")
listKey.push(abilityName+" onAbilityDestroy");
console.log(abilityName + " onAbilityDestroy")
listKey.push(abilityName + " onAbilityDestroy");
},
onAbilityContinue(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityContinue")
listKey.push(abilityName+" onAbilityContinue");
console.log(abilityName + " onAbilityContinue")
listKey.push(abilityName + " onAbilityContinue");
}
}
var callBackId = this.context.getApplicationContext().registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.ApplicationContext5 = this.context.getApplicationContext();
var callBackId = globalThis.ApplicationContext5.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("callBackId is aaa :" + callBackId);
setTimeout(() => {
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -25,41 +25,42 @@ export default class MainAbility6 extends Ability {
let AbilityLifecycleCallback = {
onAbilityCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityCreate")
listKey.push(abilityName+" onAbilityCreate");
console.log(abilityName + " onAbilityCreate")
listKey.push(abilityName + " onAbilityCreate");
},
onAbilityWindowStageCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityWindowStageCreate")
listKey.push(abilityName+" onAbilityWindowStageCreate");
console.log(abilityName + " onAbilityWindowStageCreate")
listKey.push(abilityName + " onAbilityWindowStageCreate");
},
onAbilityForeground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityForeground")
listKey.push(abilityName+" onAbilityForeground");
console.log(abilityName + " onAbilityForeground")
listKey.push(abilityName + " onAbilityForeground");
},
onAbilityBackground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityBackground")
listKey.push(abilityName+" onAbilityBackground");
console.log(abilityName + " onAbilityBackground")
listKey.push(abilityName + " onAbilityBackground");
},
onAbilityWindowStageDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityWindowStageDestroy")
listKey.push(abilityName+" onAbilityWindowStageDestroy");
console.log(abilityName + " onAbilityWindowStageDestroy")
listKey.push(abilityName + " onAbilityWindowStageDestroy");
},
onAbilityDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityDestroy")
listKey.push(abilityName+" onAbilityDestroy");
console.log(abilityName + " onAbilityDestroy")
listKey.push(abilityName + " onAbilityDestroy");
},
onAbilityContinue(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName+" onAbilityContinue")
listKey.push(abilityName+" onAbilityContinue");
console.log(abilityName + " onAbilityContinue")
listKey.push(abilityName + " onAbilityContinue");
}
}
var callBackId = this.context.getApplicationContext().registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.ApplicationContext6 = this.context.getApplicationContext();
var callBackId = globalThis.ApplicationContext6.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("callBackId is aaa :" + callBackId);
setTimeout(() => {
globalThis.mainAbility6ListKey = listKey
......
import Ability from '@ohos.application.Ability'
export default class MainAbility7 extends Ability {
onCreate(want, launchParam) {
console.log("[Demo] MainAbility7 onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
console.log("[Demo] MainAbility7 onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility7 onWindowStageCreate")
globalThis.ability7context = this.context;
windowStage.setUIContent(this.context, "pages/MainAbility7_pages", null)
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility7 onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility7 onForeground")
var listKey = [];
var abilityName = "";
let AbilityLifecycleCallback = {
onAbilityCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName + " onAbilityCreate")
listKey.push(abilityName + " onAbilityCreate");
},
onAbilityWindowStageCreate(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName + " onAbilityWindowStageCreate")
listKey.push(abilityName + " onAbilityWindowStageCreate");
},
onAbilityForeground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName + " onAbilityForeground")
listKey.push(abilityName + " onAbilityForeground");
},
onAbilityBackground(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName + " onAbilityBackground")
listKey.push(abilityName + " onAbilityBackground");
},
onAbilityWindowStageDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName + " onAbilityWindowStageDestroy")
listKey.push(abilityName + " onAbilityWindowStageDestroy");
},
onAbilityDestroy(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName + " onAbilityDestroy")
listKey.push(abilityName + " onAbilityDestroy");
},
onAbilityContinue(ability) {
abilityName = ability.context.abilityInfo.name;
console.log(abilityName + " onAbilityContinue")
listKey.push(abilityName + " onAbilityContinue");
}
}
globalThis.ApplicationContext7 = globalThis.ability7context.getApplicationContext();
var callBackId = globalThis.ApplicationContext7.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
setTimeout(() => {
globalThis.mainAbility7ListKey = listKey
globalThis.mainAbility7CallBackId = callBackId
console.log("listKey is :" + listKey);
console.log("callBackId is :" + callBackId);
}, 3000)
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility7 onBackground")
}
};
// @ts-nocheck
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
// @ts-nocheck
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
// @ts-nocheck
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
// @ts-nocheck
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
// @ts-nocheck
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
// @ts-nocheck
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Entry
@Component
struct MainAbility7_pages {
@State message: string = 'MainAbility7'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
// @ts-nocheck
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets"
import list from '../test/ListTest'
@Entry
......
// @ts-nocheck
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -13,13 +13,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index"
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index"
export default function abilityTest(abilityContext){
export default function abilityTest(abilityContext) {
describe('AbilityTest', function() {
describe('AbilityTest', function () {
console.info("-----------------LifecycleTest is start----------------")
beforeEach(async function (done) {
console.info('LifeCycleTest before each called');
await sleep(1000);
done()
});
afterEach(async function (done) {
console.info('LifeCycleTest after each called');
if ("Multihap_LifecycleTest_007" != TAG || "Multihap_LifecycleTest_011" != TAG
|| "Multihap_LifecycleTest_006" != TAG) {
var para = {
resultCode: 2,
want: {
"abilityName": "MainAbility4",
bundleName: "com.example.lifecycletest"
}
}
console.log("LifeCycleTest terminateSelfwithresult para: " + JSON.stringify(para));
await globalThis.ability4context.terminateSelfWithResult(para)
.then((data) => {
console.log("LifeCycleTest terminateSelfwithresult successful data: " + JSON.stringify(data));
}).catch((error) => {
console.log("LifeCycleTest terminateSelfwithresult error: " + JSON.stringify(error));
});
}
done();
});
var TAG;
var listKeyTemp = [];
......@@ -49,7 +76,7 @@ export default function abilityTest(abilityContext){
",data: " + JSON.stringify(data));
});
await sleep(500);
await sleep(1000);
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
......@@ -63,7 +90,7 @@ export default function abilityTest(abilityContext){
listKeyTemp.push(globalThis.mainAbility4ListKey[i]);
}
}
console.log(TAG + "listKeyTemp is :" + listKeyTemp);
console.log(TAG + "listKeyTemp is :" + listKeyTemp);
console.log(TAG + "globalThis.mainAbility4CallBackId is :" + globalThis.mainAbility4CallBackId);
expect(listKeyTemp[0]).assertEqual("Hap2MainAbility3 onAbilityCreate");
expect(listKeyTemp[1]).assertEqual("Hap2MainAbility3 onAbilityWindowStageCreate");
......@@ -71,11 +98,12 @@ export default function abilityTest(abilityContext){
expect(listKeyTemp[3]).assertEqual("Hap2MainAbility3 onAbilityBackground");
expect(listKeyTemp[4]).assertEqual("Hap2MainAbility3 onAbilityWindowStageDestroy");
expect(listKeyTemp[5]).assertEqual("Hap2MainAbility3 onAbilityDestroy");
abilityContext.getApplicationContext()
console.info(TAG + "globalThis.ApplicationContext4 is :" + JSON.stringify(globalThis.ApplicationContext4));
globalThis.ApplicationContext4
.unregisterAbilityLifecycleCallback(globalThis.mainAbility4CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue()
expect(error.code).assertEqual(0);
done();
});
}, 4000)
......@@ -102,7 +130,7 @@ export default function abilityTest(abilityContext){
",data: " + JSON.stringify(data));
});
await sleep(500);
await sleep(1000);
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
......@@ -112,7 +140,7 @@ export default function abilityTest(abilityContext){
",data: " + JSON.stringify(data));
});
await sleep(500);
await sleep(1000);
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
......@@ -121,8 +149,8 @@ export default function abilityTest(abilityContext){
setTimeout(() => {
console.log(TAG + ": second Hap2MainAbility4 startAbility success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
for(var i = 0; i<globalThis.mainAbility4ListKey.length;i++){
if(globalThis.mainAbility4ListKey[i].substring(0,16)=="Hap2MainAbility4"){
for (var i = 0; i < globalThis.mainAbility4ListKey.length; i++) {
if (globalThis.mainAbility4ListKey[i].substring(0, 16) == "Hap2MainAbility4") {
listKeyTemp.push(globalThis.mainAbility4ListKey[i]);
}
}
......@@ -134,14 +162,14 @@ export default function abilityTest(abilityContext){
expect(listKeyTemp[3]).assertEqual("Hap2MainAbility4 onAbilityBackground");
expect(listKeyTemp[4]).assertEqual("Hap2MainAbility4 onAbilityWindowStageDestroy");
expect(listKeyTemp[5]).assertEqual("Hap2MainAbility4 onAbilityDestroy");
abilityContext.getApplicationContext()
globalThis.ApplicationContext4
.unregisterAbilityLifecycleCallback(globalThis.mainAbility4CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue()
expect(error.code).assertEqual(0);
done();
});
}, 3000)
}, 4000)
});
console.log("------------Multihap_LifecycleTest_002 end-------------");
});
......@@ -165,7 +193,7 @@ export default function abilityTest(abilityContext){
",data: " + JSON.stringify(data));
});
await sleep(500);
await sleep(1000);
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
......@@ -175,7 +203,7 @@ export default function abilityTest(abilityContext){
",data: " + JSON.stringify(data));
});
await sleep(500);
await sleep(1000);
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
......@@ -184,8 +212,8 @@ export default function abilityTest(abilityContext){
setTimeout(() => {
console.log(TAG + ": second Hap2MainAbility5 startAbility success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
for(var i = 0;i<globalThis.mainAbility4ListKey.length;i++){
if(globalThis.mainAbility4ListKey[i].substring(0,16)=="Hap2MainAbility5"){
for (var i = 0;i < globalThis.mainAbility4ListKey.length; i++) {
if (globalThis.mainAbility4ListKey[i].substring(0, 16) == "Hap2MainAbility5") {
listKeyTemp.push(globalThis.mainAbility4ListKey[i]);
}
}
......@@ -203,14 +231,14 @@ export default function abilityTest(abilityContext){
expect(listKeyTemp[9]).assertEqual("Hap2MainAbility5 onAbilityBackground");
expect(listKeyTemp[10]).assertEqual("Hap2MainAbility5 onAbilityWindowStageDestroy");
expect(listKeyTemp[11]).assertEqual("Hap2MainAbility5 onAbilityDestroy");
abilityContext.getApplicationContext()
globalThis.ApplicationContext4
.unregisterAbilityLifecycleCallback(globalThis.mainAbility4CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue()
expect(error.code).assertEqual(0);
done();
});
}, 3000)
}, 4000)
});
console.log("------------Multihap_LifecycleTest_003 end-------------");
});
......@@ -235,7 +263,7 @@ export default function abilityTest(abilityContext){
",data: " + JSON.stringify(data));
});
await sleep(500);
await sleep(1000);
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
......@@ -245,7 +273,7 @@ export default function abilityTest(abilityContext){
",data: " + JSON.stringify(data));
});
await sleep(500);
await sleep(1000);
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
......@@ -254,10 +282,10 @@ export default function abilityTest(abilityContext){
setTimeout(() => {
console.log(TAG + ": second Hap3MainAbility2 startAbility success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
for(var i = 0;i<globalThis.mainAbility4ListKey.length;i++){
if(globalThis.mainAbility4ListKey[i].substring(0,16)=="Hap2MainAbility6"){
for (var i = 0;i < globalThis.mainAbility4ListKey.length; i++) {
if (globalThis.mainAbility4ListKey[i].substring(0, 16) == "Hap2MainAbility6") {
listKeyTemp.push(globalThis.mainAbility4ListKey[i]);
}else if(globalThis.mainAbility4ListKey[i].substring(0,16)=="Hap3MainAbility2"){
} else if (globalThis.mainAbility4ListKey[i].substring(0, 16) == "Hap3MainAbility2") {
listKeyTemp1.push(globalThis.mainAbility4ListKey[i]);
}
}
......@@ -278,14 +306,14 @@ export default function abilityTest(abilityContext){
expect(listKeyTemp1[4]).assertEqual("Hap3MainAbility2 onAbilityWindowStageDestroy");
expect(listKeyTemp1[5]).assertEqual("Hap3MainAbility2 onAbilityDestroy");
abilityContext.getApplicationContext()
globalThis.ApplicationContext4
.unregisterAbilityLifecycleCallback(globalThis.mainAbility4CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue()
expect(error.code).assertEqual(0);
done();
});
}, 3000)
}, 4000)
});
console.log("------------Multihap_LifecycleTest_004 end-------------");
});
......@@ -329,10 +357,10 @@ export default function abilityTest(abilityContext){
setTimeout(() => {
console.log(TAG + ": second Hap2MainAbility7 startAbility success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
for(var i = 0;i<globalThis.mainAbility4ListKey.length;i++){
if(globalThis.mainAbility4ListKey[i].substring(0,16)=="Hap2MainAbility6"){
for (var i = 0;i < globalThis.mainAbility4ListKey.length; i++) {
if (globalThis.mainAbility4ListKey[i].substring(0, 16) == "Hap2MainAbility6") {
listKeyTemp.push(globalThis.mainAbility4ListKey[i]);
}else if(globalThis.mainAbility4ListKey[i].substring(0,16)=="Hap2MainAbility7"){
} else if (globalThis.mainAbility4ListKey[i].substring(0, 16) == "Hap2MainAbility7") {
listKeyTemp1.push(globalThis.mainAbility4ListKey[i]);
}
}
......@@ -353,11 +381,11 @@ export default function abilityTest(abilityContext){
expect(listKeyTemp1[4]).assertEqual("Hap2MainAbility7 onAbilityWindowStageDestroy");
expect(listKeyTemp1[5]).assertEqual("Hap2MainAbility7 onAbilityDestroy");
abilityContext.getApplicationContext()
globalThis.ApplicationContext4
.unregisterAbilityLifecycleCallback(globalThis.mainAbility4CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue()
expect(error.code).assertEqual(0);
done();
});
}, 3000)
......@@ -382,9 +410,9 @@ export default function abilityTest(abilityContext){
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
abilityName: "MainAbility4"
abilityName: "MainAbility7"
}, (error, data) => {
console.log(TAG + ": first MainAbility4 startAbility success, err: " + JSON.stringify(error) +
console.log(TAG + ": first MainAbility7 startAbility success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
});
......@@ -394,26 +422,26 @@ export default function abilityTest(abilityContext){
bundleName: "com.example.lifecycletest",
abilityName: "Hap2MainAbility8"
}, (error, data) => {
setTimeout(function(){
setTimeout(function () {
console.log(TAG + ": first Hap2MainAbility8 startAbility success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
console.log(TAG + "first globalThis.mainAbility4CallBackId is :" + globalThis.mainAbility4CallBackId);
firstCallbackId = globalThis.mainAbility4CallBackId;
console.log(TAG + "first globalThis.mainAbility7CallBackId is :" + globalThis.mainAbility7CallBackId);
firstCallbackId = globalThis.mainAbility7CallBackId;
console.log(TAG + "firstCallbackId is : " + firstCallbackId);
}, 3000)
});
await sleep(1000);
await sleep(500);
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
abilityName: "MainAbility4"
abilityName: "MainAbility7"
}, (error, data) => {
console.log(TAG + ": second MainAbility4 startAbility success, err: " + JSON.stringify(error) +
console.log(TAG + ": second MainAbility7 startAbility success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
});
await sleep(500);
await sleep(1000);
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
......@@ -422,24 +450,25 @@ export default function abilityTest(abilityContext){
setTimeout(() => {
console.log(TAG + ": second Hap2MainAbility8 startAbility success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
for(var i = 0;i<globalThis.mainAbility4ListKey.length;i++){
if(globalThis.mainAbility4ListKey[i].substring(0,16)=="Hap2MainAbility8"){
listKeyTemp1.push(globalThis.mainAbility4ListKey[i]);
for (var i = 0;i < globalThis.mainAbility7ListKey.length; i++) {
if (globalThis.mainAbility7ListKey[i].substring(0, 16) == "Hap2MainAbility8") {
listKeyTemp1.push(globalThis.mainAbility7ListKey[i]);
}
}
console.log(TAG + "second globalThis.mainAbility4CallBackId is :" + globalThis.mainAbility4CallBackId);
secondCallbackId = globalThis.mainAbility4CallBackId;
console.log(TAG + "second globalThis.mainAbility7CallBackId is :" + globalThis.mainAbility7CallBackId);
secondCallbackId = globalThis.mainAbility7CallBackId;
console.log(TAG + "secondCallbackId is : " + secondCallbackId);
expect(secondCallbackId).assertEqual(firstCallbackId+1)
abilityContext.getApplicationContext()
.unregisterAbilityLifecycleCallback(globalThis.mainAbility4CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue()
done();
});
}, 3000)
expect(secondCallbackId).assertEqual(firstCallbackId + 1)
setTimeout(() => {
globalThis.ApplicationContext7
.unregisterAbilityLifecycleCallback(globalThis.mainAbility7CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code).assertEqual(0);
done();
});
}, 1000)
}, 4000)
});
console.log("------------Multihap_LifecycleTest_006 end-------------");
......@@ -469,7 +498,7 @@ export default function abilityTest(abilityContext){
",data: " + JSON.stringify(data));
});
setTimeout(function(){
setTimeout(function () {
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
abilityName: "Hap2MainAbility9"
......@@ -478,8 +507,8 @@ export default function abilityTest(abilityContext){
console.log(TAG + ":first Hap2MainAbility9 startAbility success, err: " +
JSON.stringify(error) + ",data: " + JSON.stringify(data));
for(var i = 0;i<globalThis.mainAbility6ListKey.length;i++){
if(globalThis.mainAbility6ListKey[i].substring(0,16)=="Hap2MainAbility9"){
for (var i = 0;i < globalThis.mainAbility6ListKey.length; i++) {
if (globalThis.mainAbility6ListKey[i].substring(0, 16) == "Hap2MainAbility9") {
listKeyTemp.push(globalThis.mainAbility6ListKey[i]);
}
}
......@@ -494,11 +523,11 @@ export default function abilityTest(abilityContext){
expect(listKeyTemp[4]).assertEqual("Hap2MainAbility9 onAbilityWindowStageDestroy");
expect(listKeyTemp[5]).assertEqual("Hap2MainAbility9 onAbilityDestroy");
abilityContext.getApplicationContext()
globalThis.ApplicationContext6
.unregisterAbilityLifecycleCallback(globalThis.mainAbility6CallBackId, (error, data) => {
console.log(TAG + ": first unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue()
expect(error.code).assertEqual(0);
flag = error.code;
console.log(TAG + "flag is:" + flag);
});
......@@ -507,8 +536,8 @@ export default function abilityTest(abilityContext){
}, 1000)
setTimeout(function(){
if(flag == 0){
setTimeout(function () {
if (flag == 0) {
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
......@@ -518,7 +547,7 @@ export default function abilityTest(abilityContext){
",data: " + JSON.stringify(data));
});
setTimeout(function(){
setTimeout(function () {
abilityContext.startAbility({
bundleName: "com.example.lifecycletest",
abilityName: "Hap2MainAbility9"
......@@ -528,8 +557,8 @@ export default function abilityTest(abilityContext){
console.log(TAG + ":second Hap2MainAbility9 startAbility success, err: " +
JSON.stringify(error) + ",data: " + JSON.stringify(data));
for(var i = 0;i<globalThis.mainAbility6ListKey.length;i++){
if(globalThis.mainAbility6ListKey[i].substring(0,16)=="Hap2MainAbility9"){
for (var i = 0;i < globalThis.mainAbility6ListKey.length; i++) {
if (globalThis.mainAbility6ListKey[i].substring(0, 16) == "Hap2MainAbility9") {
listKeyTemp1.push(globalThis.mainAbility6ListKey[i]);
}
}
......@@ -545,16 +574,16 @@ export default function abilityTest(abilityContext){
expect(listKeyTemp1[4]).assertEqual("Hap2MainAbility9 onAbilityWindowStageDestroy");
expect(listKeyTemp1[5]).assertEqual("Hap2MainAbility9 onAbilityDestroy");
abilityContext.getApplicationContext()
globalThis.ApplicationContext6
.unregisterAbilityLifecycleCallback(globalThis.mainAbility6CallBackId, (error, data) => {
console.log(TAG + ": second unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue()
expect(error.code).assertEqual(0);
done();
});
}, 3000)
})
}, 2000)
}, 3000)
})
}, 2000)
}
}, 10000)
......@@ -591,8 +620,8 @@ export default function abilityTest(abilityContext){
console.log(TAG + ": Hap2MainAbility6 startAbility success, err: " +
JSON.stringify(error) + ",data: " + JSON.stringify(data));
for(var i = 0;i<globalThis.mainAbility4ListKey.length;i++){
if(globalThis.mainAbility4ListKey[i].substring(0,16)=="Hap2MainAbility6"){
for (var i = 0;i < globalThis.mainAbility4ListKey.length; i++) {
if (globalThis.mainAbility4ListKey[i].substring(0, 16) == "Hap2MainAbility6") {
listKeyTemp.push(globalThis.mainAbility4ListKey[i]);
}
}
......@@ -605,16 +634,16 @@ export default function abilityTest(abilityContext){
expect(listKeyTemp[4]).assertEqual("Hap2MainAbility6 onAbilityWindowStageDestroy");
expect(listKeyTemp[5]).assertEqual("Hap2MainAbility6 onAbilityDestroy");
abilityContext.getApplicationContext()
globalThis.ApplicationContext4
.unregisterAbilityLifecycleCallback(globalThis.mainAbility4CallBackId, (error, data) => {
console.log(TAG + ": first unregisterAbilityLifecycleCallback, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue;
abilityContext.getApplicationContext()
expect(error.code).assertEqual(0);
globalThis.ApplicationContext4
.unregisterAbilityLifecycleCallback(globalThis.mainAbility4CallBackId, (error, data) => {
console.log(TAG + ": second unregisterAbilityLifecycleCallback, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue;
expect(error.code).assertEqual(1);
done()
});
});
......@@ -702,7 +731,7 @@ export default function abilityTest(abilityContext){
for (var i = 0;i < globalThis.mainAbility4ListKey.length; i++) {
if (globalThis.mainAbility4ListKey[i].substring(0, 17) == "Hap2MainAbility10") {
listKeyTemp.push(globalThis.mainAbility4ListKey[i]);
}else if (globalThis.mainAbility4ListKey[i].substring(0, 16) == "Hap3MainAbility3") {
} else if (globalThis.mainAbility4ListKey[i].substring(0, 16) == "Hap3MainAbility3") {
listKeyTemp1.push(globalThis.mainAbility4ListKey[i]);
}
}
......@@ -727,11 +756,11 @@ export default function abilityTest(abilityContext){
expect(listKeyTemp1[5]).assertEqual("Hap3MainAbility3 onAbilityBackground");
expect(listKeyTemp1[6]).assertEqual("Hap3MainAbility3 onAbilityForeground");
abilityContext.getApplicationContext()
globalThis.ApplicationContext4
.unregisterAbilityLifecycleCallback(globalThis.mainAbility4CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue()
expect(error.code).assertEqual(0);
done();
});
}, 4000)
......@@ -765,26 +794,26 @@ export default function abilityTest(abilityContext){
bundleName: "com.example.lifecycletest",
abilityName: "Hap4MainAbility1",
}, (error, data) => {
setTimeout(() => {
console.log(TAG + ": Hap4MainAbility1 startAbility success, err: " +
JSON.stringify(error) + ",data: " + JSON.stringify(data));
setTimeout(() => {
console.log(TAG + ": Hap4MainAbility1 startAbility success, err: " +
JSON.stringify(error) + ",data: " + JSON.stringify(data));
for (var i = 0; i < globalThis.mainAbility2ListKey.length; i++) {
if (globalThis.mainAbility2ListKey[i].substring(0, 16) == "Hap4MainAbility1") {
listKeyTemp.push(globalThis.mainAbility2ListKey[i]);
for (var i = 0; i < globalThis.mainAbility2ListKey.length; i++) {
if (globalThis.mainAbility2ListKey[i].substring(0, 16) == "Hap4MainAbility1") {
listKeyTemp.push(globalThis.mainAbility2ListKey[i]);
}
}
}
console.log(TAG + " listKeyTemp is :" + listKeyTemp);
console.log(TAG + " globalThis.mainAbility2CallBackId is :" + globalThis.mainAbility2CallBackId);
expect(listKeyTemp.length == 0).assertTrue();
console.log(TAG + " listKeyTemp is :" + listKeyTemp);
console.log(TAG + " globalThis.mainAbility2CallBackId is :" + globalThis.mainAbility2CallBackId);
expect(listKeyTemp.length).assertEqual(0);
abilityContext.getApplicationContext()
.unregisterAbilityLifecycleCallback(globalThis.mainAbility2CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code == 0).assertTrue()
done();
});
globalThis.ApplicationContext2
.unregisterAbilityLifecycleCallback(globalThis.mainAbility2CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
expect(error.code).assertEqual(0);
done();
});
}, 4000)
});
console.info("---------------Multihap_LifecycleTest_011 is end---------------")
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......
......@@ -91,9 +91,9 @@ export default class MyAbilityStage extends AbilityStage {
console.log("[Demo] 7listKey:" + JSON.stringify(listKey));
}
}
let applicationContext = this.context.getApplicationContext();
console.log("[Demo] stage applicationContext: " + JSON.stringify(applicationContext));
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.applicationContext = this.context.getApplicationContext();
console.log("[Demo] stage applicationContext: " + JSON.stringify(globalThis.applicationContext));
let lifecycleid = globalThis.applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("[Demo] registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid));
setTimeout(function () {
console.log("[Demo] AbilityLifecycleCallback listKey : " + JSON.stringify(listKey));
......
......@@ -92,9 +92,8 @@ export default class MainAbility1 extends Ability {
console.log("[Demo] 7listKey1:" + JSON.stringify(listKey1));
}
}
let applicationContext = this.context.getApplicationContext();
console.log("[Demo] MainAbility1 applicationContext: " + JSON.stringify(applicationContext));
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.applicationContext1 = this.context.getApplicationContext();
let lifecycleid = globalThis.applicationContext1.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("[Demo] registerAbilityLifecycleCallback1 number: " + JSON.stringify(lifecycleid));
setTimeout(function () {
console.log("[Demo] registerAbilityLifecycleCallback1 listKey: " + JSON.stringify(listKey1));
......
......@@ -77,9 +77,8 @@ export default class MainAbility10 extends Ability {
console.log("[Demo] 7listKey10:" + JSON.stringify(listKey10));
}
}
let applicationContext = this.context.getApplicationContext();
console.log("[Demo] MainAbility10 applicationContext: " + JSON.stringify(applicationContext));
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.applicationContext10 = this.context.getApplicationContext();
let lifecycleid = globalThis.applicationContext10.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("[Demo] registerAbilityLifecycleCallback10 number: " + JSON.stringify(lifecycleid));
setTimeout(function () {
console.log("[Demo] registerAbilityLifecycleCallback10 listKey: " + JSON.stringify(listKey10));
......
......@@ -71,9 +71,8 @@ export default class MainAbility11 extends Ability {
listKey11.push(abilityname + " onAbilityContinue");
}
}
let applicationContext = globalThis.ability11.getApplicationContext();
console.log("[Demo] MainAbility11 applicationContext: " + JSON.stringify(applicationContext));
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.applicationContext11 = globalThis.ability11.getApplicationContext();
let lifecycleid = globalThis.applicationContext11.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("[Demo] registerAbilityLifecycleCallback11 number: " + JSON.stringify(lifecycleid));
setTimeout(function () {
console.log("[Demo] registerAbilityLifecycleCallback11 listKey: " + JSON.stringify(listKey11));
......
......@@ -70,9 +70,8 @@ export default class MainAbility12 extends Ability {
listKey12.push(abilityname + " onAbilityContinue");
}
}
let applicationContext = this.context.getApplicationContext();
console.log("[Demo] MainAbility12 applicationContext: " + JSON.stringify(applicationContext));
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.applicationContext12 = this.context.getApplicationContext();
let lifecycleid = globalThis.applicationContext12.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("[Demo] registerAbilityLifecycleCallback12 number: " + JSON.stringify(lifecycleid));
setTimeout(function () {
console.log("[Demo] registerAbilityLifecycleCallback12 listKey: " + JSON.stringify(listKey12));
......
......@@ -93,9 +93,8 @@ export default class MainAbility3 extends Ability {
console.log("[Demo] 7listKey3:" + JSON.stringify(listKey3));
}
}
let applicationContext = this.context.getApplicationContext();
console.log("[Demo] MainAbility3 applicationContext: " + JSON.stringify(applicationContext));
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.applicationContext3 = this.context.getApplicationContext();
let lifecycleid = globalThis.applicationContext3.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("[Demo] registerAbilityLifecycleCallback3 number: " + JSON.stringify(lifecycleid));
setTimeout(function () {
console.log("[Demo] registerAbilityLifecycleCallback3 listKey : " + JSON.stringify(listKey3));
......
......@@ -93,9 +93,8 @@ export default class MainAbility4 extends Ability {
console.log("[Demo] 7listKey4:" + JSON.stringify(listKey4));
}
}
let applicationContext = this.context.getApplicationContext();
console.log("[Demo] MainAbility4 applicationContext: " + JSON.stringify(applicationContext));
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.applicationContext4 = this.context.getApplicationContext();
let lifecycleid = globalThis.applicationContext4.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("[Demo] registerAbilityLifecycleCallback4 number: " + JSON.stringify(lifecycleid));
setTimeout(function () {
console.log("[Demo] registerAbilityLifecycleCallback4 listKey : " + JSON.stringify(listKey4));
......
......@@ -113,8 +113,8 @@ export default class MainAbility6 extends Ability {
console.log("[Demo] 7listKey6:" + JSON.stringify(listKey6));
}
}
let applicationContext = globalThis.ability6.getApplicationContext();
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.applicationContext6 = globalThis.ability6.getApplicationContext();
let lifecycleid = globalThis.applicationContext6.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("[Demo] registerAbilityLifecycleCallback6 number: " + JSON.stringify(lifecycleid));
setTimeout(function () {
console.log("[Demo] registerAbilityLifecycleCallback6 listKey: " + JSON.stringify(listKey6));
......
......@@ -113,8 +113,8 @@ export default class MainAbility7 extends Ability {
console.log("[Demo] 7listKey7:" + JSON.stringify(listKey7));
}
}
let applicationContext = this.context.getApplicationContext();
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.applicationContext7 = this.context.getApplicationContext();
let lifecycleid = globalThis.applicationContext7.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("[Demo] AbilityLifecycleCallback7 number: " + JSON.stringify(lifecycleid));
setTimeout(function () {
console.log("[Demo] AbilityLifecycleCallback7 listKey: " + JSON.stringify(listKey7));
......
......@@ -112,8 +112,8 @@ export default class MainAbility8 extends Ability {
console.log("[Demo] 7listKey8:" + JSON.stringify(listKey8));
}
}
let applicationContext = this.context.getApplicationContext();
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
globalThis.applicationContext8 = this.context.getApplicationContext();
let lifecycleid = globalThis.applicationContext8.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("[Demo] AbilityLifecycleCallback8 number: " + JSON.stringify(lifecycleid));
setTimeout(function () {
console.log("[Demo] AbilityLifecycleCallback8 listKey: " + JSON.stringify(listKey8));
......
......@@ -79,7 +79,8 @@ export default class MainAbility9 extends Ability {
listKey9.push(abilityName + " onAbilityContinue");
}
}
var callBackId = this.context.getApplicationContext()
globalThis.applicationContext9 = this.context.getApplicationContext();
var callBackId = globalThis.applicationContext9
.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("callBackId is aaa :" + callBackId);
......
......@@ -64,9 +64,12 @@ export default function lifecycleTest(abilityContext) {
var TAG = "";
var listKeyTemp = ""
var tempCallbackId;
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time))
}
/*
* @tc.number Singlehap_LifeCycleTest_0100
* @tc.name Register in abilitystage,listen to the lifecycle of abilityA,deregister after listening
......@@ -90,6 +93,8 @@ export default function lifecycleTest(abilityContext) {
setTimeout(function () {
console.log(TAG + " registerAbilityLifecycleCallback listKey : " + JSON.stringify(globalThis.list));
console.log(TAG + " registerAbilityLifecycleCallback callbackid : " + JSON.stringify(globalThis.callbackid));
tempCallbackId = globalThis.callbackid;
console.log(TAG + " registerAbilityLifecycleCallback tempCallbackId : " + JSON.stringify(tempCallbackId));
var strtemp = "";
var listtemp = [];
for (var i = 0; i < globalThis.list.length; i++) {
......@@ -100,8 +105,8 @@ export default function lifecycleTest(abilityContext) {
}
console.log(TAG + " listtemp is :" + JSON.stringify(listtemp));
let exlist = listtemp;
globalThis.abilityContext.getApplicationContext()
.unregisterAbilityLifecycleCallback(globalThis.callbackid, (error, data) => {
globalThis.applicationContext
.unregisterAbilityLifecycleCallback(tempCallbackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
code = error.code;
......@@ -154,7 +159,6 @@ export default function lifecycleTest(abilityContext) {
}, 500);
setTimeout(function () {
console.log(TAG + " registerAbilityLifecycleCallback listKey : " + JSON.stringify(globalThis.list1));
var list = globalThis.list1
console.log(TAG + " registerAbilityLifecycleCallback callbackid : " + JSON.stringify(globalThis.callbackid1));
var strtemp = "";
var listtemp = [];
......@@ -166,7 +170,7 @@ export default function lifecycleTest(abilityContext) {
}
console.log(TAG + " listtemp is :" + JSON.stringify(listtemp));
let exlist = listtemp;
globalThis.ability1context.getApplicationContext()
globalThis.applicationContext1
.unregisterAbilityLifecycleCallback(globalThis.callbackid1, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -235,7 +239,7 @@ export default function lifecycleTest(abilityContext) {
}
console.log(TAG + " listtemp is :" + JSON.stringify(listtemp));
let exlist = listtemp;
globalThis.ability1context.getApplicationContext()
globalThis.applicationContext1
.unregisterAbilityLifecycleCallback(globalThis.callbackid1)
.then((data) => {
console.info(TAG + ' unregisterAbilityLifecycleCallback successful. Data: ' + data);
......@@ -245,7 +249,7 @@ export default function lifecycleTest(abilityContext) {
})
setTimeout(function () {
console.log(TAG + " secondunregister callbackid : " + JSON.stringify(globalThis.callbackid1));
globalThis.ability1context.getApplicationContext()
globalThis.applicationContext1
.unregisterAbilityLifecycleCallback(globalThis.callbackid1, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback_1 success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -330,7 +334,7 @@ export default function lifecycleTest(abilityContext) {
console.log(TAG + " terminateSelfwithresult error: " + JSON.stringify(error));
});
setTimeout(function () {
globalThis.ability1context.getApplicationContext()
globalThis.applicationContext3
.unregisterAbilityLifecycleCallback(globalThis.callbackid3, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback3 success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -388,7 +392,7 @@ export default function lifecycleTest(abilityContext) {
}, 500);
setTimeout(function () {
console.log(TAG + " start after callbackid3 : " + JSON.stringify(globalThis.callbackid3));
globalThis.abilityContext.getApplicationContext()
globalThis.applicationContext3
.unregisterAbilityLifecycleCallback(globalThis.callbackid3)
.then((data) => {
console.info(TAG + ' unregisterAbilityLifecycleCallback3 successful. Data: ' + data);
......@@ -417,12 +421,12 @@ export default function lifecycleTest(abilityContext) {
console.log(TAG + " callbackid4 : " + JSON.stringify(globalThis.callbackid4));
let id4 = globalThis.callbackid4;
expect(id3 + 1).assertEqual(id4);
globalThis.ability1context.getApplicationContext()
globalThis.applicationContext4
.unregisterAbilityLifecycleCallback(globalThis.callbackid4, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback4 success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
})
globalThis.ability1context.getApplicationContext()
globalThis.applicationContext1
.unregisterAbilityLifecycleCallback(globalThis.callbackid1, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback1 success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -500,7 +504,7 @@ export default function lifecycleTest(abilityContext) {
expect(exlist[9]).assertEqual("MainAbility2 onAbilityBackground");
expect(exlist[10]).assertEqual("MainAbility2 onAbilityWindowStageDestroy");
expect(exlist[11]).assertEqual("MainAbility2 onAbilityDestroy");
globalThis.ability1context.getApplicationContext()
globalThis.applicationContext1
.unregisterAbilityLifecycleCallback(globalThis.callbackid1, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -666,6 +670,7 @@ export default function lifecycleTest(abilityContext) {
console.error(TAG + ' start failed. Cause: ' + JSON.stringify(error));
})
}, 3000);
setTimeout(function () {
var str1 = {
"bundleName": "com.example.lifecycle_xts",
......@@ -678,6 +683,7 @@ export default function lifecycleTest(abilityContext) {
console.error(TAG + ' start failed. Cause: ' + JSON.stringify(error));
})
}, 4500);
setTimeout(function () {
console.log(TAG + " registerAbilityLifecycleCallback listKey : " + JSON.stringify(globalThis.list1));
console.log(TAG + " registerAbilityLifecycleCallback callbackid : " + JSON.stringify(globalThis.callbackid1));
......@@ -713,7 +719,7 @@ export default function lifecycleTest(abilityContext) {
expect(exlist[19]).assertEqual("MainAbility2 onAbilityWindowStageCreate");
expect(exlist[20]).assertEqual("MainAbility2 onAbilityForeground");
expect(exlist[21]).assertEqual("MainAbility1 onAbilityBackground");
abilityContext.getApplicationContext()
globalThis.applicationContext1
.unregisterAbilityLifecycleCallback(globalThis.callbackid1, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -797,7 +803,7 @@ export default function lifecycleTest(abilityContext) {
expect(exlist[15]).assertEqual("MainAbility2 onAbilityBackground");
expect(exlist[16]).assertEqual("MainAbility2 onAbilityWindowStageDestroy");
expect(exlist[17]).assertEqual("MainAbility2 onAbilityDestroy");
abilityContext.getApplicationContext()
globalThis.applicationContext1
.unregisterAbilityLifecycleCallback(globalThis.callbackid1, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -850,7 +856,7 @@ export default function lifecycleTest(abilityContext) {
id2 = globalThis.callbackid6;
console.log(TAG + " secondCallback id : " + JSON.stringify(id2));
expect(id1 + 1).assertEqual(id2);
abilityContext.getApplicationContext()
globalThis.applicationContext6
.unregisterAbilityLifecycleCallback(globalThis.callbackid6, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -903,7 +909,7 @@ export default function lifecycleTest(abilityContext) {
id2 = globalThis.callbackid7;
console.log(TAG + " secondCallback id : " + JSON.stringify(id2));
expect(id1).assertEqual(id2);
abilityContext.getApplicationContext()
globalThis.applicationContext7
.unregisterAbilityLifecycleCallback(globalThis.callbackid7, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -967,7 +973,7 @@ export default function lifecycleTest(abilityContext) {
id2 = globalThis.callbackid8;
console.log(TAG + " secondCallback id : " + JSON.stringify(id2));
expect(id1 + 1).assertEqual(id2);
abilityContext.getApplicationContext()
globalThis.applicationContext8
.unregisterAbilityLifecycleCallback(globalThis.callbackid8, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -1035,7 +1041,7 @@ export default function lifecycleTest(abilityContext) {
expect(listKeyTemp[3]).assertEqual("Hap1MainAbility1 onAbilityBackground");
expect(listKeyTemp[4]).assertEqual("Hap1MainAbility1 onAbilityWindowStageDestroy");
expect(listKeyTemp[5]).assertEqual("Hap1MainAbility1 onAbilityDestroy");
abilityContext.getApplicationContext()
globalThis.applicationContext9
.unregisterAbilityLifecycleCallback(globalThis.mainAbility9CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -1098,7 +1104,7 @@ export default function lifecycleTest(abilityContext) {
expect(listKeyTemp[9]).assertEqual("Hap1MainAbility2 onAbilityBackground");
expect(listKeyTemp[10]).assertEqual("Hap1MainAbility2 onAbilityWindowStageDestroy");
expect(listKeyTemp[11]).assertEqual("Hap1MainAbility2 onAbilityDestroy");
abilityContext.getApplicationContext()
globalThis.applicationContext9
.unregisterAbilityLifecycleCallback(globalThis.mainAbility9CallBackId, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -1191,7 +1197,7 @@ export default function lifecycleTest(abilityContext) {
expect(exlist[4]).assertEqual("MainAbility2 onAbilityWindowStageDestroy");
expect(exlist[5]).assertEqual("MainAbility2 onAbilityDestroy");
expect(id1 + 1).assertEqual(id2);
abilityContext.getApplicationContext()
globalThis.applicationContext11
.unregisterAbilityLifecycleCallback(globalThis.callbackid11, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -1387,8 +1393,8 @@ export default function lifecycleTest(abilityContext) {
expect(exlist[4]).assertEqual("MainAbility2 onAbilityWindowStageDestroy");
expect(exlist[5]).assertEqual("MainAbility2 onAbilityDestroy");
expect(id1 + 1).assertEqual(id2);
abilityContext.getApplicationContext()
.unregisterAbilityLifecycleCallback(globalThis.callbackid6, (error, data) => {
globalThis.applicationContext12
.unregisterAbilityLifecycleCallback(id2, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
console.log("------------Singlehap_LifeCycleTest_2000 END-------------");
......@@ -1574,12 +1580,12 @@ export default function lifecycleTest(abilityContext) {
expect(exlist1[5]).assertEqual("MainAbility2 onAbilityDestroy");
expect(id1 + 1).assertEqual(id2);
expect(id3 + 1).assertEqual(id4);
abilityContext.getApplicationContext()
globalThis.applicationContext12
.unregisterAbilityLifecycleCallback(globalThis.callbackid12, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
});
abilityContext.getApplicationContext()
globalThis.applicationContext1
.unregisterAbilityLifecycleCallback(globalThis.callbackid1, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
......@@ -1589,5 +1595,6 @@ export default function lifecycleTest(abilityContext) {
}, 100);
}, 7000);
});
})
}
\ No newline at end of file
......@@ -13,7 +13,9 @@
* limitations under the License.
*/
import LifeCycleTest from './LifeCycleTest'
import Test from './Test'
export default function List(context) {
LifeCycleTest(context)
// Test(context)
}
\ No newline at end of file
// @ts-nocheck
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index"
export default function lifecycleTest(abilityContext) {
describe('LifeCycleTest', function () {
beforeEach(async function (done) {
console.info('LifeCycleTest before each called');
await sleep(1000);
done()
});
afterEach(async function (done) {
console.info('LifeCycleTest after each called');
if ("Singlehap_LifeCycleTest_0200" === TAG || "Singlehap_LifeCycleTest_0300" === TAG
|| "Singlehap_LifeCycleTest_0500" === TAG || "Singlehap_LifeCycleTest_0600" === TAG
|| "Singlehap_LifeCycleTest_0800" === TAG || "Singlehap_LifeCycleTest_0900" === TAG) {
var para = {
resultCode: 2,
want: {
"abilityName": "MainAbility1",
"bundleName": "com.example.lifecycle_xts"
}
}
console.log("LifeCycleTest terminateSelfwithresult para: " + JSON.stringify(para));
await globalThis.ability1context.terminateSelfWithResult(para)
.then((data) => {
console.log("LifeCycleTest terminateSelfwithresult successful data: " + JSON.stringify(data));
}).catch((error) => {
console.log("LifeCycleTest terminateSelfwithresult error: " + JSON.stringify(error));
});
} else if ("Singlehap_LifeCycleTest_2000" === TAG) {
var para1 = {
resultCode: 2,
want: {
"abilityName": "MainAbility12",
"bundleName": "com.example.lifecycle_xts"
}
}
console.log("LifeCycleTest terminateSelfwithresult para: " + JSON.stringify(para1));
await globalThis.ability12.terminateSelfWithResult(para1)
.then((data) => {
console.log("LifeCycleTest terminateSelfwithresult successful data: " + JSON.stringify(data));
}).catch((error) => {
console.log("LifeCycleTest terminateSelfwithresult error: " + JSON.stringify(error));
});
}
done();
});
var TAG = "";
var listKeyTemp = ""
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time))
}
/*
* @tc.number Singlehap_LifeCycleTest_0700
* @tc.name Multiple registration/unregistration
* @tc.desc Function test
* @tc.level 0
*/
it("Singlehap_LifeCycleTest_0700", 0, async function (done) {
console.log("------------Singlehap_LifeCycleTest_0700 START-------------");
TAG = "Singlehap_LifeCycleTest_0700";
var code1;
var code2;
var code3;
var id1;
var id2;
var id3;
var listKey8 = [];
let AbilityLifecycleCallback = {
onAbilityCreate(ability) {
console.log(TAG + " onAbilityCreate ability:" + JSON.stringify(ability));
let abilityname = ability.context.abilityInfo.name;
console.log(TAG + " onAbilityCreate abilityname:" + JSON.stringify(abilityname));
console.log(TAG + " " + abilityname + " onAbilityCreate");
listKey8.push(abilityname + " onAbilityCreate");
},
onAbilityWindowStageCreate(ability) {
console.log(TAG + " onAbilityWindowStageCreate ability:" + JSON.stringify(ability));
let abilityname = ability.context.abilityInfo.name;
console.log(TAG + " onAbilityWindowStageCreate abilityname:" + JSON.stringify(abilityname));
console.log(TAG + " " + abilityname + " onAbilityWindowStageCreate");
listKey8.push(abilityname + " onAbilityWindowStageCreate");
},
onAbilityWindowStageDestroy(ability) {
console.log(TAG + " AbilityLifecycleCallback1 onAbilityWindowStageDestroy ability:"
+ JSON.stringify(ability));
let abilityname = ability.context.abilityInfo.name;
console.log(TAG + " AbilityLifecycleCallback1 onAbilityWindowStageDestroy abilityname:"
+ JSON.stringify(abilityname));
console.log(TAG + " " + abilityname + " onAbilityWindowStageDestroy");
listKey8.push(abilityname + " onAbilityWindowStageDestroy");
},
onAbilityDestroy(ability) {
console.log(TAG + " AbilityLifecycleCallback1 onAbilityDestroy ability:"
+ JSON.stringify(ability));
let abilityname = ability.context.abilityInfo.name;
console.log(TAG + " AbilityLifecycleCallback1 onAbilityDestroy abilityname:"
+ JSON.stringify(abilityname));
console.log(TAG + " " + abilityname + " onAbilityDestroy");
listKey8.push(abilityname + " onAbilityDestroy");
},
onAbilityForeground(ability) {
console.log(TAG + " AbilityLifecycleCallback1 onAbilityForeground ability:"
+ JSON.stringify(ability));
let abilityname = ability.context.abilityInfo.name;
console.log(TAG + " AbilityLifecycleCallback1 onAbilityForeground abilityname:"
+ JSON.stringify(abilityname));
console.log(TAG + " " + abilityname + " onAbilityForeground");
listKey8.push(abilityname + " onAbilityForeground");
},
onAbilityBackground(ability) {
console.log(TAG + " AbilityLifecycleCallback1 onAbilityBackground ability:"
+ JSON.stringify(ability));
let abilityname = ability.context.abilityInfo.name;
console.log(TAG + " AbilityLifecycleCallback1 onAbilityBackground abilityname:"
+ JSON.stringify(abilityname));
console.log(TAG + " " + abilityname + " onAbilityBackground");
listKey8.push(abilityname + " onAbilityBackground");
},
onAbilityContinue(ability) {
console.log(TAG + " AbilityLifecycleCallback1 onAbilityContinue ability:"
+ JSON.stringify(ability));
let abilityname = ability.context.abilityInfo.name;
console.log(TAG + " AbilityLifecycleCallback1 onAbilityContinue abilityname:"
+ JSON.stringify(abilityname));
console.log(TAG + " " + abilityname + " onAbilityContinue");
listKey8.push(abilityname + " onAbilityContinue");
}
}
let applicationContext = globalThis.abilityContext.getApplicationContext();
id1 = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log(TAG + " registerAbilityLifecycleCallback1 number: " + JSON.stringify(id1));
applicationContext.unregisterAbilityLifecycleCallback(id1, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback1 success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
code1 = error.code;
})
setTimeout(function () {
id2 = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log(TAG + " registerAbilityLifecycleCallback2 number: " + JSON.stringify(id2));
applicationContext.unregisterAbilityLifecycleCallback(id2, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback2 success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
code2 = error.code;
})
}, 1000);
setTimeout(function () {
id3 = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log(TAG + " registerAbilityLifecycleCallback3 number: " + JSON.stringify(id3));
applicationContext.unregisterAbilityLifecycleCallback(id3, (error, data) => {
console.log(TAG + ": unregisterAbilityLifecycleCallback3 success, err: " + JSON.stringify(error) +
",data: " + JSON.stringify(data));
code3 = error.code;
expect(id1 > 0).assertTrue();
expect(id2).assertEqual(id1 + 1);
expect(id3).assertEqual(id2 + 1);
expect(code1).assertEqual(0);
expect(code2).assertEqual(0);
expect(code3).assertEqual(0);
console.log("------------Singlehap_LifeCycleTest_0700 END-------------");
done();
})
}, 3000);
});
})
}
\ No newline at end of file
......@@ -6,7 +6,8 @@
"description": "$string:phone_entry_dsc",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
"phone",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
......@@ -133,4 +134,4 @@
"label": "$string:MainAbility12_label"
}]
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册