提交 12285b41 编写于 作者: W wangkailong

getgroupdir

Signed-off-by: Nwangkailong <wangkailong6@huawei.com>
Change-Id: I8f5f20481b5076ebf9d143bf744b06ff92cad56e
上级 6582acfa
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Ability from '@ohos.app.ability.UIAbility'; import Ability from '@ohos.app.ability.UIAbility';
import commonEvent from '@ohos.commonEventManager';
import Window from '@ohos.window'; import Window from '@ohos.window';
export default class EntryAbility extends Ability { export default class EntryAbility extends Ability {
...@@ -23,6 +24,19 @@ 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', 'Ability onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); 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() { onDestroy() {
......
/*
* 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');
}
};
...@@ -31,6 +31,14 @@ ...@@ -31,6 +31,14 @@
] ]
} }
] ]
},
{
"name": "EntryAbility2",
"srcEntrance": "./ets/entryability2/EntryAbility2.ts",
"description": "$string:EntryAbility2_desc",
"icon": "$media:icon",
"visible": true,
"label": "$string:EntryAbility2_label"
} }
] ]
} }
......
...@@ -11,6 +11,14 @@ ...@@ -11,6 +11,14 @@
{ {
"name": "EntryAbility_label", "name": "EntryAbility_label",
"value": "label" "value": "label"
},
{
"name": "EntryAbility2_desc",
"value": "description"
},
{
"name": "EntryAbility2_label",
"value": "label"
} }
] ]
} }
\ No newline at end of file
...@@ -11,6 +11,14 @@ ...@@ -11,6 +11,14 @@
{ {
"name": "EntryAbility_label", "name": "EntryAbility_label",
"value": "label" "value": "label"
},
{
"name": "EntryAbility2_desc",
"value": "description"
},
{
"name": "EntryAbility2_label",
"value": "label"
} }
] ]
} }
\ No newline at end of file
...@@ -11,6 +11,14 @@ ...@@ -11,6 +11,14 @@
{ {
"name": "EntryAbility_label", "name": "EntryAbility_label",
"value": "label" "value": "label"
},
{
"name": "EntryAbility2_desc",
"value": "description"
},
{
"name": "EntryAbility2_label",
"value": "label"
} }
] ]
} }
\ No newline at end of file
...@@ -15,6 +15,11 @@ ...@@ -15,6 +15,11 @@
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' 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() { export default function ActsGetgroupdirTest() {
describe('ActsGetgroupdirTest', function () { describe('ActsGetgroupdirTest', function () {
...@@ -127,5 +132,91 @@ export default function ActsGetgroupdirTest() { ...@@ -127,5 +132,91 @@ export default function ActsGetgroupdirTest() {
done(); 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
...@@ -42,6 +42,12 @@ ...@@ -42,6 +42,12 @@
"startWindowIcon": "$media:icon", "startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background" "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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册