diff --git a/ability/ability_runtime/BUILD.gn b/ability/ability_runtime/BUILD.gn index 5b9daed008aa1c92f642532d5e29ecd98e4c2989..fc90f4a74a019873d9b54a7cc4c8b133352de7c9 100644 --- a/ability/ability_runtime/BUILD.gn +++ b/ability/ability_runtime/BUILD.gn @@ -43,6 +43,7 @@ group("ability_runtime") { "amsgetabilityprocessinfo:amsgetabilityprocessinfo", "apicover:apicover", "apitest:ActsApiTest", + "apprecovery:apprecovery", "context:context", "fa:fa", "faapicover:faapicover", diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/AppScope/app.json b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..1955d14f2638ccf77a9bf13d9cc787ef7eb2cbbd --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/AppScope/app.json @@ -0,0 +1,19 @@ +{ + "app": { + "bundleName": "com.example.actsapprecoverytestcaller", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "keepAlive" : true, + "singleUser": true, + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/AppScope/resources/base/element/string.json b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..085dcba9658eaa44cfd3f1db51a5eb70414ee8ac --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ActsAppRecoveryTestCaller" + } + ] +} diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/BUILD.gn b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9b6c27f01f0c2014f7096b24ef585886a8610ba9 --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsAppRecoveryTestCaller") { + hap_profile = "entry/src/ohosTest/module.json" + js_build_mode = "debug" + deps = [ + ":actsapprecoverytestcaller_js_assets", + ":actsapprecoverytestcaller_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsAppRecoveryTestCaller" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("actsapprecoverytestcaller_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("actsapprecoverytestcaller_js_assets") { + source_dir = "entry/src/ohosTest/ets" +} + +ohos_resources("actsapprecoverytestcaller_resources") { + sources = [ "entry/src/ohosTest/resources" ] + deps = [ ":actsapprecoverytestcaller_app_profile" ] + hap_profile = "entry/src/ohosTest/module.json" +} diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/Test.json b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..5d2ed553494c1402da51edbd6bef70a1988fb34f --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/Test.json @@ -0,0 +1,28 @@ +{ + "description": "Configuration for aceceshi Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "bundle-name": "com.example.actsapprecoverytestcaller", + "module-name": "entry_test", + "shell-timeout": "600000" + }, + "kits": [ + { + "test-file-name": [ + "ActsAppRecoveryTestCaller.hap", + "AppRecoveryRely.hap", + "AppRecoverysRely.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + "power-shell wakeup", + "power-shell setmode 602" + ] + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/test/Ability.test.ets b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..caac2f1229edc3979b995a0a7e37136a0f08c650 --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,546 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import commonEvent from '@ohos.commonEvent' +import abilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import missionManager from '@ohos.application.missionManager'; + + +const CASE_TIME_OUT=5000; +var ACTS_AppRecovery = { + events: ["ACTS_AppRecovery_First", "ACTS_AppRecovery_Second"] +}; + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + beforeAll(function () {}) + beforeEach(function () {}) + afterEach(function () {}) + afterAll(function () {}) + + /* + * @tc.number: Acts_AppRecovery_0100 + * @tc.name: Fault recovery of multi-Ability application + * @tc.desc: When the application settings restart recovery status is valid, the pre-failure state of Ability + * application will not be restored after normal exit and restart. + */ + it('Acts_AppRecovery_0100',0, async function (done) { + let subscriber; + let flag = false; + console.info("Acts_AppRecovery_0100====> start") + commonEvent.createSubscriber(ACTS_AppRecovery).then(async (data) => { + console.debug("Acts_AppRecovery_0100====> Create Subscribe"); + subscriber = data; + commonEvent.subscribe(subscriber, subscribeCallBack); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoveryrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0100_once" + },(err)=>{ + console.debug("Acts_AppRecovery_0100====> startAbility err:"+JSON.stringify(err)); + expect(err.code).assertEqual(0); + }) + }) + + function subscribeCallBack(err, data) { + console.debug("Acts_AppRecovery_0100====> subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_First") { + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + setTimeout(() => { + commonEvent.subscribe(subscriber, subscribeCallBackSecond); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoveryrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0100_twice" + }, + (err) => { + console.debug("Acts_AppRecovery_0100====> second startAbility err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + } + ); + }, 800); + } + } + + function subscribeCallBackSecond(err, data) { + console.debug("Acts_AppRecovery_0100====> second subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_Second") { + flag=true; + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + + function unSubscribeCallback() { + setTimeout(() => { + console.debug("Acts_AppRecovery_0100====> unSubscribeCallback"); + done(); + }, 800); + } + + setTimeout(()=>{ + if(flag==false){ + expect().assertFail(); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + },CASE_TIME_OUT) + }) + + /* + * @tc.number: Acts_AppRecovery_0200 + * @tc.name: Fault recovery of multi-Ability application + * @tc.desc: When the application settings restart recovery status is valid, the pre-failure state of Ability + * application will not be restored after normal exit and restart. + */ + it('Acts_AppRecovery_0200',0, async function (done) { + let subscriber; + let flag = false; + let countFirst = 0; + let countSecond = 0; + console.info("Acts_AppRecovery_0200====> start") + commonEvent.createSubscriber(ACTS_AppRecovery).then(async (data) => { + console.debug("Acts_AppRecovery_0200====> Create Subscribe"); + subscriber = data; + commonEvent.subscribe(subscriber, subscribeCallBack); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoverysrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0200_once" + },(err)=>{ + console.debug("Acts_AppRecovery_0200====> startAbility err:"+JSON.stringify(err)); + expect(err.code).assertEqual(0); + }) + }) + + function subscribeCallBack(err, data) { + console.debug("Acts_AppRecovery_0200====> subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_First") { + countFirst++; + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + if (countFirst < 2) { + return; + } + setTimeout(() => { + commonEvent.subscribe(subscriber, subscribeCallBackSecond); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoverysrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0200_twice" + }, + (err) => { + console.debug("Acts_AppRecovery_0200====> second startAbility err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + } + ); + }, 800); + } + } + + function subscribeCallBackSecond(err, data) { + console.debug("Acts_AppRecovery_0200====> second subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_Second") { + countSecond++; + flag=true; + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + if (countSecond == 2) { + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + } + + function unSubscribeCallback() { + setTimeout(() => { + console.debug("Acts_AppRecovery_0200====> unSubscribeCallback"); + done(); + }, 800); + } + + setTimeout(()=>{ + if(flag==false){ + expect().assertFail(); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + },CASE_TIME_OUT) + }) + + /* + * @tc.number: Acts_AppRecovery_0300 + * @tc.name: Fault recovery of multi-Ability application + * @tc.desc: When the application setting restart recovery status is valid, exit the application by clearing the + * task list and do not restore the pre-failure state of the Ability application after the application + * restart. + */ + it('Acts_AppRecovery_0300',0, async function (done) { + let subscriber; + let flag = false; + console.info("Acts_AppRecovery_0300====> start") + commonEvent.createSubscriber(ACTS_AppRecovery).then(async (data) => { + console.debug("Acts_AppRecovery_0300====> Create Subscribe"); + subscriber = data; + commonEvent.subscribe(subscriber, subscribeCallBack); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoveryrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0300_once" + },(err)=>{ + console.debug("Acts_AppRecovery_0300====> startAbility err:"+JSON.stringify(err)); + expect(err.code).assertEqual(0); + }) + }) + function subscribeCallBack(err, data) { + console.debug("Acts_AppRecovery_0300====> subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_First") { + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + missionManager.getMissionInfos('', 1024, (err, missionInfos)=>{ + console.debug('Acts_AppRecovery_0300====> missionInfos: ' + JSON.stringify(missionInfos)); + console.debug('Acts_AppRecovery_0300====> missionInfos.length: ' + JSON.stringify(missionInfos.length)); + for (var i = 0; i < missionInfos.length; i++) { + if ((missionInfos[i].want.bundleName == "com.example.apprecoveryrely") + && (missionInfos[i].want.abilityName == "EntryAbility")) { + missionManager.clearMission(missionInfos[i].missionId, (err)=>{ + console.debug('Acts_AppRecovery_0300====> clearMission err: ' + JSON.stringify(err)); + }) + } + } + setTimeout(()=>{ + commonEvent.subscribe(subscriber, subscribeCallBackSecond); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoveryrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0300_twice" + }, (err) => { + console.debug("Acts_AppRecovery_0300====> second startAbility err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + }) + }, 800) + }); + } + } + function subscribeCallBackSecond(err, data) { + console.debug("Acts_AppRecovery_0300====> second subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_Second") { + flag=true; + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + function unSubscribeCallback() { + setTimeout(() => { + console.debug("Acts_AppRecovery_0300====> unSubscribeCallback"); + done(); + }, 800); + } + setTimeout(()=>{ + if(flag==false){ + expect().assertFail(); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + },CASE_TIME_OUT) + }) + + + /* + * @tc.number: Acts_AppRecovery_0400 + * @tc.name: Fault recovery of multi-Ability application + * @tc.desc: When the application setting restart recovery status is valid, exit the application by clearing the + * task list and do not restore the pre-failure state of the Ability application after the application + * restart. + */ + it('Acts_AppRecovery_0400',0, async function (done) { + let subscriber; + let flag = false; + let countFirst = 0; + let countSecond = 0; + console.info("Acts_AppRecovery_0400====> start") + commonEvent.createSubscriber(ACTS_AppRecovery).then(async (data) => { + console.debug("Acts_AppRecovery_0400====> Create Subscribe"); + subscriber = data; + commonEvent.subscribe(subscriber, subscribeCallBack); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoverysrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0400_once" + },(err)=>{ + console.debug("Acts_AppRecovery_0400====> startAbility err:"+JSON.stringify(err)); + expect(err.code).assertEqual(0); + }) + }) + function subscribeCallBack(err, data) { + console.debug("Acts_AppRecovery_0400====> subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_First") { + countFirst++; + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + if (countFirst < 2) { + return; + } + missionManager.getMissionInfos('', 1024, (err, missionInfos)=>{ + console.debug('Acts_AppRecovery_0400====> missionInfos: ' + JSON.stringify(missionInfos)); + console.debug('Acts_AppRecovery_0400====> missionInfos.length: ' + JSON.stringify(missionInfos.length)); + for (var i = 0; i < missionInfos.length; i++) { + if ((missionInfos[i].want.bundleName == "com.example.apprecoverysrely") + && ((missionInfos[i].want.abilityName == "EntryAbility") || + (missionInfos[i].want.abilityName == "EntryAbilitySec"))){ + missionManager.clearMission(missionInfos[i].missionId, (err)=>{ + console.debug('Acts_AppRecovery_0400====> clearMission err: ' + JSON.stringify(err)); + }) + } + } + setTimeout(()=>{ + commonEvent.subscribe(subscriber, subscribeCallBackSecond); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoverysrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0400_twice" + }, (err) => { + console.debug("Acts_AppRecovery_0400====> second startAbility err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + }) + },800) + }); + } + } + function subscribeCallBackSecond(err, data) { + console.debug("Acts_AppRecovery_0400====> second subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_Second") { + countSecond++; + flag=true; + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + if (countSecond < 2) { + return; + } + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + function unSubscribeCallback() { + setTimeout(() => { + console.debug("Acts_AppRecovery_0400====> unSubscribeCallback"); + done(); + }, 800); + } + setTimeout(()=>{ + if(flag==false){ + expect().assertFail(); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + },CASE_TIME_OUT) + }) + + /* + * @tc.number: Acts_AppRecovery_0700 + * @tc.name: Fault recovery of multi-Ability application + * @tc.desc: If the restart recovery status is not set, the Ability application pre-failure state will not be + * restored after the application exits abnormally and restarts. + */ + it('Acts_AppRecovery_0700',0, async function (done) { + let subscriber; + let flag = false; + console.info("Acts_AppRecovery_0700====> start") + commonEvent.createSubscriber(ACTS_AppRecovery).then(async (data) => { + console.debug("Acts_AppRecovery_0700====> Create Subscribe"); + subscriber = data; + commonEvent.subscribe(subscriber, subscribeCallBack); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoveryrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0700_once" + },(err)=>{ + console.debug("Acts_AppRecovery_0700====> startAbility err:"+JSON.stringify(err)); + expect(err.code).assertEqual(0); + }) + }) + + function subscribeCallBack(err, data) { + console.debug("Acts_AppRecovery_0700====> subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_First") { + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + setTimeout(()=>{ + commonEvent.subscribe(subscriber, subscribeCallBackSecond); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoveryrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0700_twice" + }, (err) => { + console.debug("Acts_AppRecovery_0700====> second startAbility err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + }) + },800) + } + } + + function subscribeCallBackSecond(err, data) { + console.debug("Acts_AppRecovery_0700====> second subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_Second") { + flag=true; + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + + function unSubscribeCallback() { + setTimeout(() => { + console.debug("Acts_AppRecovery_0700====> unSubscribeCallback"); + done(); + }, 800); + } + + setTimeout(()=>{ + if(flag==false){ + expect().assertFail(); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + },CASE_TIME_OUT) + }) + + /* + * @tc.number: Acts_AppRecovery_0800 + * @tc.name: Fault recovery of multi-Ability application + * @tc.desc: If the restart recovery status is not set, the Ability application pre-failure state will not be + * restored after the application exits abnormally and restarts. + */ + it('Acts_AppRecovery_0800',0, async function (done) { + let subscriber; + let flag = false; + let countFirst = 0; + let countSecond = 0; + console.info("Acts_AppRecovery_0800====> start") + commonEvent.createSubscriber(ACTS_AppRecovery).then(async (data) => { + console.debug("Acts_AppRecovery_0800====> Create Subscribe"); + subscriber = data; + commonEvent.subscribe(subscriber, subscribeCallBack); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoverysrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0800_once" + },(err)=>{ + console.debug("Acts_AppRecovery_0800====> startAbility err:"+JSON.stringify(err)); + expect(err.code).assertEqual(0); + }) + }) + + function subscribeCallBack(err, data) { + console.debug("Acts_AppRecovery_0800====> subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_First") { + countFirst++; + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + if (countFirst < 2) { + return; + } + setTimeout(() => { + commonEvent.subscribe(subscriber, subscribeCallBackSecond); + globalThis.abilityContext.startAbility( + { + bundleName: "com.example.apprecoverysrely", + abilityName: "EntryAbility", + action: "Acts_AppRecovery_0800_twice" + }, + (err) => { + console.debug("Acts_AppRecovery_0800====> second startAbility err:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); + } + ); + }, 800); + } + } + + function subscribeCallBackSecond(err, data) { + console.debug("Acts_AppRecovery_0800====> second subscribeCallBack data:" + JSON.stringify(data)); + if(data.event == "ACTS_AppRecovery_Second") { + countSecond++; + flag=true; + if (data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"] == undefined) { + expect(true).assertTrue(); + } else { + expect(data.parameters.message["ohos.aafwk.param.AbilityRecoveryRestart"]).assertFalse(); + } + if (countSecond < 2) { + return; + } + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + + function unSubscribeCallback() { + setTimeout(() => { + console.debug("Acts_AppRecovery_0800====> unSubscribeCallback"); + done(); + }, 800); + } + + setTimeout(()=>{ + if(flag==false){ + expect().assertFail(); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + },CASE_TIME_OUT) + }) + + }) +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/test/List.test.ets b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb2e22661cde4c6c3e986a6718061d089e25fcd5 --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/testability/TestAbility.ets b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/testability/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..e35e89b89108c421311940ca5bc74d853b942c77 --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog' +import Ability from '@ohos.app.ability.UIAbility' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' +import Window from '@ohos.window' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + globalThis.abilityContext = this.context; + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: Window.WindowStage) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/testability/pages/Index.ets b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..431674fc5573a62cfd4d76547115834080634060 --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..1a6fe3a85d02631857806c78ce19b460a510b137 --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/module.json b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/module.json new file mode 100644 index 0000000000000000000000000000000000000000..272957d369303c76a818b3c89dfa072b6ecc0774 --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/module.json @@ -0,0 +1,45 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND" + }, + { + "name": "ohos.permission.MANAGE_MISSIONS" + } + ] + } +} diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/element/color.json b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/element/string.json b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/media/icon.png b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/profile/test_pages.json b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b7e7343cacb32ce982a45e76daad86e435e054fe --- /dev/null +++ b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/signature/openharmony_sx.p7b b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..e2fb0d83f985c21058e76b2bba4274f66f3edbab Binary files /dev/null and b/ability/ability_runtime/apprecovery/ActsAppRecoveryTestCaller/signature/openharmony_sx.p7b differ diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/AppScope/app.json b/ability/ability_runtime/apprecovery/AppRecoveryRely/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..4bb1b57b2fae1bf75a62182bb1ad0b6dcbb78784 --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/AppScope/app.json @@ -0,0 +1,19 @@ +{ + "app": { + "bundleName": "com.example.apprecoveryrely", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "keepAlive" : true, + "singleUser": true, + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/AppScope/resources/base/element/string.json b/ability/ability_runtime/apprecovery/AppRecoveryRely/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9311965cac8e15b8001612d094a8880fb5734add --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AppRecoveryRely" + } + ] +} diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/apprecovery/AppRecoveryRely/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/apprecovery/AppRecoveryRely/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/BUILD.gn b/ability/ability_runtime/apprecovery/AppRecoveryRely/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8883579348af26f8ae54854796fb997693973eaa --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_hap_assist_suite("AppRecoveryRely") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":apprecoveryrely_js_assets", + ":apprecoveryrely_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "AppRecoveryRely" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("apprecoveryrely_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("apprecoveryrely_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("apprecoveryrely_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":apprecoveryrely_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/ets/app/MyAbilityStage.ets b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/ets/app/MyAbilityStage.ets new file mode 100644 index 0000000000000000000000000000000000000000..24519dfb74c6da66587156bc132a930348583fad --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/ets/app/MyAbilityStage.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from '@ohos.app.ability.AbilityStage'; +import appRecovery from '@ohos.app.ability.appRecovery'; + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("Maple Create"); + // global switch for appRecovery function in current package + appRecovery.enableAppRecovery(); + } +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/ets/entryability/EntryAbility.ts b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..57ac0e16b143ac843818c446d95655f97745ebd9 --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog' +import Ability from '@ohos.app.ability.UIAbility' +import Window from '@ohos.window' +import commonEvent from '@ohos.commonEvent' +import appRecovery from '@ohos.app.ability.appRecovery' +import AbilityConstant from '@ohos.app.ability.AbilityConstant' +let message; +let commonEventData={ + parameters:{ + message:message, + } +} + +let strAction = ""; + +export default class EntryAbility extends Ability { + onCreate(want, launchParam) { + globalThis.context = this.context; + strAction = want.action; + console.log(strAction + "Rely====> want:" + JSON.stringify(want)); + console.log(strAction + "Rely====> launchParam:" + JSON.stringify(launchParam)); + commonEventData.parameters.message = want.parameters; + } + + onDestroy() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: Window.WindowStage) { + // Main window is created, set main page for this ability + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + + // 第一次启动设置项目 + if (strAction == "Acts_AppRecovery_0100_once" || strAction == "Acts_AppRecovery_0300_once" || + strAction == "Acts_AppRecovery_0700_once" || strAction == "Acts_AppRecovery_0900_once" || + strAction == "Acts_AppRecovery_1100_once") { + // 是否包存状态 + if (strAction == "Acts_AppRecovery_0100_once" || strAction == "Acts_AppRecovery_0300_once" || + strAction == "Acts_AppRecovery_1100_once") { + appRecovery.saveAppState(this.context); + console.log(strAction + "Rely====> saveAppState"); + } else { + console.log(strAction + "Rely====> not saveAppState"); + } + // 回复ACTS_AppRecovery_First消息 + setTimeout(() => { + commonEvent.publish("ACTS_AppRecovery_First",commonEventData,(err)=>{ + console.log(strAction + "Rely====> publish err:" + JSON.stringify(err)); + // 是否退出 + if (strAction == "Acts_AppRecovery_0100_once" || + strAction == "Acts_AppRecovery_0700_once") { + setTimeout(()=>{ + globalThis.context.terminateSelf().then(() => { + console.info(strAction + "Rely====> terminateSelf end"); + }).catch((err) => { + console.info(strAction + "Rely====> terminateSelf err:" + JSON.stringify(err)); + }); + }, 50) + } + }) + }, 200); + } + + // 第二次启动设置项目 + if (strAction == "Acts_AppRecovery_0100_twice" || strAction == "Acts_AppRecovery_0300_twice" || + strAction == "Acts_AppRecovery_0700_twice" || strAction == "Acts_AppRecovery_0900_twice" || + strAction == "Acts_AppRecovery_1100_twice") { + commonEvent.publish("ACTS_AppRecovery_Second", commonEventData, (err) => { + console.log(strAction + "Rely====> second publish err:" + JSON.stringify(err)); + setTimeout(()=>{ + globalThis.context.terminateSelf().then(() => { + console.info(strAction + "Rely====> terminateSelf end"); + }).catch((err) => { + console.info(strAction + "Rely====> terminateSelf err:" + JSON.stringify(err)); + }); + }, 50) + }) + } + } + + onBackground() { + // Ability has back to background + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } + + onSaveState(reason, wantParam: {[key:string]: any}) { + console.log(strAction + "RelyonSaveStage====> wantParam:" + JSON.stringify(wantParam)); + return AbilityConstant.OnSaveResult.RECOVERY_AGREE; + } +} diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/ets/pages/Index.ets b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad7ec009d021f1ebecb5a816a69e3c80cf654b63 --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/module.json b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..2e51e31ef31ced6fd0f15462eb940f29e382237b --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/module.json @@ -0,0 +1,39 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "srcEntrance": "./ets/app/MyAbilityStage.ets", + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntrance": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "visible": true, + "recoverable": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/element/color.json b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9e99b66dcb60d89ec3bad08c8c1515475ac2fe3a --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "AppRecoveryRely" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/en_US/element/string.json b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9e99b66dcb60d89ec3bad08c8c1515475ac2fe3a --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "AppRecoveryRely" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/zh_CN/element/string.json b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f53b2127579abfacf37c6af916c7dc42a37f3e6c --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoveryRely/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "AppRecoveryRely" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoveryRely/signature/openharmony_sx.p7b b/ability/ability_runtime/apprecovery/AppRecoveryRely/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..65481a97e77bc5e916f0af1323d342a3a438e0c5 Binary files /dev/null and b/ability/ability_runtime/apprecovery/AppRecoveryRely/signature/openharmony_sx.p7b differ diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/AppScope/app.json b/ability/ability_runtime/apprecovery/AppRecoverysRely/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..064895b60772901b0eb526c6bc222c4dd79f2a0d --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/AppScope/app.json @@ -0,0 +1,19 @@ +{ + "app": { + "bundleName": "com.example.apprecoverysrely", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "keepAlive" : true, + "singleUser": true, + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/AppScope/resources/base/element/string.json b/ability/ability_runtime/apprecovery/AppRecoverysRely/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..101d26acab7bbc32ff2d7a0e6627c4c1bebb22f5 --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AppRecoverysRely" + } + ] +} diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/apprecovery/AppRecoverysRely/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/apprecovery/AppRecoverysRely/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/BUILD.gn b/ability/ability_runtime/apprecovery/AppRecoverysRely/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fc1998248a40f1fedacade2d9d40400d1b94582c --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//test/xts/tools/build/suite.gni") + +ohos_hap_assist_suite("AppRecoverysRely") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":apprecoverysrely_js_assets", + ":apprecoverysrely_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "AppRecoverysRely" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("apprecoverysrely_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("apprecoverysrely_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("apprecoverysrely_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":apprecoverysrely_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/app/MyAbilityStage.ets b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/app/MyAbilityStage.ets new file mode 100644 index 0000000000000000000000000000000000000000..24519dfb74c6da66587156bc132a930348583fad --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/app/MyAbilityStage.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from '@ohos.app.ability.AbilityStage'; +import appRecovery from '@ohos.app.ability.appRecovery'; + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("Maple Create"); + // global switch for appRecovery function in current package + appRecovery.enableAppRecovery(); + } +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/entryability/EntryAbility.ts b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..7664132f4c9f1fdf4c09778148a4185b9f914c8e --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog' +import Ability from '@ohos.app.ability.UIAbility' +import Window from '@ohos.window' +import commonEvent from '@ohos.commonEvent' +import appRecovery from '@ohos.app.ability.appRecovery' +import AbilityConstant from '@ohos.app.ability.AbilityConstant' +let message; +let commonEventData={ + parameters:{ + message:message, + } +} + +let strAction = ""; + +export default class EntryAbility extends Ability { + onCreate(want, launchParam) { + globalThis.contextFirst = this.context; + strAction = want.action; + console.log(strAction + "Rely1====> want:" + JSON.stringify(want)); + console.log(strAction + "Rely1====> launchParam:" + JSON.stringify(launchParam)); + commonEventData.parameters.message = want.parameters; + } + + onDestroy() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: Window.WindowStage) { + // Main window is created, set main page for this ability + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + // 第一次启动 + if (strAction == "Acts_AppRecovery_0200_once" || strAction == "Acts_AppRecovery_0400_once" || + strAction == "Acts_AppRecovery_0800_once" || + strAction == "Acts_AppRecovery_1000_once" || strAction == "Acts_AppRecovery_1200_once") { + // 需要包存状态的用例 + if (strAction == "Acts_AppRecovery_0200_once" || + strAction == "Acts_AppRecovery_0400_once" || + strAction == "Acts_AppRecovery_1200_once") { + appRecovery.saveAppState(this.context); + console.log(strAction + "Rely1====> saveAppState"); + } else { + console.log(strAction + "Rely1====> not saveAppState"); + } + setTimeout(() => { + commonEvent.publish("ACTS_AppRecovery_First",commonEventData,(err)=>{ + console.log(strAction + "Rely1====> publish err:" + JSON.stringify(err)); + }) + }, 200); + } + // 第二次启动 + if (strAction == "Acts_AppRecovery_0200_twice" || strAction == "Acts_AppRecovery_0400_twice" || + strAction == "Acts_AppRecovery_0800_twice" || + strAction == "Acts_AppRecovery_1000_twice" || strAction == "Acts_AppRecovery_1200_twice") { + setTimeout(() => { + commonEvent.publish("ACTS_AppRecovery_Second", commonEventData, (err) => { + console.log(strAction + "Rely1====> second publish err:" + JSON.stringify(err)); + }) + }, 200); + } + // 拉起第二个Ability + this.context.startAbility({ + bundleName: "com.example.apprecoverysrely", + abilityName: "EntryAbilitySec", + action: strAction + },(err) => { + console.debug(strAction + "Rely1====> startAbility err:"+JSON.stringify(err)); + // 需要自己正常退出的用例 + if (strAction == "Acts_AppRecovery_0200_once" || strAction == "Acts_AppRecovery_0200_twice" || + strAction == "Acts_AppRecovery_0400_twice" || + strAction == "Acts_AppRecovery_0800_once" || strAction == "Acts_AppRecovery_0800_twice" || + strAction == "Acts_AppRecovery_1000_twice" || strAction == "Acts_AppRecovery_1200_twice") { + setTimeout(()=>{ + globalThis.contextFirst.terminateSelf().then(() => { + console.info(strAction + "Rely1====> terminateSelf end"); + }).catch((err) => { + console.info(strAction + "Rely1====> terminateSelf err:" + JSON.stringify(err)); + }); + }, 200) + } + }); + } + + onBackground() { + // Ability has back to background + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } + + onSaveState(reason, wantParam: {[key:string]: any}) { + console.log(strAction + "Rely1onSaveStage====> wantParam:" + JSON.stringify(wantParam)); + return AbilityConstant.OnSaveResult.RECOVERY_AGREE; + } +} diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/entryabilitysec/EntryAbilitySec.ts b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/entryabilitysec/EntryAbilitySec.ts new file mode 100644 index 0000000000000000000000000000000000000000..7cdc543560d80fb214aaf4dd2604c06b041a89e6 --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/entryabilitysec/EntryAbilitySec.ts @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog' +import Ability from '@ohos.app.ability.UIAbility' +import Window from '@ohos.window' +import commonEvent from '@ohos.commonEvent' +import appRecovery from '@ohos.app.ability.appRecovery' +import AbilityConstant from '@ohos.app.ability.AbilityConstant' +let message; +let commonEventData={ + parameters:{ + message:message, + } +} + +let strAction = ""; + +export default class EntryAbilitySec extends Ability { + onCreate(want, launchParam) { + globalThis.contextSecond = this.context; + strAction = want.action; + console.log(strAction + "Rely2====> want:" + JSON.stringify(want)); + console.log(strAction + "Rely2====> launchParam:" + JSON.stringify(launchParam)); + commonEventData.parameters.message = want.parameters; + } + + onDestroy() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: Window.WindowStage) { + // Main window is created, set main page for this ability + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index_sec', (err, data) => { + if (err.code) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + + if (strAction == "Acts_AppRecovery_0200_once" || strAction == "Acts_AppRecovery_0400_once" || + strAction == "Acts_AppRecovery_0800_once" || + strAction == "Acts_AppRecovery_1000_once" || strAction == "Acts_AppRecovery_1200_once") { + if (strAction == "Acts_AppRecovery_0200_once" || + strAction == "Acts_AppRecovery_0400_once" || + strAction == "Acts_AppRecovery_1200_once") { + appRecovery.saveAppState(this.context); + console.log(strAction + "Rely2====> saveAppState"); + } else { + console.log(strAction + "Rely2====> not saveAppState"); + } + setTimeout(() => { + commonEvent.publish("ACTS_AppRecovery_First",commonEventData,(err)=>{ + console.log(strAction + "Rely2====> publish err:" + JSON.stringify(err)); + }) + }, 200); + } + if (strAction == "Acts_AppRecovery_0200_twice" || strAction == "Acts_AppRecovery_0400_twice" || + strAction == "Acts_AppRecovery_0800_twice" || + strAction == "Acts_AppRecovery_1000_twice" || strAction == "Acts_AppRecovery_1200_twice") { + setTimeout(() => { + commonEvent.publish("ACTS_AppRecovery_Second", commonEventData, (err) => { + console.log(strAction + "Rely2====> second publish err:" + JSON.stringify(err)); + }) + }, 200); + } + + if (strAction == "Acts_AppRecovery_0200_once" || strAction == "Acts_AppRecovery_0200_twice" || + strAction == "Acts_AppRecovery_0400_twice" || + strAction == "Acts_AppRecovery_0800_once" || strAction == "Acts_AppRecovery_0800_twice" || + strAction == "Acts_AppRecovery_1000_twice" || strAction == "Acts_AppRecovery_1200_twice") { + setTimeout(()=>{ + globalThis.contextSecond.terminateSelf().then(() => { + console.info(strAction + "Rely2====> terminateSelf end"); + }).catch((err) => { + console.info(strAction + "Rely2====> terminateSelf err:" + JSON.stringify(err)); + }); + }, 300) + } + } + + onBackground() { + // Ability has back to background + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } + + onSaveState(reason, wantParam: {[key:string]: any}) { + console.log(strAction + "Rely2onSaveStage====> wantParam:" + JSON.stringify(wantParam)); + return AbilityConstant.OnSaveResult.RECOVERY_AGREE; + } +} diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/pages/Index.ets b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..0caca712dc3eaf652f08c0b4d6b9f54088b96d87 --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@Entry +@Component +struct Index { + @State message: string = 'Rely1 Abilitys' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/pages/Index_sec.ets b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/pages/Index_sec.ets new file mode 100644 index 0000000000000000000000000000000000000000..3f9bb44fa307d9a67d9f39d56f23dded5023c320 --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/ets/pages/Index_sec.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@Entry +@Component +struct IndexSec { + @State message: string = 'Rely2 Abilitys' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/module.json b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..2184774f7cda3ed0c82b59beb0af8dab9d5480e2 --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/module.json @@ -0,0 +1,50 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "srcEntrance": "./ets/app/MyAbilityStage.ets", + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntrance": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "visible": true, + "recoverable": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "EntryAbilitySec", + "srcEntrance": "./ets/entryabilitysec/EntryAbilitySec.ts", + "description": "$string:EntryAbilitySec_desc", + "icon": "$media:icon", + "label": "$string:EntryAbilitySec_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "recoverable": true, + "visible": true + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/element/color.json b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..423c984039a382f686f7e598bad3c397b30b373a --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "EntryAbilitySec_desc", + "value": "description" + }, + { + "name": "EntryAbilitySec_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..2fea8da0ae60f7cdf8e2b22822ce5c35584ae35c --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/Index", + "pages/Index_sec" + ] +} diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/en_US/element/string.json b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..423c984039a382f686f7e598bad3c397b30b373a --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "EntryAbilitySec_desc", + "value": "description" + }, + { + "name": "EntryAbilitySec_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/zh_CN/element/string.json b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6db0a80e95ce52288fa45fd5872205a8efd079a8 --- /dev/null +++ b/ability/ability_runtime/apprecovery/AppRecoverysRely/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "EntryAbilitySec_desc", + "value": "description" + }, + { + "name": "EntryAbilitySec_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/apprecovery/AppRecoverysRely/signature/openharmony_sx.p7b b/ability/ability_runtime/apprecovery/AppRecoverysRely/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..738f07f60001f580ec0ad8e973878f38b5197be4 Binary files /dev/null and b/ability/ability_runtime/apprecovery/AppRecoverysRely/signature/openharmony_sx.p7b differ diff --git a/ability/ability_runtime/apprecovery/BUILD.gn b/ability/ability_runtime/apprecovery/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..143feec3a9b6d537acd6977d9842fbd22e56e204 --- /dev/null +++ b/ability/ability_runtime/apprecovery/BUILD.gn @@ -0,0 +1,25 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +group("apprecovery") { + testonly = true + if (is_standard_system) { + deps = [ + "AppRecoveryRely:AppRecoveryRely", + "AppRecoverysRely:AppRecoverysRely", + "ActsAppRecoveryTestCaller:ActsAppRecoveryTestCaller", + ] + } +}