Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
f9ff5586
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f9ff5586
编写于
8月 02, 2023
作者:
K
kirl75
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AMS启动规则优化
Signed-off-by:
N
kirl75
<
kirl.liu@huawei.com
>
上级
37c94b8f
变更
39
显示空白变更内容
内联
并排
Showing
39 changed file
with
1892 addition
and
0 deletion
+1892
-0
ability/ability_runtime/stage/BUILD.gn
ability/ability_runtime/stage/BUILD.gn
+1
-0
ability/ability_runtime/stage/actsstartuptest/BUILD.gn
ability/ability_runtime/stage/actsstartuptest/BUILD.gn
+24
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/AppScope/app.json
.../stage/actsstartuptest/StartUpAssistant/AppScope/app.json
+19
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/AppScope/resources/base/element/string.json
...rtUpAssistant/AppScope/resources/base/element/string.json
+8
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/AppScope/resources/base/media/app_icon.png
...artUpAssistant/AppScope/resources/base/media/app_icon.png
+0
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/BUILD.gn
...y_runtime/stage/actsstartuptest/StartUpAssistant/BUILD.gn
+46
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/ets/calleeability/CalleeAbility.ts
...sistant/entry/src/main/ets/calleeability/CalleeAbility.ts
+81
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/ets/entryability/EntryAbility.ts
...Assistant/entry/src/main/ets/entryability/EntryAbility.ts
+80
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/ets/pages/Index.ets
...ptest/StartUpAssistant/entry/src/main/ets/pages/Index.ets
+32
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/module.json
...tsstartuptest/StartUpAssistant/entry/src/main/module.json
+48
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/base/element/color.json
...ssistant/entry/src/main/resources/base/element/color.json
+8
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/base/element/string.json
...sistant/entry/src/main/resources/base/element/string.json
+24
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/base/media/icon.png
...tUpAssistant/entry/src/main/resources/base/media/icon.png
+0
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/base/profile/main_pages.json
...ant/entry/src/main/resources/base/profile/main_pages.json
+5
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/en_US/element/string.json
...istant/entry/src/main/resources/en_US/element/string.json
+24
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/zh_CN/element/string.json
...istant/entry/src/main/resources/zh_CN/element/string.json
+24
-0
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/signature/openharmony_sx.p7b
...startuptest/StartUpAssistant/signature/openharmony_sx.p7b
+0
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/AppScope/app.json
...e/stage/actsstartuptest/StartUpRuleTest/AppScope/app.json
+19
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/AppScope/resources/base/element/string.json
...artUpRuleTest/AppScope/resources/base/element/string.json
+8
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/AppScope/resources/base/media/app_icon.png
...tartUpRuleTest/AppScope/resources/base/media/app_icon.png
+0
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/BUILD.gn
...ty_runtime/stage/actsstartuptest/StartUpRuleTest/BUILD.gn
+43
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/Test.json
...y_runtime/stage/actsstartuptest/StartUpRuleTest/Test.json
+33
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts
...y/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts
+25
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts
...entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts
+45
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
...st/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
+64
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/entryability/EntryAbility.ts
...pRuleTest/entry/src/main/ets/entryability/EntryAbility.ts
+56
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/pages/Index.ets
...uptest/StartUpRuleTest/entry/src/main/ets/pages/Index.ets
+32
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/test/Ability.test.ets
.../StartUpRuleTest/entry/src/main/ets/test/Ability.test.ets
+814
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/test/List.test.ets
...est/StartUpRuleTest/entry/src/main/ets/test/List.test.ets
+20
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/testability/TestAbility.ets
...UpRuleTest/entry/src/main/ets/testability/TestAbility.ets
+64
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/testability/pages/Index.ets
...UpRuleTest/entry/src/main/ets/testability/pages/Index.ets
+49
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/module.json
...ctsstartuptest/StartUpRuleTest/entry/src/main/module.json
+86
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/base/element/color.json
...RuleTest/entry/src/main/resources/base/element/color.json
+8
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/base/element/string.json
...uleTest/entry/src/main/resources/base/element/string.json
+32
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/base/media/icon.png
...rtUpRuleTest/entry/src/main/resources/base/media/icon.png
+0
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/base/profile/main_pages.json
...est/entry/src/main/resources/base/profile/main_pages.json
+6
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/en_US/element/string.json
...leTest/entry/src/main/resources/en_US/element/string.json
+32
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/zh_CN/element/string.json
...leTest/entry/src/main/resources/zh_CN/element/string.json
+32
-0
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/signature/openharmony_sx.p7b
...sstartuptest/StartUpRuleTest/signature/openharmony_sx.p7b
+0
-0
未找到文件。
ability/ability_runtime/stage/BUILD.gn
浏览文件 @
f9ff5586
...
...
@@ -23,6 +23,7 @@ group("stage") {
"actslifecyclemultihap3:ActsLifecycleMultiHap3",
"actslifecyclemultihaptest:ActsLifecycleMultiHapTest",
"actslifecyclesinglehaptest:ActsLifecycleSingleHapTest",
"actsstartuptest:startuptest",
"actsuripermission:ActsUriPermission",
"actswindowstagelifecyclemultihaptest:ActsWindowStageLifecycleMultiHapTest",
"actswindowstagelifecyclesinglehaptest:ActsWindowStageLifecycleSingleHapTest",
...
...
ability/ability_runtime/stage/actsstartuptest/BUILD.gn
0 → 100644
浏览文件 @
f9ff5586
# Copyright (c) 2021-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("startuptest") {
testonly = true
if (is_standard_system) {
deps = [
"StartUpAssistant:StartUpAssistant",
"StartUpRuleTest:StartUpRuleTest",
]
}
}
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/AppScope/app.json
0 → 100644
浏览文件 @
f9ff5586
{
"app"
:
{
"bundleName"
:
"com.acts.startupassistant"
,
"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
}
}
}
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/AppScope/resources/base/element/string.json
0 → 100644
浏览文件 @
f9ff5586
{
"string"
:
[
{
"name"
:
"app_name"
,
"value"
:
"StartUpAssistant"
}
]
}
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/AppScope/resources/base/media/app_icon.png
0 → 100644
浏览文件 @
f9ff5586
6.6 KB
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/BUILD.gn
0 → 100644
浏览文件 @
f9ff5586
# 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("ActsStartUpAssistant") {
hap_name = "ActsStartUpAssistant"
js_build_mode = "debug"
testonly = true
hap_profile = "entry/src/main/module.json"
deps = [
":actsstartupassistant_js_assets",
":actsstartupassistant_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("actsstartupassistant_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("actsstartupassistant_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("actsstartupassistant_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":actsstartupassistant_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/ets/calleeability/CalleeAbility.ts
0 → 100644
浏览文件 @
f9ff5586
/*
* 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
'
;
import
commonEvent
from
'
@ohos.commonEventManager
'
;
function
unsubscribe
(
subscriber
)
{
commonEvent
.
unsubscribe
(
subscriber
,
(
err
,
data
)
=>
{
console
.
debug
(
'
=ACTS_unsubscribe (err,data)=======>
'
);
});
}
export
default
class
CalleeAbility
extends
UIAbility
{
onCreate
(
want
,
launchParam
)
{
hilog
.
info
(
0x0000
,
'
testTag
'
,
'
%{public}s
'
,
'
CalleeAbility onCreate
'
);
let
subscriber
=
null
;
let
terminateSelfEvent
=
{
events
:
[
'
terminateAssistantAbility
'
,
],
};
commonEvent
.
createSubscriber
(
terminateSelfEvent
).
then
((
data
)
=>
{
console
.
log
(
'
createSubscriber
'
);
subscriber
=
data
;
commonEvent
.
subscribe
(
subscriber
,
(
err
,
data
)
=>
{
console
.
log
(
'
ACTS_StartUpRuleOptimizeTest terminateSelfWithResult CalleeAbility
'
);
let
result
=
{
resultCode
:
0
};
this
.
context
.
terminateSelfWithResult
(
result
,
()
=>
{});
unsubscribe
(
subscriber
);
});
})
}
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
'
);
}
}
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/ets/entryability/EntryAbility.ts
0 → 100644
浏览文件 @
f9ff5586
/*
* 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
'
;
import
commonEvent
from
'
@ohos.commonEventManager
'
;
function
unsubscribe
(
subscriber
)
{
commonEvent
.
unsubscribe
(
subscriber
,
(
err
,
data
)
=>
{
console
.
debug
(
'
=ACTS_unsubscribe (err,data)=======>
'
);
});
}
export
default
class
EntryAbility
extends
UIAbility
{
onCreate
(
want
,
launchParam
)
{
hilog
.
info
(
0x0000
,
'
ACTS_StartUpRuleOptimizeTest
'
,
'
%{public}s
'
,
'
AssistantAbility onCreate
'
);
let
subscriber
=
null
;
let
terminateSelfEvent
=
{
events
:
[
'
terminateAssistantAbility
'
,
],
};
commonEvent
.
createSubscriber
(
terminateSelfEvent
).
then
((
data
)
=>
{
console
.
log
(
'
createSubscriber
'
);
subscriber
=
data
;
commonEvent
.
subscribe
(
subscriber
,
(
err
,
data
)
=>
{
console
.
log
(
'
ACTS_StartUpRuleOptimizeTest terminateSelfWithResult AssistantAbility
'
);
let
result
=
{
resultCode
:
0
}
this
.
context
.
terminateSelfWithResult
(
result
,
()
=>
{});
});
})
}
onDestroy
()
{
hilog
.
info
(
0x0000
,
'
ACTS_StartUpRuleOptimizeTest
'
,
'
%{public}s
'
,
'
AssistantAbility 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
,
'
ACTS_StartUpRuleOptimizeTest
'
,
'
%{public}s
'
,
'
AssistantAbility onForeground
'
);
}
onBackground
()
{
// Ability has back to background
hilog
.
info
(
0x0000
,
'
ACTS_StartUpRuleOptimizeTest
'
,
'
%{public}s
'
,
'
AssistantAbility onBackground
'
);
}
}
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/ets/pages/Index.ets
0 → 100644
浏览文件 @
f9ff5586
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Entry
@Component
struct Index {
@State message: string = 'StartUpTest AssistantApp';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/module.json
0 → 100644
浏览文件 @
f9ff5586
{
"module"
:
{
"name"
:
"entry"
,
"type"
:
"entry"
,
"description"
:
"$string:module_desc"
,
"mainElement"
:
"EntryAbility"
,
"deviceTypes"
:
[
"phone"
,
"tablet"
],
"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"
:
"CalleeAbility"
,
"srcEntry"
:
"./ets/calleeability/CalleeAbility.ts"
,
"description"
:
"$string:CalleeAbility_desc"
,
"icon"
:
"$media:icon"
,
"label"
:
"$string:CalleeAbility_label"
,
"startWindowIcon"
:
"$media:icon"
,
"exported"
:
true
,
"launchType"
:
"singleton"
,
"startWindowBackground"
:
"$color:start_window_background"
}
]
}
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/base/element/color.json
0 → 100644
浏览文件 @
f9ff5586
{
"color"
:
[
{
"name"
:
"start_window_background"
,
"value"
:
"#FFFFFF"
}
]
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/base/element/string.json
0 → 100644
浏览文件 @
f9ff5586
{
"string"
:
[
{
"name"
:
"module_desc"
,
"value"
:
"module description"
},
{
"name"
:
"EntryAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"EntryAbility_label"
,
"value"
:
"label"
},
{
"name"
:
"CalleeAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"CalleeAbility_label"
,
"value"
:
"label"
}
]
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/base/media/icon.png
0 → 100644
浏览文件 @
f9ff5586
6.6 KB
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/base/profile/main_pages.json
0 → 100644
浏览文件 @
f9ff5586
{
"src"
:
[
"pages/Index"
]
}
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/en_US/element/string.json
0 → 100644
浏览文件 @
f9ff5586
{
"string"
:
[
{
"name"
:
"module_desc"
,
"value"
:
"module description"
},
{
"name"
:
"EntryAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"EntryAbility_label"
,
"value"
:
"label"
},
{
"name"
:
"CalleeAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"CalleeAbility_label"
,
"value"
:
"label"
}
]
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/entry/src/main/resources/zh_CN/element/string.json
0 → 100644
浏览文件 @
f9ff5586
{
"string"
:
[
{
"name"
:
"module_desc"
,
"value"
:
"模块描述"
},
{
"name"
:
"EntryAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"EntryAbility_label"
,
"value"
:
"label"
},
{
"name"
:
"CalleeAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"CalleeAbility_label"
,
"value"
:
"label"
}
]
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpAssistant/signature/openharmony_sx.p7b
0 → 100644
浏览文件 @
f9ff5586
文件已添加
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/AppScope/app.json
0 → 100644
浏览文件 @
f9ff5586
{
"app"
:
{
"bundleName"
:
"com.acts.startuptest"
,
"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
}
}
}
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/AppScope/resources/base/element/string.json
0 → 100644
浏览文件 @
f9ff5586
{
"string"
:
[
{
"name"
:
"app_name"
,
"value"
:
"startuptest"
}
]
}
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/AppScope/resources/base/media/app_icon.png
0 → 100644
浏览文件 @
f9ff5586
6.6 KB
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/BUILD.gn
0 → 100644
浏览文件 @
f9ff5586
# 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("ActsStartUpRuleTest") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":actsstartupruletest_js_assets",
":actsstartupruletest_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsStartUpRuleTest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("actsstartupruletest_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("actsstartupruletest_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("actsstartupruletest_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":actsstartupruletest_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/Test.json
0 → 100644
浏览文件 @
f9ff5586
{
"description"
:
"Configuration for startuprule demo Tests"
,
"driver"
:
{
"type"
:
"OHJSUnitTest"
,
"test-timeout"
:
"180000"
,
"bundle-name"
:
"com.acts.startuptest"
,
"module-name"
:
"entry"
,
"shell-timeout"
:
"600000"
,
"testcase-timeout"
:
15000
},
"kits"
:
[
{
"test-file-name"
:
[
"ActsStartUpRuleTest.hap"
,
"ActsStartUpAssistant.hap"
],
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
},
{
"type"
:
"ShellKit"
,
"run-command"
:
[
"power-shell wakeup"
,
"power-shell setmode 602"
,
"uinput -T -d 300 600 -m 300 600 300 100 -u 300 100"
,
"hilog -b D"
,
"hilog -Q pidoff"
,
"hilog -Q domainoff"
,
"hilog -G 2M"
]
}
]
}
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts
0 → 100644
浏览文件 @
f9ff5586
/*
* 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
DataShareExtensionAbility
from
'
@ohos.application.DataShareExtensionAbility
'
;
export
default
class
DataShareExtAbility
extends
DataShareExtensionAbility
{
onCreate
(
want
)
{
console
.
log
(
`DataShareExtAbility onCreate:
${
JSON
.
stringify
(
want
)}
`
);
}
onDestroy
()
{
console
.
log
(
`DataShareExtAbility onDestroy`
);
}
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts
0 → 100644
浏览文件 @
f9ff5586
/*
* 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
ServiceExtensionAbility
from
'
@ohos.app.ability.ServiceExtensionAbility
'
import
rpc
from
'
@ohos.rpc
'
class
StubTest
extends
rpc
.
RemoteObject
{
constructor
(
des
)
{
super
(
des
);
}
onRemoteRequest
(
code
,
data
,
reply
,
option
)
{
return
true
;
}
}
export
default
class
ServiceExtAbility
extends
ServiceExtensionAbility
{
onCreate
(
want
)
{
console
.
log
(
`onCreate:
${
JSON
.
stringify
(
want
)}
`
);
}
onRequest
(
want
,
startId
)
{
console
.
log
(
`onRequest:
${
JSON
.
stringify
(
want
)}
`
);
}
onConnect
(
want
)
{
console
.
log
(
`onConnect END`
);
return
new
StubTest
(
"
stub
"
);
}
onDisconnect
(
want
):
void
{
console
.
log
(
`HXW onDisconnect:
${
JSON
.
stringify
(
want
)}
`
);
}
onDestroy
()
{
console
.
log
(
`onDestroy`
);
}
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
0 → 100644
浏览文件 @
f9ff5586
/*
* 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
)
{
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
,
d
)
=>
{
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
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/entryability/EntryAbility.ts
0 → 100644
浏览文件 @
f9ff5586
/*
* 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
'
);
}
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
'
);
}
}
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/pages/Index.ets
0 → 100644
浏览文件 @
f9ff5586
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/test/Ability.test.ets
0 → 100644
浏览文件 @
f9ff5586
/*
* 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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'@ohos/hypium'
import
backgroundTaskManager
from
'@ohos.resourceschedule.backgroundTaskManager'
;
import
wantAgent
from
'@ohos.app.ability.wantAgent'
;
import
commonEvent
from
'@ohos.commonEventManager'
;
import
dataShare
from
'@ohos.data.dataShare'
;
import
AbilityDelegatorRegistry
from
'@ohos.app.ability.abilityDelegatorRegistry'
;
let
ERROR_START_ABILITY_WAITTING
=
16000017
;
let
ERROR_NO_PERMISSION
=
201
;
let
dataShareUri
=
"datashare:///startuptest"
;
let
context
=
null
;
let
abilityDelegator
=
AbilityDelegatorRegistry
.
getAbilityDelegator
();
function
sleep
(
time
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
time
));
}
// start continuous task
async
function
startContinuousTask
(
TAG
):
Promise
<
void
>
{
let
wantAgentInfo
=
{
wants
:
[
{
bundleName
:
'com.acts.startuptest'
,
abilityName
:
'TestAbility'
,
}
],
operationType
:
wantAgent
.
OperationType
.
START_ABILITY
,
requestCode
:
0
,
wantAgentFlags
:
[
wantAgent
.
WantAgentFlags
.
UPDATE_PRESENT_FLAG
]
}
try
{
let
wantAgentObject
=
await
wantAgent
.
getWantAgent
(
wantAgentInfo
);
await
backgroundTaskManager
.
startBackgroundRunning
(
context
,
backgroundTaskManager
.
BackgroundMode
.
DATA_TRANSFER
,
wantAgentObject
);
}
catch
(
error
)
{
console
.
log
(
TAG
+
` Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`
);
}
}
// cancel continuous task
async
function
stopContinuousTask
(
TAG
):
Promise
<
void
>
{
try
{
await
backgroundTaskManager
.
stopBackgroundRunning
(
context
)
}
catch
(
error
)
{
console
.
log
(
TAG
+
` Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`
);
}
}
export
default
function
abilityTest
()
{
describe
(
'ActsAbilityTest'
,
function
()
{
beforeAll
(
async
function
()
{
context
=
globalThis
.
testContext
;
await
abilityDelegator
.
executeShellCommand
(
'killall com.acts.startupassistant'
);
})
beforeEach
(
async
function
()
{
//globalThis.onForegroundFlag = false;
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{});
})
afterEach
(
async
function
()
{
await
stopContinuousTask
(
'afterEach SUB_AA_StartUpRuleOptimizeTest'
);
await
sleep
(
200
);
})
afterAll
(
async
function
()
{
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{});
await
abilityDelegator
.
executeShellCommand
(
'killall com.acts.startupassistant'
);
})
/**
* @tc.number SUB_AA_StartUpRuleOptimizeTest_0100
* @tc.name Prohibit background startAbility test
* @tc.desc Ability can not be started during a non-long-term task or non-scheduling foreground
*/
it
(
'SUB_AA_StartUpRuleOptimizeTest_0100'
,
0
,
async
function
(
done
)
{
let
TAG
=
'SUB_AA_StartUpRuleOptimizeTest_0100 '
;
function
startAbilityWithBgTask
()
{
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startuptest'
}
context
.
startAbility
(
want
,
(
err
)
=>
{
console
.
log
(
TAG
+
' startAbility error: '
+
err
.
code
+
' '
+
err
.
message
);
if
(
err
&&
err
.
code
)
{
expect
(
err
.
code
)
.
assertEqual
(
ERROR_NO_PERMISSION
);
setTimeout
(()
=>
{
console
.
log
(
TAG
+
" publish terminateAssistantAbility event"
);
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{
console
.
log
(
TAG
+
'publish terminate event'
)
});
},
100
);
}
else
{
expect
()
.
assertFail
();
done
();
}
})
}
let
callbackId
;
let
testDone
=
false
;
let
AbilityLifecycleCallback
=
{
onAbilityForeground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityForeground"
)
if
(
abilityName
===
'TestAbility'
)
{
if
(
testDone
===
true
)
{
console
.
log
(
TAG
+
'testDone'
);
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
)
done
();
}
}
},
onAbilityBackground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityBackground"
)
if
(
abilityName
===
'TestAbility'
)
{
setTimeout
(
startAbilityWithBgTask
,
100
);
}
}
}
callbackId
=
globalThis
.
ApplicationContext
.
on
(
'abilityLifecycle'
,
AbilityLifecycleCallback
);
// Start another ability, ensure testAbility is background
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startupassistant'
};
console
.
log
(
TAG
+
'startAbilityForResult'
);
context
.
startAbilityForResult
(
want
,
(
err
,
data
)
=>
{
console
.
log
(
TAG
+
' assistantAbility is terminated'
);
expect
(
err
.
code
)
.
assertEqual
(
0
);
testDone
=
true
;
});
})
/**
* @tc.number SUB_AA_StartUpRuleOptimizeTest_0200
* @tc.name Allow background startAbility for background running ContinuousTask
* @tc.desc Test the startAbility of a background running ContinuousTask.
*/
it
(
'SUB_AA_StartUpRuleOptimizeTest_0200'
,
0
,
async
function
(
done
)
{
let
TAG
=
'SUB_AA_StartUpRuleOptimizeTest_0200 '
;
function
startAbilityWithBgTask
()
{
console
.
log
(
TAG
+
'startAbilityWithBgTask'
);
let
want
=
{
abilityName
:
'TestAbility'
,
bundleName
:
'com.acts.startuptest'
};
// test startAbility
context
.
startAbility
(
want
)
.
then
(()
=>
{
console
.
log
(
TAG
+
' startAbility success'
);
if
(
testDone
===
true
)
{
console
.
log
(
TAG
+
'testDone'
);
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
);
done
();
}
else
{
testDone
=
true
;
}
})
.
catch
((
err
)
=>
{
console
.
log
(
TAG
+
' startAbility error: '
+
err
.
code
+
' '
+
err
.
message
);
if
(
err
.
code
===
ERROR_START_ABILITY_WAITTING
)
{
testDone
=
true
;
return
;
}
expect
()
.
assertFail
();
done
();
})
}
let
callbackId
;
let
testDone
=
false
;
let
AbilityLifecycleCallback
=
{
onAbilityForeground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityForeground"
);
if
(
abilityName
===
'TestAbility'
)
{
if
(
testDone
===
true
)
{
console
.
log
(
TAG
+
'testDone'
);
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
);
done
();
}
}
},
onAbilityBackground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityBackground"
)
if
(
abilityName
===
'TestAbility'
)
{
startAbilityWithBgTask
();
}
}
}
callbackId
=
globalThis
.
ApplicationContext
.
on
(
'abilityLifecycle'
,
AbilityLifecycleCallback
);
await
startContinuousTask
(
TAG
);
// Start another ability, ensure testAbility is background
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startupassistant'
};
console
.
log
(
TAG
+
'startAbility'
);
context
.
startAbility
(
want
,
(
err
,
data
)
=>
{
console
.
log
(
TAG
+
'startAbility callback '
+
err
.
code
);
if
(
err
.
code
&&
err
.
code
!=
ERROR_START_ABILITY_WAITTING
)
{
expect
()
.
assertFail
();
done
();
}
});
})
/**
* @tc.number SUB_AA_StartUpRuleOptimizeTest_0300
* @tc.name Allow background startAbilityByCall for background running ContinuousTask
* @tc.desc Test the startAbilityByCall of a background running ContinuousTask.
*/
it
(
'SUB_AA_StartUpRuleOptimizeTest_0300'
,
0
,
async
function
(
done
)
{
let
TAG
=
'SUB_AA_StartUpRuleOptimizeTest_0300 '
;
function
startAbilityWithBgTask
()
{
let
want
=
{
abilityName
:
'CalleeAbility'
,
bundleName
:
'com.acts.startupassistant'
};
// test startAbilityByCall
context
.
startAbilityByCall
(
want
)
.
then
(
async
()
=>
{
console
.
log
(
TAG
+
' startAbilityByCall success'
);
setTimeout
(()
=>
{
console
.
log
(
TAG
+
" publish terminateAssistantAbility event"
);
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{
console
.
log
(
TAG
+
'publish done'
)
});
},
100
);
})
.
catch
((
err
)
=>
{
console
.
log
(
TAG
+
' startAbilityByCall error: '
+
err
.
code
+
' '
+
err
.
message
);
expect
()
.
assertFail
();
done
();
})
}
let
callbackId
;
let
testDone
=
false
;
let
AbilityLifecycleCallback
=
{
onAbilityForeground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityForeground"
);
if
(
abilityName
===
'TestAbility'
)
{
if
(
testDone
===
true
)
{
console
.
log
(
TAG
+
'testDone'
);
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
);
done
();
}
}
},
onAbilityBackground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityBackground"
);
if
(
abilityName
===
'TestAbility'
)
{
startAbilityWithBgTask
();
}
}
}
callbackId
=
globalThis
.
ApplicationContext
.
on
(
'abilityLifecycle'
,
AbilityLifecycleCallback
);
await
startContinuousTask
(
TAG
);
// Start another ability, ensure testAbility is background
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startupassistant'
};
console
.
log
(
TAG
+
'startAbilityForResult'
);
context
.
startAbilityForResult
(
want
,
(
err
,
data
)
=>
{
console
.
log
(
TAG
+
' assistantAbility is terminated err.code '
+
err
.
code
);
expect
(
err
.
code
)
.
assertEqual
(
0
);
testDone
=
true
;
});
})
/**
* @tc.number SUB_AA_StartUpRuleOptimizeTest_0400
* @tc.name Allow background connectServiceExtensionAbility for background running ContinuousTask
* @tc.desc Test the connectServiceExtensionAbility of a background running ContinuousTask.
*/
it
(
'SUB_AA_StartUpRuleOptimizeTest_0400'
,
0
,
async
function
(
done
)
{
let
TAG
=
'SUB_AA_StartUpRuleOptimizeTest_0400 '
;
let
connectId
;
let
connection
=
{
onConnect
:
function
(
elementName
,
proxy
)
{
console
.
log
(
TAG
+
' onConnect'
);
setTimeout
(()
=>
{
console
.
log
(
TAG
+
" publish terminateAssistantAbility event"
);
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{
console
.
log
(
TAG
+
'send terminate event'
)});
context
.
disconnectServiceExtensionAbility
(
connectId
);
},
100
);
},
onDisconnect
:
function
()
{
console
.
log
(
TAG
+
'onDisconnect'
);
},
onFailed
:
function
(
code
)
{
console
.
log
(
TAG
+
`onFailed ${code}`
);
expect
()
.
assertFail
();
done
();
}
}
function
startAbilityWithBgTask
()
{
console
.
log
(
TAG
+
'startAbilityWithBgTask'
);
let
want
=
{
abilityName
:
'ServiceExtAbility'
,
bundleName
:
'com.acts.startuptest'
};
// test connectServiceExtensionAbility
connectId
=
context
.
connectServiceExtensionAbility
(
want
,
connection
);
}
let
callbackId
;
let
testDone
=
false
;
let
AbilityLifecycleCallback
=
{
onAbilityForeground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityForeground"
)
if
(
abilityName
===
'TestAbility'
)
{
if
(
testDone
===
true
)
{
console
.
log
(
TAG
+
'testDone'
);
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
)
done
();
}
}
},
onAbilityBackground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityBackground"
)
if
(
abilityName
===
'TestAbility'
)
{
startAbilityWithBgTask
();
}
}
}
callbackId
=
globalThis
.
ApplicationContext
.
on
(
'abilityLifecycle'
,
AbilityLifecycleCallback
);
await
startContinuousTask
(
TAG
);
// Start another ability, ensure testAbility is background
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startupassistant'
};
console
.
log
(
TAG
+
'startAbilityForResult'
);
context
.
startAbilityForResult
(
want
,
(
err
,
data
)
=>
{
console
.
log
(
TAG
+
' assistantAbility is terminated'
);
expect
(
err
.
code
)
.
assertEqual
(
0
);
testDone
=
true
;
});
})
/**
* @tc.number SUB_AA_StartUpRuleOptimizeTest_0500
* @tc.name Allow background startServiceExtensionAbility for background running ContinuousTask
* @tc.desc Test the startServiceExtensionAbility of a background running ContinuousTask.
*/
it
(
'SUB_AA_StartUpRuleOptimizeTest_0500'
,
0
,
async
function
(
done
)
{
let
TAG
=
'SUB_AA_StartUpRuleOptimizeTest_0500 '
;
function
startAbilityWithBgTask
()
{
let
want
=
{
abilityName
:
'ServiceExtAbility'
,
bundleName
:
'com.acts.startuptest'
};
// test startServiceExtensionAbility
context
.
startServiceExtensionAbility
(
want
)
.
then
(()
=>
{
console
.
log
(
TAG
+
' startServiceExtensionAbility success'
);
setTimeout
(()
=>
{
console
.
log
(
TAG
+
" publish terminateAssistantAbility event"
);
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{
console
.
log
(
TAG
+
'publish done'
)
});
},
100
);
})
.
catch
((
err
)
=>
{
console
.
log
(
TAG
+
' startServiceExtensionAbility error: '
+
err
.
code
+
' '
+
err
.
message
);
expect
()
.
assertFail
();
done
();
});
}
let
callbackId
;
let
testDone
=
false
;
let
AbilityLifecycleCallback
=
{
onAbilityForeground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityForeground"
);
if
(
abilityName
===
'TestAbility'
)
{
if
(
testDone
===
true
)
{
console
.
log
(
TAG
+
'testDone'
);
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
);
done
();
}
}
},
onAbilityBackground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityBackground"
);
if
(
abilityName
===
'TestAbility'
)
{
startAbilityWithBgTask
();
}
}
}
callbackId
=
globalThis
.
ApplicationContext
.
on
(
'abilityLifecycle'
,
AbilityLifecycleCallback
);
await
startContinuousTask
(
TAG
);
// Start another ability, ensure testAbility is background
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startupassistant'
};
console
.
log
(
TAG
+
'startAbilityForResult'
);
context
.
startAbilityForResult
(
want
,
(
err
,
data
)
=>
{
console
.
log
(
TAG
+
' assistantAbility is terminated'
);
expect
(
err
.
code
)
.
assertEqual
(
0
);
testDone
=
true
;
});
})
/**
* @tc.number SUB_AA_StartUpRuleOptimizeTest_0600
* @tc.name Allow background createDataShareHelper for background running ContinuousTask
* @tc.desc Test the createDataShareHelper of a background running ContinuousTask.
*/
it
(
'SUB_AA_StartUpRuleOptimizeTest_0600'
,
0
,
async
function
(
done
)
{
let
TAG
=
'SUB_AA_StartUpRuleOptimizeTest_0600 '
;
function
startAbilityWithBgTask
()
{
// Test connect dataShare
dataShare
.
createDataShareHelper
(
context
,
dataShareUri
,
(
err
,
dataShareHelper
)
=>
{
console
.
log
(
TAG
+
' createDataShareHelper callback'
);
if
(
err
&&
err
.
code
)
{
console
.
log
(
TAG
+
' createDataShareHelper failed '
+
err
.
code
+
' '
+
err
.
message
);
expect
()
.
assertFail
();
done
();
}
else
{
console
.
log
(
TAG
+
' createDataShareHelper success'
);
setTimeout
(()
=>
{
console
.
log
(
TAG
+
" publish terminateAssistantAbility event"
);
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{
console
.
log
(
TAG
+
'publish done'
)
});
},
100
);
}
})
}
let
callbackId
;
let
testDone
=
false
;
let
AbilityLifecycleCallback
=
{
onAbilityForeground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityForeground"
)
if
(
abilityName
===
'TestAbility'
)
{
if
(
testDone
===
true
)
{
console
.
log
(
TAG
+
'testDone'
);
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
)
done
();
}
}
},
onAbilityBackground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityBackground"
)
if
(
abilityName
===
'TestAbility'
)
{
startAbilityWithBgTask
();
}
}
}
callbackId
=
globalThis
.
ApplicationContext
.
on
(
'abilityLifecycle'
,
AbilityLifecycleCallback
);
await
startContinuousTask
(
TAG
);
// Start another ability, ensure testAbility is background
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startupassistant'
}
console
.
log
(
TAG
+
'startAbilityForResult'
);
context
.
startAbilityForResult
(
want
,
(
err
,
data
)
=>
{
console
.
log
(
TAG
+
' assistantAbility is terminated err.code '
+
err
.
code
);
expect
(
err
.
code
)
.
assertEqual
(
0
);
testDone
=
true
;
});
})
/**
* @tc.number SUB_AA_StartUpRuleOptimizeTest_0700
* @tc.name Allow background startAbility when the ability is moving to foreground
* @tc.desc Test the startAbility call when the ability is moving to foreground.
*/
it
(
'SUB_AA_StartUpRuleOptimizeTest_0700'
,
0
,
async
function
(
done
)
{
let
TAG
=
'SUB_AA_StartUpRuleOptimizeTest_0700 '
;
function
startAbilityWithMoveToForeground
()
{
let
want
=
{
abilityName
:
'TestAbility'
,
bundleName
:
'com.acts.startuptest'
}
// test startAbility
context
.
startAbility
(
want
)
.
then
(()
=>
{
console
.
log
(
TAG
+
' startAbility success'
);
})
.
catch
((
err
)
=>
{
console
.
log
(
TAG
+
' startAbility error: '
+
err
.
code
+
' '
+
err
.
message
);
if
(
err
.
code
!=
ERROR_START_ABILITY_WAITTING
)
{
expect
()
.
assertFail
();
done
();
}
})
}
let
callbackId
;
let
onForeground
=
false
;
let
AbilityLifecycleCallback
=
{
onAbilityForeground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityForeground"
)
if
(
abilityName
===
'TestAbility'
&&
!
onForeground
)
{
onForeground
=
true
;
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
)
done
();
}
},
onAbilityBackground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityBackground"
);
if
(
abilityName
===
'TestAbility'
)
{
setTimeout
(()
=>
{
console
.
log
(
TAG
+
" publish terminateAssistantAbility event"
);
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{
console
.
log
(
TAG
+
'publish done'
)});
},
100
);
}
}
}
callbackId
=
globalThis
.
ApplicationContext
.
on
(
'abilityLifecycle'
,
AbilityLifecycleCallback
);
// Start another ability, ensure testAbility is background
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startupassistant'
}
console
.
log
(
TAG
+
'startAbilityForResult'
);
globalThis
.
onForegroundFlag
=
false
;
context
.
startAbilityForResult
(
want
,
(
err
,
data
)
=>
{
console
.
log
(
TAG
+
' assistantAbility is terminated SUB_AA_StartUpRuleOptimizeTest'
);
expect
(
onForeground
)
.
assertEqual
(
false
);
expect
(
err
.
code
)
.
assertEqual
(
0
);
startAbilityWithMoveToForeground
();
});
})
/**
* @tc.number SUB_AA_StartUpRuleOptimizeTest_0800
* @tc.name Allow background startAbilityByCall when the ability is moving to foreground
* @tc.desc Test the startAbilityByCall call when the ability is moving to foreground.
*/
it
(
'SUB_AA_StartUpRuleOptimizeTest_0800'
,
0
,
async
function
(
done
)
{
let
TAG
=
'SUB_AA_StartUpRuleOptimizeTest_0800 '
;
function
startAbilityWithMoveToForeground
()
{
let
want
=
{
abilityName
:
'CalleeAbility'
,
bundleName
:
'com.acts.startupassistant'
}
// test startAbilityByCall
context
.
startAbilityByCall
(
want
)
.
then
(()
=>
{
console
.
log
(
TAG
+
' startAbilityByCall success'
);
done
();
})
.
catch
((
err
)
=>
{
console
.
log
(
TAG
+
' startAbilityByCall error: '
+
err
.
code
+
' '
+
err
.
message
);
expect
()
.
assertFail
();
done
();
})
}
let
callbackId
;
let
onForeground
=
false
;
let
AbilityLifecycleCallback
=
{
onAbilityForeground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityForeground"
)
if
(
abilityName
===
'TestAbility'
&&
!
onForeground
)
{
onForeground
=
true
;
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
)
}
},
async
onAbilityBackground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityBackground"
);
if
(
abilityName
===
'TestAbility'
)
{
await
sleep
(
100
);
console
.
log
(
TAG
+
" publish terminateAssistantAbility event"
);
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{
console
.
log
(
TAG
+
'publish done'
)});
}
}
}
callbackId
=
globalThis
.
ApplicationContext
.
on
(
'abilityLifecycle'
,
AbilityLifecycleCallback
);
// Start another ability, ensure testAbility is background
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startupassistant'
}
console
.
log
(
TAG
+
'startAbilityForResult'
);
let
option
=
{
windowMode
:
1
}
context
.
startAbilityForResult
(
want
,
option
,
(
err
,
data
)
=>
{
console
.
log
(
TAG
+
' assistantAbility is terminated'
);
expect
(
onForeground
)
.
assertEqual
(
false
);
expect
(
err
.
code
)
.
assertEqual
(
0
);
startAbilityWithMoveToForeground
();
});
})
/**
* @tc.number SUB_AA_StartUpRuleOptimizeTest_0900
* @tc.name Allow background connectServiceExtensionAbility when the ability is moving to foreground
* @tc.desc Test the connectServiceExtensionAbility call when the ability is moving to foreground.
*/
it
(
'SUB_AA_StartUpRuleOptimizeTest_0900'
,
0
,
async
function
(
done
)
{
let
TAG
=
'SUB_AA_StartUpRuleOptimizeTest_0900 '
;
let
connectId
;
let
connection
=
{
onConnect
:
function
(
elementName
,
proxy
)
{
console
.
log
(
TAG
+
' onConnect'
);
context
.
disconnectServiceExtensionAbility
(
connectId
);
},
onDisconnect
:
function
()
{
console
.
log
(
TAG
+
'onDisconnect'
);
done
();
},
onFailed
:
function
(
code
)
{
console
.
log
(
TAG
+
`onFailed ${code}`
);
expect
()
.
assertFail
();
done
();
}
}
function
startAbilityWithMoveToForeground
()
{
let
want
=
{
abilityName
:
'ServiceExtAbility'
,
bundleName
:
'com.acts.startuptest'
}
// test connectServiceExtensionAbility
connectId
=
context
.
connectServiceExtensionAbility
(
want
,
connection
);
}
let
callbackId
;
let
onForeground
=
false
;
let
AbilityLifecycleCallback
=
{
onAbilityForeground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityForeground"
)
if
(
abilityName
===
'TestAbility'
&&
!
onForeground
)
{
onForeground
=
true
;
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
);
}
},
async
onAbilityBackground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityBackground"
)
if
(
abilityName
===
'TestAbility'
)
{
await
sleep
(
100
);
console
.
log
(
TAG
+
" publish terminateAssistantAbility event"
);
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{
console
.
log
(
TAG
+
'publish done'
)});
}
}
}
callbackId
=
globalThis
.
ApplicationContext
.
on
(
'abilityLifecycle'
,
AbilityLifecycleCallback
);
// Start another ability, ensure testAbility is background
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startupassistant'
}
console
.
log
(
TAG
+
'startAbilityForResult'
);
context
.
startAbilityForResult
(
want
,
(
err
,
data
)
=>
{
console
.
log
(
TAG
+
' assistantAbility is terminated'
);
expect
(
onForeground
)
.
assertEqual
(
false
);
expect
(
err
.
code
)
.
assertEqual
(
0
);
startAbilityWithMoveToForeground
();
});
})
/**
* @tc.number SUB_AA_StartUpRuleOptimizeTest_1000
* @tc.name Allow background startServiceExtensionAbility when the ability is moving to foreground
* @tc.desc Test the startServiceExtensionAbility call when the ability is moving to foreground.
*/
it
(
'SUB_AA_StartUpRuleOptimizeTest_1000'
,
0
,
async
function
(
done
)
{
let
TAG
=
'SUB_AA_StartUpRuleOptimizeTest_1000 '
;
function
startAbilityWithMoveToForeground
()
{
let
want
=
{
abilityName
:
'ServiceExtAbility'
,
bundleName
:
'com.acts.startuptest'
}
// test startServiceExtensionAbility
context
.
startServiceExtensionAbility
(
want
)
.
then
(()
=>
{
console
.
log
(
TAG
+
' startServiceExtensionAbility success'
);
})
.
catch
((
err
)
=>
{
console
.
log
(
TAG
+
' startServiceExtensionAbility error: '
+
err
.
code
+
' '
+
err
.
message
);
expect
()
.
assertFail
();
done
();
})
}
let
callbackId
;
let
onForeground
=
false
;
let
AbilityLifecycleCallback
=
{
onAbilityForeground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityForeground"
)
if
(
abilityName
===
'TestAbility'
&&
!
onForeground
)
{
onForeground
=
true
;
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
);
done
();
}
},
async
onAbilityBackground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityBackground"
)
if
(
abilityName
===
'TestAbility'
)
{
await
sleep
(
100
);
console
.
log
(
TAG
+
" publish terminateAssistantAbility event"
);
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{
console
.
log
(
TAG
+
'publish done'
)});
}
}
}
callbackId
=
globalThis
.
ApplicationContext
.
on
(
'abilityLifecycle'
,
AbilityLifecycleCallback
);
// Start another ability, ensure testAbility is background
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startupassistant'
}
console
.
log
(
TAG
+
'startAbilityForResult'
);
context
.
startAbilityForResult
(
want
,
(
err
,
data
)
=>
{
console
.
log
(
TAG
+
' assistantAbility is terminated'
);
expect
(
onForeground
)
.
assertEqual
(
false
);
expect
(
err
.
code
)
.
assertEqual
(
0
);
startAbilityWithMoveToForeground
();
});
})
/**
* @tc.number SUB_AA_StartUpRuleOptimizeTest_1100
* @tc.name Allow background createDataShareHelper when the ability is moving to foreground
* @tc.desc Test the createDataShareHelper call when the ability is moving to foreground.
*/
it
(
'SUB_AA_StartUpRuleOptimizeTest_1100'
,
0
,
async
function
(
done
)
{
let
TAG
=
'SUB_AA_StartUpRuleOptimizeTest_1100 '
;
function
startAbilityWithMoveToForeground
()
{
// Test connect dataShare
dataShare
.
createDataShareHelper
(
context
,
dataShareUri
,
(
err
,
dataShareHelper
)
=>
{
console
.
log
(
TAG
+
' createDataShareHelper callback'
);
if
(
err
&&
err
.
code
)
{
console
.
log
(
TAG
+
' createDataShareHelper failed '
+
err
.
code
+
' '
+
err
.
message
);
expect
()
.
assertFail
();
done
();
}
else
{
console
.
log
(
TAG
+
' createDataShareHelper success'
);
done
();
}
})
}
let
callbackId
;
let
onForeground
=
false
;
let
AbilityLifecycleCallback
=
{
onAbilityForeground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityForeground"
)
if
(
abilityName
===
'TestAbility'
&&
!
onForeground
)
{
onForeground
=
true
;
globalThis
.
ApplicationContext
.
off
(
'abilityLifecycle'
,
callbackId
);
}
},
onAbilityBackground
(
ability
)
{
let
abilityName
=
ability
.
context
.
abilityInfo
.
name
;
console
.
log
(
TAG
+
abilityName
+
" onAbilityBackground"
);
if
(
abilityName
===
'TestAbility'
)
{
setTimeout
(()
=>
{
console
.
log
(
TAG
+
" publish terminateAssistantAbility event"
);
commonEvent
.
publish
(
'terminateAssistantAbility'
,
()
=>
{
console
.
log
(
TAG
+
'publish done'
)});
},
100
);
}
}
}
callbackId
=
globalThis
.
ApplicationContext
.
on
(
'abilityLifecycle'
,
AbilityLifecycleCallback
);
// Start another ability, ensure testAbility is background
let
want
=
{
abilityName
:
'EntryAbility'
,
bundleName
:
'com.acts.startupassistant'
}
console
.
log
(
TAG
+
'startAbilityForResult'
);
context
.
startAbilityForResult
(
want
,
(
err
,
data
)
=>
{
console
.
log
(
TAG
+
' assistantAbility is terminated'
);
expect
(
onForeground
)
.
assertEqual
(
false
);
expect
(
err
.
code
)
.
assertEqual
(
0
);
startAbilityWithMoveToForeground
();
});
})
})
}
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/test/List.test.ets
0 → 100644
浏览文件 @
f9ff5586
/*
* 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
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/testability/TestAbility.ets
0 → 100644
浏览文件 @
f9ff5586
/*
* 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) {
globalThis.onForegroundFlag = false;
globalThis.testContext = this.context;
globalThis.ApplicationContext = this.context.getApplicationContext();
hilog.info(0x0000, 'ACTS_StartUpRuleOptimizeTest', '%{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) ?? '');
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let 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(0x01300, 'HXWACTS_StartUpRuleOptimizeTest', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'ACTS_StartUpRuleOptimizeTest', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/ets/testability/pages/Index.ets
0 → 100644
浏览文件 @
f9ff5586
/*
* 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 TestAbility';
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
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/module.json
0 → 100644
浏览文件 @
f9ff5586
{
"module"
:
{
"name"
:
"entry"
,
"type"
:
"entry"
,
"description"
:
"$string:module_desc"
,
"mainElement"
:
"EntryAbility"
,
"deviceTypes"
:
[
"default"
,
"car"
,
"tablet"
],
"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"
:
"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"
,
"backgroundModes"
:
[
"dataTransfer"
]
}
],
"extensionAbilities"
:
[
{
"name"
:
"ServiceExtAbility"
,
"description"
:
"service"
,
"type"
:
"service"
,
"exported"
:
true
,
"srcEntry"
:
"./ets/ServiceExtAbility/ServiceExtAbility.ts"
},
{
"name"
:
"DataShareExtAbility"
,
"description"
:
"dataShare"
,
"type"
:
"dataShare"
,
"uri"
:
"datashare://startuptest"
,
"exported"
:
true
,
"srcEntry"
:
"./ets/DataShareExtAbility/DataShareExtAbility.ts"
}
],
"requestPermissions"
:
[
{
"name"
:
"ohos.permission.KEEP_BACKGROUND_RUNNING"
,
"reason"
:
"$string:keep_running"
,
"usedScene"
:
{
"abilities"
:
[
"TestAbility"
],
"when"
:
"always"
}
},
{
"name"
:
"ohos.permission.ABILITY_BACKGROUND_COMMUNICATION"
},
{
"name"
:
"ohos.permission.CLEAN_BACKGROUND_PROCESSES"
}
]
}
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/base/element/color.json
0 → 100644
浏览文件 @
f9ff5586
{
"color"
:
[
{
"name"
:
"start_window_background"
,
"value"
:
"#FFFFFF"
}
]
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/base/element/string.json
0 → 100644
浏览文件 @
f9ff5586
{
"string"
:
[
{
"name"
:
"module_desc"
,
"value"
:
"module description"
},
{
"name"
:
"EntryAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"EntryAbility_label"
,
"value"
:
"label"
},
{
"name"
:
"module_test_desc"
,
"value"
:
"test ability description"
},
{
"name"
:
"TestAbility_desc"
,
"value"
:
"the test ability"
},
{
"name"
:
"TestAbility_label"
,
"value"
:
"test label"
},
{
"name"
:
"keep_running"
,
"value"
:
"长时任务权限"
}
]
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/base/media/icon.png
0 → 100644
浏览文件 @
f9ff5586
6.6 KB
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/base/profile/main_pages.json
0 → 100644
浏览文件 @
f9ff5586
{
"src"
:
[
"pages/Index"
,
"testability/pages/Index"
]
}
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/en_US/element/string.json
0 → 100644
浏览文件 @
f9ff5586
{
"string"
:
[
{
"name"
:
"module_desc"
,
"value"
:
"module description"
},
{
"name"
:
"EntryAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"EntryAbility_label"
,
"value"
:
"label"
},
{
"name"
:
"module_test_desc"
,
"value"
:
"test ability description"
},
{
"name"
:
"TestAbility_desc"
,
"value"
:
"the test ability"
},
{
"name"
:
"TestAbility_label"
,
"value"
:
"test label"
},
{
"name"
:
"keep_running"
,
"value"
:
"长时任务权限"
}
]
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/entry/src/main/resources/zh_CN/element/string.json
0 → 100644
浏览文件 @
f9ff5586
{
"string"
:
[
{
"name"
:
"module_desc"
,
"value"
:
"模块描述"
},
{
"name"
:
"EntryAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"EntryAbility_label"
,
"value"
:
"label"
},
{
"name"
:
"module_test_desc"
,
"value"
:
"test ability description"
},
{
"name"
:
"TestAbility_desc"
,
"value"
:
"the test ability"
},
{
"name"
:
"TestAbility_label"
,
"value"
:
"test label"
},
{
"name"
:
"keep_running"
,
"value"
:
"长时任务权限"
}
]
}
\ No newline at end of file
ability/ability_runtime/stage/actsstartuptest/StartUpRuleTest/signature/openharmony_sx.p7b
0 → 100644
浏览文件 @
f9ff5586
文件已添加
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录