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 5a2ad1b43fc919610df43f64ff4f8e01b48a0d29..bc189a79fd9e71de1fb5685d8d086788caa9b796 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 0000000000000000000000000000000000000000..f0a1b3d57aeff79f288964af977311a513f43680 --- /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 0e288c05b41ef026b9f802f6c848bd5301ebc785..38d69be4490b0d4c51f56f25d50902925939f043 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 f94595515a99e0c828807e243494f57f09251930..8ba20c18482a6ba8a9e4e664f58332b25e508acc 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 f94595515a99e0c828807e243494f57f09251930..8ba20c18482a6ba8a9e4e664f58332b25e508acc 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 597ecf95e61d7e30367c22fe2f8638008361b044..ab65ed60b7ea8366729368f80de7d5e693c3c499 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 Binary files a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/signature/openharmony_sx.p7b and b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirhap/signature/openharmony_sx.p7b differ 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 231a61a7f4927c27a877e881a0910bdd8f8d1ae9..cb57ff34f1a6b3a616a82c19ca3b6402f53fd69a 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 7b7b47f86f34c4ff8ee78eab271c777fe0014e63..eae6a1541b747191d647f3f9a91fbfbab221b749 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 Binary files a/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/signature/openharmony_sx.p7b and b/ability/ability_runtime/stage/actsgetgroupdirtest/actsgetgroupdirtest/signature/openharmony_sx.p7b differ