From 12285b410837a99c3541b39372d0ed23dd6bbf87 Mon Sep 17 00:00:00 2001 From: wangkailong Date: Wed, 19 Jul 2023 21:30:44 +0800 Subject: [PATCH] getgroupdir Signed-off-by: wangkailong Change-Id: I8f5f20481b5076ebf9d143bf744b06ff92cad56e --- .../src/main/ets/entryability/EntryAbility.ts | 14 +++ .../main/ets/entryability2/EntryAbility2.ts | 58 +++++++++++ .../entry/src/main/module.json | 8 ++ .../main/resources/base/element/string.json | 8 ++ .../main/resources/en_US/element/string.json | 8 ++ .../main/resources/zh_CN/element/string.json | 8 ++ .../signature/openharmony_sx.p7b | Bin 3537 -> 3551 bytes .../ets/test/ActsGetgroupdirTest.test.ets | 91 ++++++++++++++++++ .../entry/src/main/module.json | 6 ++ .../signature/openharmony_sx.p7b | Bin 3535 -> 3595 bytes 10 files changed, 201 insertions(+) create mode 100755 ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/ets/entryability2/EntryAbility2.ts diff --git a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/ets/entryability/EntryAbility.ts b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/ets/entryability/EntryAbility.ts index 5a2ad1b43..bc189a79f 100644 --- a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/ets/entryability/EntryAbility.ts +++ b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/ets/entryability/EntryAbility.ts @@ -15,6 +15,7 @@ import hilog from '@ohos.hilog'; import Ability from '@ohos.app.ability.UIAbility'; +import commonEvent from '@ohos.commonEventManager'; import Window from '@ohos.window'; export default class EntryAbility extends Ability { @@ -23,6 +24,19 @@ export default class EntryAbility extends Ability { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); + this.context.getGroupDir('context_hap1').then(data => { + let commonEventData = { + parameters:{ + res: data, + } + }; + console.error('getgroupdirhap2 getGroupDir ====> result data' + data); + commonEvent.publish('ACTS_GETGROUP1_EVENT', commonEventData, (err) => { + console.log('getgroupdirhap2 getGroupDir publish err:' + JSON.stringify(err)); + }); + }).catch((error) => { + console.error('getgroupdirhap2 getGroupDir ====> result err' + JSON.stringify(error)); + }); } onDestroy() { diff --git a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/ets/entryability2/EntryAbility2.ts b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/ets/entryability2/EntryAbility2.ts new file mode 100755 index 000000000..f0a1b3d57 --- /dev/null +++ b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/ets/entryability2/EntryAbility2.ts @@ -0,0 +1,58 @@ +/* + * 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 Ability from '@ohos.app.ability.UIAbility'; +import commonEvent from '@ohos.commonEvent'; + +function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); +} +export default class EntryAbility2 extends Ability { + onCreate(want, launchParam) { + this.context.getGroupDir('context_hap2').then(data => { + let commonEventData = { + parameters:{ + res: data, + } + }; + console.error('getgroupdirhap2 getGroupDir ====> result data' + data); + commonEvent.publish('ACTS_GETGROUP2_EVENT', commonEventData, (err) => { + console.log('getgroupdirhap2 getGroupDir publish err:' + JSON.stringify(err)); + }); + }).catch((error) => { + console.error('getgroupdirhap2 getGroupDir ====> result err' + JSON.stringify(error)); + }); + } + + onDestroy() { + console.log('[Demo] EntryAbility2 onDestroy'); + } + + onWindowStageCreate(windowStage) { + console.log('[Demo] EntryAbility2 onWindowStageCreate'); + windowStage.setUIContent(this.context, 'pages/Index', null); + } + + onWindowStageDestroy() { + console.log('[Demo] EntryAbility2 onWindowStageDestroy'); + } + + onForeground() { + console.log('[Demo] EntryAbility2 onForeground'); + } + + onBackground() { + console.log('[Demo] EntryAbility2 onBackground'); + } +}; diff --git a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/module.json b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/module.json index 0e288c05b..38d69be44 100644 --- a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/module.json +++ b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/module.json @@ -31,6 +31,14 @@ ] } ] + }, + { + "name": "EntryAbility2", + "srcEntrance": "./ets/entryability2/EntryAbility2.ts", + "description": "$string:EntryAbility2_desc", + "icon": "$media:icon", + "visible": true, + "label": "$string:EntryAbility2_label" } ] } diff --git a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/base/element/string.json index f94595515..8ba20c184 100644 --- a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/base/element/string.json +++ b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/base/element/string.json @@ -11,6 +11,14 @@ { "name": "EntryAbility_label", "value": "label" + }, + { + "name": "EntryAbility2_desc", + "value": "description" + }, + { + "name": "EntryAbility2_label", + "value": "label" } ] } \ No newline at end of file diff --git a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/en_US/element/string.json b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/en_US/element/string.json index f94595515..8ba20c184 100644 --- a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/en_US/element/string.json +++ b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/en_US/element/string.json @@ -11,6 +11,14 @@ { "name": "EntryAbility_label", "value": "label" + }, + { + "name": "EntryAbility2_desc", + "value": "description" + }, + { + "name": "EntryAbility2_label", + "value": "label" } ] } \ No newline at end of file diff --git a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/zh_CN/element/string.json b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/zh_CN/element/string.json index 597ecf95e..ab65ed60b 100644 --- a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/zh_CN/element/string.json +++ b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/entry/src/main/resources/zh_CN/element/string.json @@ -11,6 +11,14 @@ { "name": "EntryAbility_label", "value": "label" + }, + { + "name": "EntryAbility2_desc", + "value": "description" + }, + { + "name": "EntryAbility2_label", + "value": "label" } ] } \ No newline at end of file diff --git a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/signature/openharmony_sx.p7b b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/signature/openharmony_sx.p7b index 4db9702642cc927fde368c0cd32a908c91a4a759..643a9204b5855244b8fceaedd18cc391854b6120 100644 GIT binary patch delta 255 zcmca8eP7zapo#Z38>d#AN85K^Ms}tJO}uA-LMNCQ84Y<2xY;-p+B_IjnOT?^4VqYM z5egX>G_mHfG_huFbokD~r=ygdpI4GvQ4*h#SYWi-j5U&-3urQ<4bT{a?8ygMQz!r9 zajmyBG&Zs{v4}Fzha1GnVyMKT(6jcV{JiCfIUA&6!cSP`tn6n_pS0kBEvZ`QBMH6%UBu! delta 241 zcmcaFeNo!Mpo#Y^8>d#AN85K^Ms}tJO}zVnLc5q484Y<2xY;-p+B_IjnOT?^4VqZ< z5DFO=G_l6BG_gi+bokD)*^M=Voy*aniP09Q&mep9L$1`xyu7aUMh2FKMkba~2KsQF zoGgY)EDA5DYw#Xn>|vcc%`GHl|ANm?j`^>)mKQQte`m#*&Us>!0T&ww&`sxTS(uqv z+znir6d4x0Jaeh)_tBgC+oC42UfK9Pzsl*gDQAYp( diff --git a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/entry/src/main/ets/test/ActsGetgroupdirTest.test.ets b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/entry/src/main/ets/test/ActsGetgroupdirTest.test.ets index 231a61a7f..cb57ff34f 100644 --- a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/entry/src/main/ets/test/ActsGetgroupdirTest.test.ets +++ b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/entry/src/main/ets/test/ActsGetgroupdirTest.test.ets @@ -15,6 +15,11 @@ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import commonEvent from '@ohos.commonEventManager' + +var ACTS_GetGroupFunction = { + events: ['ACTS_GETGROUP1_EVENT', 'ACTS_GETGROUP2_EVENT'] +}; export default function ActsGetgroupdirTest() { describe('ActsGetgroupdirTest', function () { @@ -127,5 +132,91 @@ export default function ActsGetgroupdirTest() { done(); }) }) + + /* + * @tc.number AMS_getGroupDir_007 + * @tc.name getGroupDir + * @tc.desc Function test + * @tc.level 0 + */ + it('AMS_getGroupDir_007',0, async function (done) { + var subscriber; + var res; + console.log("start AMS_getGroupDir_007 =====>"); + commonEvent.createSubscriber(ACTS_GetGroupFunction).then(async (data) => { + console.debug('====>AMS_getGroupDir_007 Create Subscribe'); + subscriber = data; + + commonEvent.subscribe(subscriber, subscribeCallBack); + await globalThis.myContext.getGroupDir("context_hap1", (err, data) => { + res = data; + expect(err).assertNull(); + }) + globalThis.myContext.startAbility({ + bundleName: 'com.example.getgroupdirhap2', + abilityName: 'EntryAbility', + moduleName: 'entry', + },(err) => { + console.debug('====>AMS_getGroupDir_007 startAbility err:' + JSON.stringify(err)); + expect(err.code).assertEqual(0); + }) + }) + + function subscribeCallBack(err, data) { + console.debug('====>AMS_getGroupDir_007 subscribeCallBack data:' + JSON.stringify(data)); + if (data.event === 'ACTS_GETGROUP1_EVENT') { + expect(data.parameters.res).assertContain("/data/storage/el2/group"); + expect(data.parameters.res === res).assertFalse(); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + function unSubscribeCallback() { + console.debug('====>AMS_getGroupDir_007 unSubscribeCallback'); + done(); + } + }) + + /* + * @tc.number AMS_getGroupDir_008 + * @tc.name getGroupDir + * @tc.desc Function test + * @tc.level 0 + */ + it('AMS_getGroupDir_008',0, async function (done) { + var subscriber; + var res; + console.log("start AMS_getGroupDir_008 =====>"); + commonEvent.createSubscriber(ACTS_GetGroupFunction).then(async (data) => { + console.debug('====>AMS_getGroupDir_008 Create Subscribe'); + subscriber = data; + + commonEvent.subscribe(subscriber, subscribeCallBack); + await globalThis.myContext.getGroupDir("context_hap2", (err, data) => { + res = data; + expect(err).assertNull(); + }) + globalThis.myContext.startAbility({ + bundleName: 'com.example.getgroupdirhap2', + abilityName: 'EntryAbility2', + moduleName: 'entry', + },(err) => { + console.debug('====>AMS_getGroupDir_008 startAbility err:' + JSON.stringify(err)); + expect(err.code).assertEqual(0); + }) + }) + + function subscribeCallBack(err, data) { + console.debug('====>AMS_getGroupDir_008 subscribeCallBack data:' + JSON.stringify(data)); + if (data.event === 'ACTS_GETGROUP2_EVENT') { + expect(data.parameters.res).assertContain("/data/storage/el2/group"); + expect(data.parameters.res).assertEqual(res); + commonEvent.unsubscribe(subscriber, unSubscribeCallback); + } + } + function unSubscribeCallback() { + console.debug('====>AMS_getGroupDir_008 unSubscribeCallback'); + done(); + } + }) }) } \ No newline at end of file diff --git a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/entry/src/main/module.json b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/entry/src/main/module.json index 7b7b47f86..eae6a1541 100644 --- a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/entry/src/main/module.json +++ b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/entry/src/main/module.json @@ -42,6 +42,12 @@ "startWindowIcon": "$media:icon", "startWindowBackground": "$color:start_window_background" } + ], + "requestPermissions": [ + { + "name":"ohos.permission.START_ABILITIES_FROM_BACKGROUND", + "reason":"need use ohos.permission.START_ABILITIES_FROM_BACKGROUND" + } ] } } \ No newline at end of file diff --git a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/signature/openharmony_sx.p7b b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/signature/openharmony_sx.p7b index 5540c87c1c77d802a1200242f0fbb76c8f5a0bde..2c97bd00145bdedd2970bfc1342d78b2792fe228 100644 GIT binary patch delta 323 zcmX>v-7Vu_(8R~i#;Mij(e|B}k)3Hl6Ymd$Cf+YhjEsi72Hb3%32h#Xsmv@)j0R1t zD-jAA7c{ZXVrgQXw$b4WOO%dMa(-S(YDGzWMq+`HQf#e`QetvWv65A_QesX{etBw& zE`%Sgl%J7btXGg)l$%*xoSC1e7aZak6cX>~Mr)qCOeN9XJr4Y=4ifZjZ3%figW;%4B&q#(CsZgWH5u9IPbX_G%~3;6O{ z;Ai?q3-zt6E6ymsD%P3Hq~O_f$Zax*?-c&EFF6+&zu57RKP#j#^K1M1ptH6w0~xNG F000Y7Z{Yv{ delta 263 zcmeB{IWO&C(8PP1jZ>@5qwPB{BRkWACf+?jp&d+&jE1}h+-#f)Z61uN%q&cd22HHl z2!)Ibnpk64nph(?I(%V~iLKR9N=(ivRco~S&Mw#6AI|S#S6m;^bLAPI?$-H63k!SC zb`*O)TW`R{#sPHbIa?NHCKe9^Hzq}fmDz6f2RE->p?K)Px5b@bSSwC6Nq4<(FyYEP vx~6sY`T(Gk&GJ(ZiMaJR7pXcj+>w?M