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

!9697 自定义操作Extension测试提交

Merge pull request !9697 from xinking129/master
......@@ -25,6 +25,7 @@ group("ability_runtime") {
"actsabilitydelegatorcase:ActsAbilityDelegatorCaseTest",
"actsabilitymanageretstest:ActsAbilityManagerEtsTest",
"actsabilityusertest:ActsAbilityuserTest",
"actsactionextensionability:actsactionextensionability",
"actscalldataabilitytest:ActsCallDataAbilityTest",
"actscalltest:actscalltest",
"actscrosscall:actscrosscall",
......
# 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("actsactionextensionability") {
testonly = true
if (is_standard_system) {
deps = [
"actsactionextensionabilityotherrely:ActsActionExtensionAbilityOtherRely",
"actsactionextensionabilityself:ActsActionExtensionAbilitySelfModule",
"actsactionextensionabilityself:ActsActionExtensionAbilitySelfRely",
"actsactionextensionabilitytest:ActsActionExtensionAbilityTest",
]
}
}
{
"app": {
"bundleName": "com.example.actsactionextensionabilityrely",
"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
}
}
}
# 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("ActsActionExtensionAbilityOtherRely") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":actsactionextensionabilityotherrely_js_assets",
":actsactionextensionabilityotherrely_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsActionExtensionAbilityOtherRely"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("actsactionextensionabilityotherrely_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("actsactionextensionabilityotherrely_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("actsactionextensionabilityotherrely_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":actsactionextensionabilityotherrely_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
/*
* 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 ActionExtensionAbility from '@ohos.app.ability.ActionExtensionAbility';
export default class UiExtAbility extends ActionExtensionAbility {
onCreate() {
console.info('=======>UIExtAbility onCreate======>');
}
onSessionCreate(want, session) {
console.log(`want: ${JSON.stringify(want)}}`);
let storage: LocalStorage = new LocalStorage({
'session': session
});
session.loadContent('pages/Page', storage);
console.info('=======>UIExtAbility onSessionCreate======>');
}
onSessionDestroy(session) {
console.log('onSessionDestroy');
}
onDestroy() {
console.info('=======>UIExtensionAbility onDestroy ======>');
}
onForeground() {
// Ability has brought to foreground
console.log('=====> UIExtAbility onForeground =====> ');
}
};
/*
* 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 ActionExtensionAbility from '@ohos.app.ability.ActionExtensionAbility';
import commonEventManager from '@ohos.commonEventManager';
let count = 0;
const TIME_OUT = 500;
export default class ActsActionExtensionAbility extends ActionExtensionAbility {
storage: LocalStorage;
message: string;
onCreate() {
console.log('====>ActsActionExtensionAbility onCreate called');
count++;
}
onForeground() {
console.log('====>ActsActionExtensionAbility onForeground called');
count++;
let options = {
parameters: {
'count': count
}
};
commonEventManager.publish('ACTS_TEST_FOREGROUND', options, function () {});
}
onBackground() {
console.log('====>ActsActionExtensionAbility onBackground called');
count++;
commonEventManager.publish('ACTS_TEST_BACKGROUND', function () {});
setTimeout(() => {
globalThis.session.terminateSelf();
}, TIME_OUT);
}
onSessionCreate(want, session) {
console.log('====>ActsActionExtensionAbility onSessionCreate called');
count++;
this.message = want.parameters.shareMessages;
this.storage = new LocalStorage(
{
'session': session,
'messages': this.message
});
session.loadContent('pages/PageThree', this.storage);
globalThis.session = session;
}
onDestroy() {
console.log('====>ActsActionExtensionAbility onDestroy called');
count++;
let options = {
parameters: {
'count': count
}
};
commonEventManager.publish('ACTS_TEST_DESTROY', options, function () {});
}
onSessionDestroy(session) {
console.log('====>ActsActionExtensionAbility onSessionDestroy called');
count++;
}
}
/*
* 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import type window from '@ohos.window';
export default class CalledAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onCreate');
console.log('=====> second app CalledAbility bas been created =====>');
if (want.action === 'AsyncCallback_0200') {
this.context.terminateSelfWithResult({
resultCode: 0,
want: {
parameters: {
action: 'ACTION'
}
}
}, (err) => {
console.log('=====> AsyncCallback_0200 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code);
});
}
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/PageTwo', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
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.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onForeground');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onBackground');
}
}
/*
* 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
console.info('====>another EntryAbility');
if (want.action === 'ActionExtensionAbility_0100') {
this.context.startAbility({
bundleName: 'com.example.actsactionextensionabilityrely',
abilityName: 'ActsActionExtensionAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
}).catch((err)=>{
console.info('====>ActionExtensionAbility_0100 err:' + JSON.stringify(err));
});
}
if (want.action === 'AsyncCallback_0200') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0200':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0200',
bundleName: 'com.example.actsactionextensionabilityrely',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'AsyncCallback_0300') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0300':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0300',
bundleName: 'com.example.actsactionextensionabilityrely',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Promise_0200') {
console.info("====>EntryAbility want.action == 'Promise_0200':");
AppStorage.SetOrCreate('want', {
action: 'Promise_0200',
bundleName: 'com.example.actsactionextensionabilityrely',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Promise_0300') {
console.info("====>EntryAbility want.action == 'Promise_0300':");
AppStorage.SetOrCreate('want', {
action: 'Promise_0300',
bundleName: 'com.example.actsactionextensionabilityrely',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
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.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
}
/*
* 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 Want from '@ohos.app.ability.Want';
@Entry
@Component
struct Index {
@State message: string = 'Second application'
@StorageLink('want') want: Want = {
action: "AsyncCallback_0200",
bundleName: 'com.example.actsactionextensionabilityrely',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
UIExtensionComponent(this.want)
.size({width:'100%',height:'100'})
.backgroundColor(Color.Blue)
.border({width:5,color:Color.Red})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* 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.
*/
var storage = LocalStorage.GetShared()
@Entry(storage)
@Component
struct Page {
@State message: string = 'UIExtAbility'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* 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.
*/
var storage = LocalStorage.GetShared();
@Entry(storage)
@Component
struct PageThree {
build() {
Row() {
Column() {
Text('acton')
.fontSize(24)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
.backgroundColor('#e0ffff')
.borderRadius(16)
}
}
\ No newline at end of file
/*
* 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 PageTwo {
@State message: string = 'Second application'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "entry_assist",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"default"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ts",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
},
{
"name": "CalledAbility",
"srcEntry": "./ets/calledability/CalledAbility.ts",
"description": "$string:CalledAbility_desc",
"visible": true,
"icon": "$media:icon",
"label": "$string:CalledAbility_label",
"launchType": "standard",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background"
}
],
"extensionAbilities": [
{
"name": "UIExtAbility",
"icon": "$media:icon",
"description": "UIExtAbility",
"type": "action",
"visible": true,
"srcEntrance": "./ets/UIExtensionAbility/UIExtAbility.ts"
},
{
"name": "ActsActionExtensionAbility",
"icon": "$media:icon",
"description": "ActsActionExtensionAbility",
"type": "action",
"visible": true,
"srcEntrance": "./ets/actionextensionability/ActsActionExtensionAbility.ts"
}
],
"requestPermissions": [
{
"name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
},
{
"name": "ohos.permission.START_INVISIBLE_ABILITY"
}
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.example.actsactionextensionabilitytest",
"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
}
}
}
# 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("ActsActionExtensionAbilitySelfRely") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":actsactionextensionabilityselfrely_js_assets",
":actsactionextensionabilityselfrely_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsActionExtensionAbilitySelfRely"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("actsactionextensionabilityselfrely_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("actsactionextensionabilityselfrely_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("actsactionextensionabilityselfrely_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":actsactionextensionabilityselfrely_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
ohos_hap_assist_suite("ActsActionExtensionAbilitySelfModule") {
hap_profile = "feature/src/main/module.json"
js_build_mode = "debug"
deps = [
":actsactionextensionabilityselfmodule_js_assets",
":actsactionextensionabilityselfmodule_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsActionExtensionAbilitySelfModule"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("actsactionextensionabilityselfmodule_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("actsactionextensionabilityselfmodule_js_assets") {
source_dir = "feature/src/main/ets"
}
ohos_resources("actsactionextensionabilityselfmodule_resources") {
sources = [ "feature/src/main/resources" ]
deps = [ ":actsactionextensionabilityselfmodule_app_profile" ]
hap_profile = "feature/src/main/module.json"
}
/*
* 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 ActionExtensionAbility from '@ohos.app.ability.ActionExtensionAbility';
import wantConstant from '@ohos.app.ability.wantConstant';
import commonEvent from '@ohos.commonEventManager';
import hilog from '@ohos.hilog';
export default class UiExtAbility extends ActionExtensionAbility {
onCreate() {
hilog.info(0x0000, 'testTag', 'UIExtAbility onCreate want: %{public}s');
console.info('=======>UIExtAbility onCreate======>');
}
onSessionCreate(want, session) {
console.log(`want: ${JSON.stringify(want)}}`);
let storage: LocalStorage = new LocalStorage({
'session': session
});
session.loadContent('pages/Page', storage);
console.info('=======>UIExtAbility onSessionCreate======>');
if (want.action === 'Acts_ActionExtensionAbility_1000') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1000======>');
this.context.startAbility({
action: 'Acts_ActionExtensionAbility_1000',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error) => {
console.info('=======>Acts_ActionExtensionAbility_1000 error.code ======>' + error.code);
let commonEventData = {
parameters: {
num: error.code
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_1000 publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'Acts_ActionExtensionAbility_1100') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1100======>');
this.context.startAbility({
action: 'Acts_ActionExtensionAbility_1100',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}).then(() => {
console.info('=======>Acts_ActionExtensionAbility_1100 UIExtAbility startAbility success ======>');
let commonEventData = {
parameters: {
str: 'success'
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_1100 publish err:' + JSON.stringify(err));
});
}).catch((err) => {
console.debug('====>Acts_ActionExtensionAbility_1100 UIExtAbility startAbility err:' + JSON.stringify(err));
});
}
if (want.action === 'Acts_ActionExtensionAbility_1200') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1200======>');
this.context.startAbility({
action: 'Acts_ActionExtensionAbility_1200',
bundleName: 'xxx.xxxx.xxxxx',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error) => {
console.info('=======>Acts_ActionExtensionAbility_1200 error.code ======>' + error.code);
let commonEventData = {
parameters: {
num: error.code
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_1200 publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'Acts_ActionExtensionAbility_1300') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1300======>');
this.context.startAbilityForResult({
action: 'Acts_ActionExtensionAbility_1300',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error, data) => {
console.info('=======>Acts_ActionExtensionAbility_1300 error.code ======>' + error.code);
console.info('=======>Acts_ActionExtensionAbility_1300 data.resultCode ======>' + data.resultCode);
console.info('=======>Acts_ActionExtensionAbility_1300 data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
num: error.code,
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_1300 publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'Acts_ActionExtensionAbility_1400') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1300======>');
this.context.startAbilityForResult({
action: 'Acts_ActionExtensionAbility_1400',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}).then((data) => {
console.info('=======>Acts_ActionExtensionAbility_1400 data.resultCode ======>' + data.resultCode);
console.info('=======>Acts_ActionExtensionAbility_1400 data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_1400 publish err:' + JSON.stringify(err));
});
}).catch((error) => {
console.info('=======>Acts_ActionExtensionAbility_1400 error.code ======>' + error.code);
});
}
if (want.action === 'Acts_ActionExtensionAbility_1500') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1500======>');
this.context.startAbilityForResult({
action: 'Acts_ActionExtensionAbility_1500',
bundleName: 'xxx.xxxxxxx.xxx',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error, data) => {
console.info('=======>Acts_ActionExtensionAbility_1500 first from own error.code ======>' + error.code);
let commonEventData = {
parameters: {
num: error.code
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_1500 first publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'Acts_ActionExtensionAbility_1600') {
session.setReceiveDataCallback((data) => {
let options = {
parameters: {
'result': data
}
};
commonEvent.publish('setReceiveDataCallback', options, (err) => {
console.log('Acts_ActionExtensionAbility_1600');
});
});
}
if (want.action === 'Acts_ActionExtensionAbility_1800') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_1800======>');
this.context.startAbility({
action: 'Acts_ActionExtensionAbility_1800',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'ActsActionExtensionAbility'
}, (error, data) => {
console.info('=======>Acts_ActionExtensionAbility_1800 first from own error.code ======>' + error.code);
let commonEventData = {
parameters: {
num: error.code
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_1800 first publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'Acts_ActionExtensionAbility_context') {
let options = {
parameters: {
'context': this.context
}
};
commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => {
console.log('Acts_ActionExtensionAbility_context');
});
}
if (want.action === 'Acts_ActionExtensionAbility_2200') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2200======>');
console.info('Acts_ActionExtensionAbility_2200 resourceManager: ' + this.context.resourceManager);
let commonEventData = {
parameters: {
resourceManager: this.context.resourceManager
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_2200 first publish err:' + JSON.stringify(err));
});
}
if (want.action === 'Acts_ActionExtensionAbility_2300') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2300======>');
console.info('Acts_ActionExtensionAbility_2300 applicationInfo: ' + this.context.applicationInfo);
let applicationInfo = this.context.applicationInfo;
let commonEventData = {
parameters: {
name: applicationInfo.name,
description_length: applicationInfo.description.length,
descriptionId: applicationInfo.descriptionId,
label: applicationInfo.label,
labelId: applicationInfo.labelId,
icon: applicationInfo.icon,
iconId: applicationInfo.iconId,
codePath: typeof (applicationInfo.codePath)
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_2300 first publish err:' + JSON.stringify(err));
});
}
if (want.action === 'Acts_ActionExtensionAbility_2400') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2400======>');
let commonEventData = {
parameters: {
cacheDir: this.context.cacheDir
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_2400 first publish err:' + JSON.stringify(err));
});
}
if (want.action === 'Acts_ActionExtensionAbility_2500') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2500======>');
let commonEventData = {
parameters: {
tempDir: this.context.tempDir
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_2500 first publish err:' + JSON.stringify(err));
});
}
if (want.action === 'Acts_ActionExtensionAbility_2600') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2600======>');
let commonEventData = {
parameters: {
filesDir: this.context.filesDir
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_2600 first publish err:' + JSON.stringify(err));
});
}
if (want.action === 'Acts_ActionExtensionAbility_2700') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2700======>');
let commonEventData = {
parameters: {
databaseDir: this.context.databaseDir
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_2700 first publish err:' + JSON.stringify(err));
});
}
if (want.action === 'Acts_ActionExtensionAbility_2800') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2800======>');
let commonEventData = {
parameters: {
preferencesDir: this.context.preferencesDir
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_2800 first publish err:' + JSON.stringify(err));
});
}
if (want.action === 'Acts_ActionExtensionAbility_2900') {
console.info('=======>UIExtAbility onSessionCreate want.action == Acts_ActionExtensionAbility_2900======>');
let commonEventData = {
parameters: {
bundleCodeDir: this.context.bundleCodeDir
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Acts_ActionExtensionAbility_2900 first publish err:' + JSON.stringify(err));
});
}
if (want.action === 'Acts_ActionExtensionAbility_3000') {
let moduleContext = this.context.createModuleContext('entry');
let options = {
parameters: {
'bundleName': moduleContext.applicationInfo.name
}
};
commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => {
console.log('Acts_ActionExtensionAbility_context');
});
}
if (want.action === 'Acts_ActionExtensionAbility_3100') {
let moduleContext = this.context.createModuleContext('entry_test');
let options = {
parameters: {
'bundleName': moduleContext.applicationInfo.name
}
};
commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => {
console.log('Acts_ActionExtensionAbility_context');
});
}
if (want.action === 'Acts_ActionExtensionAbility_3200') {
let moduleContext;
try {
moduleContext = this.context.createModuleContext('entry_assist');
} catch {
console.log('createModuleContext err');
}
let options = {
parameters: {
'moduleContext': moduleContext
}
};
commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => {
console.log('Acts_ActionExtensionAbility_context');
});
}
if (want.action === 'Acts_ActionExtensionAbility_3300') {
let moduleContext;
try {
moduleContext = this.context.createModuleContext('abc');
} catch {
console.log('createModuleContext err');
}
let options = {
parameters: {
'moduleContext': moduleContext
}
};
commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => {
console.log('Acts_ActionExtensionAbility_context');
});
}
if (want.action === 'Acts_ActionExtensionAbility_3400') {
let moduleContext;
try {
moduleContext = this.context.createModuleContext(undefined);
} catch {
console.log('createModuleContext err');
}
let options = {
parameters: {
'moduleContext': moduleContext
}
};
commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => {
console.log('Acts_ActionExtensionAbility_context');
});
}
if (want.action === 'Acts_ActionExtensionAbility_3500') {
let applicationContext = this.context.getApplicationContext();
let options = {
parameters: {
'applicationContext': applicationContext
}
};
commonEvent.publish('ACTS_TEST_CONTEXT', options, (err) => {
console.log('Acts_ActionExtensionAbility_context');
});
}
}
onSessionDestroy(session) {
console.log('onSessionDestroy');
}
onDestroy() {
console.info('=======>UIExtensionAbility onDestroy ======>');
}
onForeground() {
console.log('=====> UIExtAbility onForeground =====> ');
}
};
/*
* 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 ActionExtensionAbility from '@ohos.app.ability.ActionExtensionAbility';
import commonEventManager from '@ohos.commonEventManager';
let count = 0;
const TIME_OUT = 500;
export default class ActsActionExtensionAbility extends ActionExtensionAbility {
storage: LocalStorage;
message: string;
onCreate() {
console.log('====>ActsActionExtensionAbility onCreate called');
count++;
}
onForeground() {
console.log('====>ActsActionExtensionAbility onForeground called');
count++;
let options = {
parameters: {
'count': count
}
};
commonEventManager.publish('ACTS_TEST_FOREGROUND', options, function () {});
}
onBackground() {
console.log('====>ActsActionExtensionAbility onBackground called');
count++;
commonEventManager.publish('ACTS_TEST_BACKGROUND', function () {});
setTimeout(() => {
globalThis.session.terminateSelf();
}, TIME_OUT);
}
onSessionCreate(want, session) {
console.log('====>ActsActionExtensionAbility onSessionCreate called');
count++;
this.message = want.parameters.shareMessages;
this.storage = new LocalStorage(
{
'session': session,
'messages': this.message
});
session.loadContent('pages/PageThree', this.storage);
globalThis.session = session;
}
onDestroy() {
console.log('====>ActsActionExtensionAbility onDestroy called');
count++;
let options = {
parameters: {
'count': count
}
};
commonEventManager.publish('ACTS_TEST_DESTROY', options, function () {});
}
onSessionDestroy(session) {
console.log('====>ActsActionExtensionAbility onSessionDestroy called');
count++;
}
}
/*
* 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import type window from '@ohos.window';
export default class CalledAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onCreate');
console.log('=====> first app CalledAbility =====>');
const TIMEOUT = 50;
globalThis.terminateCalledAbility = (str) => {
setTimeout(() => {
this.context.terminateSelf().then(() => {
console.info('====>terminateSelf' + JSON.stringify(str) + ' end');
}).catch((err) => {
console.info('====>terminateSelf ' + JSON.stringify(str) + ' err:' + JSON.stringify(err));
});
}, TIMEOUT);
};
if (want.action === 'Acts_ActionExtensionAbility_1000') {
this.context.terminateSelf();
}
if (want.action === 'Acts_ActionExtensionAbility_1100') {
this.context.terminateSelf();
}
if (want.action === 'Acts_ActionExtensionAbility_1300') {
this.context.terminateSelfWithResult({
resultCode: 0,
want: {
parameters: {
action: 'ACTION'
}
}
}, (err) => {
console.log('=====> Acts_ActionExtensionAbility_1300 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code);
});
}
if (want.action === 'Acts_ActionExtensionAbility_1400') {
this.context.terminateSelfWithResult({
resultCode: 0,
want: {
parameters: {
action: 'ACTION'
}
}
}, (err) => {
console.log('=====> Acts_ActionExtensionAbility_1400 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code);
});
}
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/PageTwo', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
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.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onForeground');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onBackground');
}
}
/*
* 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import type window from '@ohos.window';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
const TIMEOUT = 50;
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
globalThis.terminate = (str) => {
setTimeout(() => {
this.context.terminateSelf().then(() => {
console.info('====>terminateSelf' + JSON.stringify(str) + ' end');
}).catch((err) => {
console.info('====>terminateSelf ' + JSON.stringify(str) + ' err:' + JSON.stringify(err));
});
}, TIMEOUT);
};
if (want.action === 'Acts_ActionExtensionAbility_0100') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0100');
AppStorage.SetOrCreate('want', {
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'ActsActionExtensionAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_0300') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0300');
AppStorage.SetOrCreate('want', {
bundleName: 'com.example.actsactionextensionabilityrely',
abilityName: 'ActsActionExtensionAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_0400') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0400');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_0400',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'FeatureActionExtensionAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_0500') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0500');
AppStorage.SetOrCreate('want', {
bundleName: '',
abilityName: 'ActsActionExtensionAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_0600') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0600');
AppStorage.SetOrCreate('want', {
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: '',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_0700') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_0700');
AppStorage.SetOrCreate('want', {
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'ActsActionExtensionAbility',
});
}
if (want.action === 'Acts_ActionExtensionAbility_DEFAULT') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_DEFAULT');
AppStorage.SetOrCreate('want', {
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_1000') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1000');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_1000',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_1100') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1100');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_1100',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_1200') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1200');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_1200',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_1300') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1300');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_1300',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_1400') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1400');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_1400',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_1500') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1500');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_1500',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_1600') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1600');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_1600',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_1700') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1700');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_1700',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_1800') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_1800');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_1800',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_context') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_context');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_context',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_2200') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2200');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_2200',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_2300') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2300');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_2300',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_2400') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2400');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_2400',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_2500') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2500');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_2500',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_2600') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2600');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_2600',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_2700') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2700');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_2700',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_2800') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2800');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_2800',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_2900') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_2900');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_2900',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_3000') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3000');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_3000',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_3100') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3100');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_3100',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_3200') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3200');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_3200',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_3300') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3300');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_3300',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_3400') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3400');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_3400',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_3500') {
console.info('====>EntryAbility want.action == Acts_ActionExtensionAbility_3500');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_3500',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
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.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
}
/*
* 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import type window from '@ohos.window';
const CUMULATIVE = 2;
export default class OtherAbility extends UIAbility {
circulate: number = 0;
onCreate(want, launchParam) {
console.log('=====> OtherAbility onCreate =====>');
}
onDestroy() {
console.log('=====> OtherAbility onDestroy =====>');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.log('=====> OtherAbility onWindowStageCreate =====>');
windowStage.loadContent('pages/IndexTwo', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log('=====> OtherAbility onWindowStageDestroy =====>');
}
onForeground() {
console.log('=====> OtherAbility onForeground =====>');
this.circulate++;
console.log(`=====> OtherAbility circulate count: ${this.circulate}`);
if (this.circulate === CUMULATIVE) {
this.context.terminateSelfWithResult({
resultCode: 0,
want: {
parameters: {
action: 'ACTION'
}
}
}, (err) => {
console.log('=====> OtherAbility CalledAbilityCallBack terminateSelfWithResult =====>' + err.code);
});
}
}
onBackground() {
// Ability has back to background
console.log('=====> OtherAbility onBackground =====>');
}
}
/*
* 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 Want from '@ohos.app.ability.Want';
import commonEventManager from '@ohos.commonEventManager';
@Entry
@Component
struct Index {
@State message: string = 'First application';
@StorageLink('want') want: Want = {
action: 'AsyncCallback_0100',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'UIExtAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
};
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
UIExtensionComponent(this.want)
.size({width:'100%',height:'100'})
.backgroundColor(Color.Blue)
.border({width:5,color:Color.Red})
.onRemoteReady((proxy) => {
setTimeout(() => {
proxy.send({
name: {
test: 'actionExtensionTest'
}
});
}, 1000);
})
.onResult((data)=>{
var onResultEvent = 'ACTS_UIExtension_OnResult';
var options = {
parameters: {
'result': data
}
}
commonEventManager.publish(onResultEvent, options, (err) => {
console.log('ACTS_UIExtension_OnResult');
});
})
.onReceive((data)=>{
var onReceiveEvent = 'ACTS_UIExtension_OnReceive';
var options = {
parameters: {
'result': data
}
}
commonEventManager.publish(onReceiveEvent, options, (err) => {
console.log('ACTS_UIExtension_OnReceive');
});
})
.onError((err) => {
var options = {
parameters: {
'err': err
}
}
commonEventManager.publish('ACTS_TEST_START_ERR', options, function (){});
})
.onRelease((releaseCode) => {
var options = {
parameters: {
'releaseCode': releaseCode
}
}
commonEventManager.publish('ACTS_TEST_RELEASE', options, function (){});
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* 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 IndexTwo {
@State message: string = 'Other Ability!';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button('TerminateCallback0100')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.StartAbilityForResult_CallBack()
})
.margin({
top: 5
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* 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 Want from '@ohos.app.ability.Want';
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
import commonEventManager from '@ohos.commonEventManager';
const sleepTimeOne = 1000;
var storage = LocalStorage.GetShared();
@Entry(storage)
@Component
struct Page {
@State message: string = 'UIExtAbility';
@StorageLink('actionWant') want: Want = {
action: "Acts_ActionExtensionAbility_1700",
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'ActsActionExtensionAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
};
private session: UIExtensionContentSession = storage.get<UIExtensionContentSession>('session');
aboutToAppear() {
var appearEvent = 'ACTS_UIExtension_AboutToAppear';
var terminateSelfWithResultEvent = 'ACTS_UIExtension_TerminateSelfWithResult';
var sendDataEvent = 'ACTS_UIExtension_SendData';
var subscriber;
var subscribeInfo = {
events: [terminateSelfWithResultEvent, sendDataEvent]
};
commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log('createSubscriber data : ' + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log('SubscribeInfoCallback : ' + JSON.stringify(data));
if (data.event === terminateSelfWithResultEvent) {
this.session.terminateSelfWithResult({
'resultCode': 1,
'want': {
'action': 'ACTION'
}
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log('UnSubscribeInfoCallback : ' + JSON.stringify(data));
});
} else if (data.event === sendDataEvent) {
this.session.sendData({
name: {
test: 'actionExtensionTest'
}
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log('UnSubscribeInfoCallback : ' + JSON.stringify(data));
});
}
});
}).catch((error) => {
console.log('createSubscriber error : ' + JSON.stringify(error));
})
setTimeout(() => {
commonEventManager.publish(appearEvent, function (){});
}, sleepTimeOne);
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(30)
.fontWeight(FontWeight.Bold)
UIExtensionComponent(this.want)
.size({width:'100%',height:'100'})
.backgroundColor(Color.Blue)
.border({width:5,color:Color.Red})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* 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.
*/
var storage = LocalStorage.GetShared();
@Entry(storage)
@Component
struct Index3 {
build() {
Row() {
Column() {
Text('acton')
.fontSize(24)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
.backgroundColor('#e0ffff')
.borderRadius(16)
}
}
\ No newline at end of file
/*
* 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 PageTwo {
@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
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"default"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"metadata":[
{
"name":"test_metadata"
}
],
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ts",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
},
{
"name": "OtherAbility",
"srcEntry": "./ets/otherability/OtherAbility.ts",
"description": "$string:OtherAbility_desc",
"visible": true,
"icon": "$media:icon",
"label": "$string:OtherAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background"
},
{
"name": "CalledAbility",
"srcEntry": "./ets/calledability/CalledAbility.ts",
"description": "$string:CalledAbility_desc",
"visible": true,
"icon": "$media:icon",
"label": "$string:CalledAbility_label",
"launchType": "standard",
"exported": false,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background"
}
],
"extensionAbilities": [
{
"name": "UIExtAbility",
"icon": "$media:icon",
"description": "UIExtAbility",
"type": "action",
"visible": true,
"srcEntrance": "./ets/UIExtensionAbility/UIExtAbility.ts"
},
{
"name": "ActsActionExtensionAbility",
"icon": "$media:icon",
"description": "ActsActionExtensionAbility",
"type": "action",
"visible": true,
"srcEntrance": "./ets/actionextensionability/ActsActionExtensionAbility.ts"
}
],
"requestPermissions": [
{
"name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
}
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "OtherAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "OtherAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"src": [
"pages/Index",
"pages/Page",
"pages/PageTwo",
"pages/PageThree"
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "OtherAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "OtherAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
/*
* 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 ActionExtensionAbility from '@ohos.app.ability.ActionExtensionAbility';
import commonEventManager from '@ohos.commonEventManager';
export default class FeatureActionExtensionAbility extends ActionExtensionAbility {
storage: LocalStorage;
message: string;
onCreate() {
}
onForeground() {
console.log('====>FeatureActionExtensionAbility onForeground called');
}
onBackground() {
console.log('====>FeatureActionExtensionAbility onBackground called');
}
onSessionCreate(want, session) {
console.log('====>FeatureActionExtensionAbility onSessionCreate called');
commonEventManager.publish('ACTS_FEATURE_CREATE', function () {});
if (want.action === 'Acts_ActionExtensionAbility_0400') {
this.context.startAbility({
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'FeatureAbility',
action: 'Acts_ActionExtensionAbility_0400'
});
}
this.message = want.parameters.shareMessages;
this.storage = new LocalStorage(
{
'session': session,
'messages': this.message
});
session.loadContent('pages/Index2', this.storage);
}
onDestroy() {
console.log('====>FeatureActionExtensionAbility onDestroy called');
}
onSessionDestroy(session) {
console.log('====>FeatureActionExtensionAbility onSessionDestroy called');
}
}
/*
* 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import type window from '@ohos.window';
export default class FeatureAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
const TIMEOUT = 50;
globalThis.featureTerminate = (str) => {
setTimeout(() => {
this.context.terminateSelf().then(() => {
console.info('====>terminateSelf' + JSON.stringify(str) + ' end');
}).catch((err) => {
console.info('====>terminateSelf ' + JSON.stringify(str) + ' err:' + JSON.stringify(err));
});
}, TIMEOUT);
};
if (want.action === 'Acts_ActionExtensionAbility_0400') {
console.info('====>FeatureAbility want.action == Acts_ActionExtensionAbility_0400');
AppStorage.SetOrCreate('want', {
action: 'Acts_ActionExtensionAbility_0400',
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'FeatureActionExtensionAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
if (want.action === 'Acts_ActionExtensionAbility_0200') {
console.info('====>FeatureAbility want.action == Acts_ActionExtensionAbility_0200');
AppStorage.SetOrCreate('want', {
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'ActsActionExtensionAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
});
}
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
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.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
}
/*
* 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 Want from '@ohos.app.ability.Want';
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
@StorageLink('want') want: Want = {
bundleName: 'com.example.actsactionextensionabilitytest',
abilityName: 'ActsActionExtensionAbility',
parameters: {
'ability.want.params.uiExtensionType': 'action'
}
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
UIExtensionComponent(this.want).width('100%').height('35%')
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* 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.
*/
var storage = LocalStorage.GetShared();
@Entry(storage)
@Component
struct Index2 {
@State message: string = 'FeatureActionExtensionAbility';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "feature",
"type": "feature",
"description": "$string:module_desc",
"mainElement": "FeatureAbility",
"deviceTypes": [
"default"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "FeatureAbility",
"srcEntry": "./ets/featureability/FeatureAbility.ts",
"description": "$string:FeatureAbility_desc",
"icon": "$media:icon",
"label": "$string:FeatureAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"exported": true
}
],
"extensionAbilities": [
{
"name": "FeatureActionExtensionAbility",
"icon": "$media:icon",
"description": "FeatureActionExtensionAbility",
"type": "action",
"exported": true,
"srcEntrance": "./ets/actionextensionability/FeatureActionExtensionAbility.ts"
}
],
"requestPermissions": [
{
"name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
}
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "FeatureAbility_desc",
"value": "description"
},
{
"name": "FeatureAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "FeatureAbility_desc",
"value": "description"
},
{
"name": "FeatureAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "FeatureAbility_desc",
"value": "description"
},
{
"name": "FeatureAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.example.actsactionextensionabilitytest",
"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
}
}
}
# 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("ActsActionExtensionAbilityTest") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":actsactionextensionabilitytest_js_assets",
":actsactionextensionabilitytest_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsActionExtensionAbilityTest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("actsactionextensionabilitytest_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("actsactionextensionabilitytest_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("actsactionextensionabilitytest_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":actsactionextensionabilitytest_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for aceceshi Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"bundle-name": "com.example.actsactionextensionabilitytest",
"module-name": "entry_test",
"shell-timeout": "600000",
"testcase-timeout": 25000
},
"kits": [
{
"test-file-name": [
"ActsActionExtensionAbilityOtherRely.hap",
"ActsActionExtensionAbilitySelfRely.hap",
"ActsActionExtensionAbilitySelfModule.hap",
"ActsActionExtensionAbilityTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
},
{
"type": "ShellKit",
"run-command": [
"power-shell wakeup",
"power-shell setmode 602",
"hilog -Q pidoff",
"hilog -Q domainoff",
"hilog -b D",
"setenforce 0"
]
}
]
}
\ No newline at end of file
/*
* 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.app.ability.abilityDelegatorRegistry';
let abilityDelegator = undefined;
let abilityDelegatorArguments = undefined;
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility';
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback);
let cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName;
let debug = abilityDelegatorArguments.parameters['-D'];
if (debug == 'true') {
cmd += ' -D';
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
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
/*
* 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
/*
* 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 UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
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) ?? '');
globalThis.context = this.context;
var abilityDelegator: any;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var abilityDelegatorArguments: any;
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('testability/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/*
* 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.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
{
"module": {
"name": "entry_test",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"default"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/testability/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": 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"
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册