mirror of
https://github.com/openharmony/ability_ability_lite.git
synced 2026-07-01 18:25:51 -04:00
update openharmony 1.0.1
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
### 该问题是怎么引起的?
|
||||
|
||||
|
||||
|
||||
### 重现步骤
|
||||
|
||||
|
||||
|
||||
### 报错信息
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
### 相关的Issue
|
||||
|
||||
|
||||
### 原因(目的、解决的问题等)
|
||||
|
||||
|
||||
### 描述(做了什么,变更了什么)
|
||||
|
||||
|
||||
### 测试用例(新增、改动、可能影响的功能)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,2 +1,95 @@
|
||||
## Introduction
|
||||
A data struct named Want utilized to encapsulate some elements in order to simplify the process of starting an application.
|
||||
# Ability Management Framework<a name="EN-US_TOPIC_0000001062157546"></a>
|
||||
|
||||
- [Introduction](#section11660541593)
|
||||
- [\#EN-US\_TOPIC\_0000001062157546/section5503249756](#section5503249756)
|
||||
- [Directory Structure](#section1464106163817)
|
||||
- [Usage](#section1954314201620)
|
||||
- [Repositories Involved](#section93061357133720)
|
||||
|
||||
## Introduction<a name="section11660541593"></a>
|
||||
|
||||
The ability management framework is provided by OpenHarmony for you to develop OpenHarmony applications. The following figure shows the architecture of the ability management framework.
|
||||
|
||||
**Figure 1** Ability management framework
|
||||
|
||||

|
||||
|
||||
- **AbilityKit** is a development kit provided by the ability management framework. You can use this kit to develop applications based on the **Ability** component. There are two types of applications developed based on the **Ability** component: **JS Ability** developed using the JavaScript language and **Native Ability** developed using the C/C++ language. The **JS application development framework** encapsulates JavaScript UI components on the basis of the AbilityKit and is used to help you quickly develop JS Ability-based applications.
|
||||
- **Ability** is the minimum unit for the system to schedule applications. It is a component that can implement an independent functionality. An application can contain one or more **Ability** instances. There are two types of templates that you can use to create an **Ability** instance: Page and Service.
|
||||
- An **Ability using the Page template** \(Page ability for short\) provides a UI for interacting with users.
|
||||
- An **Ability using the Service template** \(Service ability for short\) does not have a UI and is used for running background tasks.
|
||||
|
||||
- An **AbilitySlice** represents a single screen and its control logic. It is specific to Page abilities. A Page ability may contain one ability slice or multiple ability slices that provide highly relevant capabilities. The following figure shows the relationship between a Page ability and its ability slices.
|
||||
|
||||
**Figure 2** Relationship between a Page ability and its ability slices
|
||||
|
||||

|
||||
|
||||
- **Lifecycle** is a general term for all states of an ability, including **UNINITIALIZED**, **INITIAL**, **INACTIVE**, **ACTIVE**, and **BACKGROUND**. The following figure shows the lifecycle state transition of an ability.
|
||||
|
||||
**Figure 3** Lifecycle state transition of a Page ability
|
||||
|
||||

|
||||
|
||||
- Description of ability lifecycle states:
|
||||
- **UNINITIALIZED**: The ability is not initialized. This state is a temporary state. An ability changes directly to the **INITIAL** state upon its creation.
|
||||
|
||||
- **INITIAL**: This state refers to the initial or stopped state. The ability in this state is not running. The ability enters the **INACTIVE** state after it is started.
|
||||
|
||||
- **INACTIVE**: The ability is visible but does not gain focus.
|
||||
|
||||
- **ACTIVE**: The ability is in the foreground and has focus. The ability changes from the **ACTIVE** state to the **INACTIVE** state before returning to the background.
|
||||
|
||||
- **BACKGROUND**: The ability returns to the background. After being re-activated, the ability enters the **ACTIVE** state. After being destroyed, the ability enters the **INITIAL** state.
|
||||
|
||||
- **AbilityLoader** is used to register and load **Ability** classes. After creating an **Ability** class, you should first call the registration API defined in **AbilityLoader** to register the **Ability** class name with the ability management framework so that this **Ability** can be instantiated when being started.
|
||||
- **AbilityManager** enables inter-process communication \(IPC\) between the AbilityKit and the Ability Manager Service.
|
||||
- **EventHandler** is provided by the AbilityKit to enable inter-thread communication between abilities.
|
||||
- The **Ability Manager Service** is a system service used to coordinate the running relationships and lifecycle states of **Ability** instances. It consists of the following sub-modules:
|
||||
- The **service startup** sub-module starts and registers the Ability Manager Service.
|
||||
- The **service interface management** sub-module manages external capabilities provided by the Ability Manager Service.
|
||||
- The **process management** sub-module starts and destroys processes where **Ability** instances are running, and maintains the process information.
|
||||
- The **ability stack management** sub-module maintains the presentation sequence of abilities in the stack.
|
||||
- The **lifecycle scheduling** sub-module changes an ability to a particular state based on the current operation of the system.
|
||||
- The **connection management** sub-module manages connections to Service abilities.
|
||||
|
||||
- **AppSpawn** is a system service used to create the process for running an ability. This service has high permissions. It sets permissions for **Ability** instances and pre-loads some common modules to accelerate application startup.
|
||||
|
||||
## Directory Structure<a name="section1464106163817"></a>
|
||||
|
||||
```
|
||||
/foundation/aafwk/aafwk_lite
|
||||
├── frameworks
|
||||
│ ├── ability_lite # Core implementation code of AbilityKit
|
||||
│ ├── abilitymgr_lite # Client code used for communication between the AbilityKit and Ability Manager Service
|
||||
│ └── want_lite # Implementation code of the information carrier for interaction between abilities
|
||||
├── interfaces
|
||||
│ ├── kits
|
||||
│ │ ├── ability_lite # AbilityKit APIs exposed externally
|
||||
│ │ └── want_lite # External APIs of the information carrier for interaction between abilities
|
||||
│ └── innerkits
|
||||
│ └── abilitymgr_lite # Internal APIs provided by the Ability Manager Service for other subsystems
|
||||
└── services
|
||||
└── abilitymgr_lite # Implementation code of the Ability Manager Service
|
||||
```
|
||||
|
||||
## Usage<a name="section1954314201620"></a>
|
||||
|
||||
- The Ability Manager Service is running in the foundation process.
|
||||
- The Ability Manager Service is registered with **sa\_manager**. **sa\_manager** runs in the foundation process and sets up a thread runtime environment for the service. For details about how to create and use the Ability Manager Service, see [SA Framework](en-us_topic_0000001051589563.md).
|
||||
- The Ability Manager Service starts upon OS startup.
|
||||
|
||||
- After the HAP installation is complete, you can use the aa tool to run the demo for starting the specified ability through the following command. \(Taking **hispark\_taurus** as an example, you can obtain the aa tool from the **out/hispark\_taurus/ipcamera\_hispark\_taurus/dev\_tools/bin** directory after the version building.\)
|
||||
|
||||
```
|
||||
./bin/aa start -p com.xxxxxx.hiability -n MainAbility
|
||||
```
|
||||
|
||||
## Repositories Involved<a name="section93061357133720"></a>
|
||||
|
||||
Application framework
|
||||
|
||||
**aafwk\_lite**
|
||||
|
||||
appexecfwk\_lite
|
||||
|
||||
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
# 元能力组件<a name="ZH-CN_TOPIC_0000001062157546"></a>
|
||||
|
||||
- [简介](#section11660541593)
|
||||
- [\#ZH-CN\_TOPIC\_0000001062157546/section5503249756](#section5503249756)
|
||||
- [目录](#section1464106163817)
|
||||
- [使用说明](#section1954314201620)
|
||||
- [相关仓](#section93061357133720)
|
||||
|
||||
## 简介<a name="section11660541593"></a>
|
||||
|
||||
**元能力组件**,是OpenHarmony为开发者提供的一套开发鸿蒙应用的开发框架。元能力组件由如下模块组成:
|
||||
|
||||
**图1** 元能力组件框架图
|
||||
|
||||

|
||||
|
||||
- **AbilityKit**是Ability框架提供给开发者的开发包,开发者基于该开发包可以开发出基于Ability组件的应用。基于Ability组件开发的应用有两种类型:基于Javascript语言开发的Ability(**JS Ability**)和基于C/C++语言开发的Ability(**Native Ability**)。**JS应用开发框架**是开发者开发JS Ability所用到框架,是在AbilityKit基础封装的包含JS UI组件的一套方便开发者能够迅速开发Ability应用的框架。
|
||||
- **Ability**是系统调度应用的最小单元,是能够完成一个独立功能的组件,一个应用可以包含一个或多个Ability。Ability分为两种类型:Page类型的Ability和Service类型的Ability
|
||||
- **Page类型的Ability:**带有界面,为用户提供人机交互的能力。
|
||||
- **Service类型的Ability**:不带界面,为用户提供后台任务机制。
|
||||
|
||||
- **AbilitySlice**是单个页面及其控制逻辑的总和,是Page类型Ability特有的组件,一个Page类型的Ability可以包含多个AbilitySlice,此时,这些页面提供的业务能力应当是高度相关的。Page类型的Ability和AbilitySlice的关系如下图2所示:
|
||||
|
||||
**图2 **Ability与AbilitySlice的关系图
|
||||
|
||||

|
||||
|
||||
- **生命周期**是Ability被调度到启动、激活、隐藏和退出等各个状态的的统称。Ability各生命周期流转如下图所示:
|
||||
|
||||
**图3** Ability生命周期流转图
|
||||
|
||||

|
||||
|
||||
- Ability生命周期各状态解析:
|
||||
- **UNINITIALIZED**:未初始状态,为临时状态,Ability被创建后会由UNINITIALIZED状态进入INITIAL状态;
|
||||
|
||||
- **INITIAL**:初始化状态,也表示停止状态,表示当前Ability未运行,Ability被启动后由INITIAL态进入INACTIVE状态;
|
||||
|
||||
- **INACTIVE**:未激活状态,表示当前窗口已显示但是无焦点状态。
|
||||
|
||||
- **ACTIVE**:前台激活状态,表示当前窗口已显示,并获取焦点,Ability在退到后台之前先由ACTIVE状态进入INACTIVE状态;
|
||||
|
||||
- **BACKGROUND**: 后台状态,表示当前Ability退到后台,Ability在被销毁后由BACKGROUND状态进入INITIAL状态,或者重新被激活后由BACKGROUND状态进入ACTIVE状态。
|
||||
|
||||
- **AbilityLoader**负责注册和加载开发者Ability的模块。开发者开发的Ability先要调用AbilityLoader的注册接口注册到框架中,接着Ability启动时会被实例化。
|
||||
- **AbilityManager**负责AbilityKit和Ability管理服务进行IPC的通信。
|
||||
- **EventHandler**是AbilityKit提供给开发者的用于在Ability中实现线程间通信的一个模块。
|
||||
- **Ability运行管理服务**是用于协调各Ability运行关系、及生命周期进行调度的系统服务。其中,**服务启动**模块负责Ability管理服务的启动、注册等。**服务接口管理模块**负责Ability管理服务对外能力的管理。**进程管理模块**负责Ability应用所在进程的启动和销毁、及其进程信息维护等功能。**Ability栈管理模块**负责维护各个Ability之间跳转的先后关系。**生命周期调度模块**是Ability管理服务根据系统当前的操作调度Ability进入相应的状态的模块**。连接管理模块**是Ability管理服务对Service类型Ability连接管理的模块
|
||||
- **AppSpawn**是负责创建Ability应用所在进程的系统服务,该服务有较高的权限,为Ability应用设置相应的权限,并预加载一些通用的模块,加速应用的启动。
|
||||
|
||||
## 目录<a name="section1464106163817"></a>
|
||||
|
||||
```
|
||||
/foundation/aafwk/aafwk_lite
|
||||
├── frameworks
|
||||
│ ├── ability_lite # AbilityKit实现的核心代码
|
||||
│ ├── abilitymgr_lite # 管理AbilityKit与Ability管理服务通信的客户端代码
|
||||
│ └── want_lite # Ability之间交互的信息载体的实现代码
|
||||
├── interfaces
|
||||
│ ├── kits
|
||||
│ │ ├── ability_lite # AbilityKit为开发者提供的接口
|
||||
│ │ └── want_lite # Ability之间交互的信息载体的对外接口
|
||||
│ └── innerkits
|
||||
│ └── abilitymgr_lite # Ability管理服务为其它子系统提供的接口
|
||||
└── services
|
||||
└── abilitymgr_lite # Ability管理服务的实现代码
|
||||
```
|
||||
|
||||
## 使用说明<a name="section1954314201620"></a>
|
||||
|
||||
- 元能力运行管理服务为AbilityMs,服务运行于foudation进程中;
|
||||
- AbilityMs注册到sa\_manager中,sa\_manager运行于foundation进程中,sa\_manager为AbilityMs创建线程运行环境。具体创建AbilityMs服务的方式以及使用该服务的方式,可参考[系统服务框架子系统](zh-cn_topic_0000001051589563.md);
|
||||
- 系统启动后,AbilityMs会随系统启动而启动;
|
||||
|
||||
- 包安装完成后,通过如下命令(以hispark\_taurus为例,aa工具在系统构建后放置在out/hispark\_taurus/ipcamera\_hispark\_taurus/dev\_tools/bin下),运行Demo启动相应Ability:
|
||||
|
||||
```
|
||||
./bin/aa start -p com.xxxxxx.hiability -n MainAbility
|
||||
```
|
||||
|
||||
## 相关仓<a name="section93061357133720"></a>
|
||||
|
||||
用户程序框架子系统
|
||||
|
||||
**aafwk\_lite**
|
||||
|
||||
appexecfwk\_lite
|
||||
|
||||
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 4.8 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
Executable
+128
@@ -0,0 +1,128 @@
|
||||
# Copyright (c) 2020 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("//build/lite/config/component/lite_component.gni")
|
||||
import("//build/lite/config/subsystem/aafwk/config.gni")
|
||||
import("//build/lite/ndk/ndk.gni")
|
||||
|
||||
generate_notice_file("ability_notice_file") {
|
||||
module_name = "ability"
|
||||
module_source_dir_list = [
|
||||
"//third_party/bounds_checking_function",
|
||||
"//third_party/cJSON",
|
||||
]
|
||||
}
|
||||
|
||||
lite_library("ability") {
|
||||
target_type = "shared_library"
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Wno-format",
|
||||
"-Wno-format-extra-args",
|
||||
]
|
||||
cflags_cc = cflags
|
||||
sources = [
|
||||
"src/ability.cpp",
|
||||
"src/ability_context.cpp",
|
||||
"src/ability_env.cpp",
|
||||
"src/ability_env_impl.cpp",
|
||||
"src/ability_event_handler.cpp",
|
||||
"src/ability_loader.cpp",
|
||||
"src/ability_main.cpp",
|
||||
"src/ability_scheduler.cpp",
|
||||
"src/ability_thread.cpp",
|
||||
]
|
||||
|
||||
if (enable_ohos_appexecfwk_feature_ability == true) {
|
||||
sources += [
|
||||
"src/ability_slice.cpp",
|
||||
"src/ability_slice_manager.cpp",
|
||||
"src/ability_slice_route.cpp",
|
||||
"src/ability_slice_scheduler.cpp",
|
||||
"src/ability_slice_stack.cpp",
|
||||
"src/ability_window.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
public_deps = [
|
||||
"${aafwk_lite_path}/frameworks/abilitymgr_lite:abilitymanager",
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
"//utils/native/lite/kv_store:kv_store",
|
||||
]
|
||||
|
||||
if (enable_ohos_appexecfwk_feature_ability == true) {
|
||||
public_deps += [ "//foundation/graphic/ui:lite_ui" ]
|
||||
}
|
||||
|
||||
include_dirs = [
|
||||
"${aafwk_lite_path}/frameworks/abilitymgr_lite/include",
|
||||
"${aafwk_lite_path}/frameworks/want_lite/include",
|
||||
"${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
"${aafwk_lite_path}/interfaces/kits/ability_lite",
|
||||
"${appexecfwk_lite_path}/utils/bundle_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite/include",
|
||||
"//foundation/graphic/ui/frameworks",
|
||||
"//foundation/graphic/surface/interfaces/kits",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/registry",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
"//foundation/communication/ipc_lite/frameworks/liteipc/include",
|
||||
"//kernel/liteos_a/kernel/include",
|
||||
"//kernel/liteos_a/kernel/common",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//third_party/freetype/include",
|
||||
"//utils/native/lite/kv_store/innerkits",
|
||||
"//utils/native/lite/include",
|
||||
"./include",
|
||||
"./",
|
||||
]
|
||||
|
||||
defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ]
|
||||
|
||||
if (board_name == "hispark_taurus") {
|
||||
defines += [ "OPENHARMONY_FONT_PATH" ]
|
||||
}
|
||||
|
||||
if (enable_ohos_appexecfwk_feature_ability == true) {
|
||||
defines += [ "ABILITY_WINDOW_SUPPORT" ]
|
||||
}
|
||||
}
|
||||
|
||||
lite_component("aafwk_abilitykit_lite") {
|
||||
if (enable_ohos_appexecfwk_feature_ability == true) {
|
||||
public_configs = [ ":abilitykit_config" ]
|
||||
}
|
||||
|
||||
features = [ ":ability" ]
|
||||
}
|
||||
|
||||
config("abilitykit_config") {
|
||||
ldflags = [
|
||||
"-lstdc++",
|
||||
"-Wl,-rpath-link=$ohos_root_path/$root_out_dir",
|
||||
]
|
||||
}
|
||||
|
||||
ndk_lib("ability_notes") {
|
||||
lib_extension = ".so"
|
||||
deps = [
|
||||
":ability",
|
||||
"${aafwk_lite_path}/frameworks/abilitymgr_lite:abilitymanager",
|
||||
]
|
||||
head_files = [
|
||||
"${aafwk_lite_path}/interfaces/kits/ability_lite",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
]
|
||||
}
|
||||
Executable
+177
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
# AbilityKit - ability development kit
|
||||
|
||||
## Introduction
|
||||
|
||||
The cpp file is the implementation of AbilityKit class.
|
||||
|
||||
## Features
|
||||
|
||||
- provides methods for users to write their own applications.
|
||||
- manage slices of the ability in an application
|
||||
- create the application main thread and display the window
|
||||
|
||||
## Directions
|
||||
|
||||
```
|
||||
|
||||
.
|
||||
└── ability_lite
|
||||
├── BUILD.gn
|
||||
├── include
|
||||
│ ├── ability_env_impl.h # implementation of ability_env.h
|
||||
│ ├── ability_scheduler.h # execute ability task from ability manager service
|
||||
│ ├── ability_service_manager.h # manage the ability of service
|
||||
│ ├── ability_slice_manager.h # manage the slice of the ability
|
||||
│ ├── ability_slice_route.h # manage the entry of an ability
|
||||
│ ├── ability_slice_scheduler.h # scheduler the slices of an ability
|
||||
│ ├── ability_slice_stack.h # store all the slices in an ability and supply method to operate them
|
||||
│ ├── ability_thread.h # the main thread of the kit
|
||||
│ ├── ability_window.h # handle the window during a whole ability lifecycle
|
||||
│ └── app_info.h # a struct that records the information of an application
|
||||
├── README.md
|
||||
└── src
|
||||
├── ability.cpp
|
||||
├── ability_context.cpp
|
||||
├── ability_env.cpp
|
||||
├── ability_env_impl.cpp
|
||||
├── ability_loader.cpp
|
||||
├── ability_manager.cpp
|
||||
├── ability_scheduler.cpp
|
||||
├── ability_service_manager.cpp
|
||||
├── ability_slice.cpp
|
||||
├── ability_slice_manager.cpp
|
||||
├── ability_slice_route.cpp
|
||||
├── ability_slice_scheduler.cpp
|
||||
├── ability_slice_stack.cpp
|
||||
├── ability_thread.cpp
|
||||
├── ability_window.cpp
|
||||
└── main.cpp
|
||||
|
||||
```
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef OHOS_ABILITY_ENV_IMPL_H
|
||||
#define OHOS_ABILITY_ENV_IMPL_H
|
||||
|
||||
#include <app_info.h>
|
||||
#include <string>
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityEnvImpl : public NoCopyable {
|
||||
public:
|
||||
static AbilityEnvImpl &GetInstance()
|
||||
{
|
||||
static AbilityEnvImpl instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
~AbilityEnvImpl() override = default;
|
||||
|
||||
void SetAppInfo(const AppInfo& appInfo);
|
||||
|
||||
const std::string& GetBundleName() const;
|
||||
|
||||
const std::string& GetSrcPath() const;
|
||||
|
||||
const std::string& GetDataPath() const;
|
||||
|
||||
private:
|
||||
AbilityEnvImpl() = default;
|
||||
|
||||
std::string bundleName_;
|
||||
std::string srcPath_;
|
||||
std::string dataPath_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_ENV_IMPL_H
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_SCHEDULER_H
|
||||
#define OHOS_ABILITY_SCHEDULER_H
|
||||
|
||||
#include <app_info.h>
|
||||
|
||||
#include "ability_event_handler.h"
|
||||
#include "nocopyable.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "serializer.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
class Scheduler {
|
||||
public:
|
||||
virtual ~Scheduler() = default;
|
||||
|
||||
/* perform application start and stop */
|
||||
virtual void PerformAppInit(const AppInfo& appInfo) = 0;
|
||||
virtual void PerformAppExit() = 0;
|
||||
|
||||
/* perform transact ability lifecycle state */
|
||||
virtual void PerformTransactAbilityState(const Want &want, int state, uint64_t token, int abilityType) = 0;
|
||||
/* perform connect ability */
|
||||
virtual void PerformConnectAbility(const Want &want, uint64_t token) = 0;
|
||||
virtual void PerformDisconnectAbility(const Want &want, uint64_t token) = 0;
|
||||
/* perform dump ability info */
|
||||
virtual void PerformDumpAbility(const Want &want, uint64_t token) = 0;
|
||||
};
|
||||
|
||||
class AbilityScheduler : public NoCopyable {
|
||||
public:
|
||||
AbilityScheduler() = delete;
|
||||
AbilityScheduler(AbilityEventHandler &eventHandler, Scheduler &scheduler);
|
||||
~AbilityScheduler() override = default;
|
||||
|
||||
static int32_t AmsCallback(const IpcContext* context, void *ipcMsg, IpcIo *data, void *arg);
|
||||
|
||||
private:
|
||||
void PerformAppInit(const AppInfo& appInfo);
|
||||
void PerformTransactAbilityState(const Want &want, int state, uint64_t token, int abilityType);
|
||||
void PerformConnectAbility(const Want &want, uint64_t token);
|
||||
void PerformDisconnectAbility(const Want &want, uint64_t token);
|
||||
void PerformAppExit();
|
||||
void PerformDumpAbility(const Want &want, uint64_t token);
|
||||
static void ClearIpcMsg(void *ipcMsg);
|
||||
|
||||
AbilityEventHandler &eventHandler_;
|
||||
Scheduler &scheduler_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_SCHEDULER_H
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_SLICE_MANAGER_H
|
||||
#define OHOS_ABILITY_SLICE_MANAGER_H
|
||||
|
||||
#include <ability.h>
|
||||
#include <ability_slice.h>
|
||||
|
||||
namespace OHOS {
|
||||
class AbilitySliceScheduler;
|
||||
|
||||
class AbilitySliceManager {
|
||||
public:
|
||||
explicit AbilitySliceManager(Ability &ability);
|
||||
~AbilitySliceManager();
|
||||
|
||||
void OnAbilityStart(const Want &want);
|
||||
void OnAbilityInactive();
|
||||
void OnAbilityActive(const Want &want);
|
||||
void OnAbilityBackground();
|
||||
void OnAbilityStop();
|
||||
|
||||
void Present(const AbilitySlice &caller, AbilitySlice &target, const Want &want);
|
||||
void Terminate(AbilitySlice &slice);
|
||||
|
||||
void SetMainRoute(const std::string &entry);
|
||||
void AddActionRoute(const std::string &action, const std::string &entry);
|
||||
|
||||
void SetUIContent(RootView *rootView);
|
||||
int GetAbilityState();
|
||||
|
||||
int TerminateAbility();
|
||||
|
||||
std::string GetSliceStackInfo() const;
|
||||
|
||||
uint64_t GetToken() const;
|
||||
|
||||
private:
|
||||
AbilitySliceScheduler *abilitySliceScheduler_ { nullptr };
|
||||
Ability &ability_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_SLICE_MANAGER_H
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_SLICE_ROUTE_H
|
||||
#define OHOS_ABILITY_SLICE_ROUTE_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
class AbilitySliceRoute {
|
||||
public:
|
||||
AbilitySliceRoute() = default;
|
||||
~AbilitySliceRoute();
|
||||
|
||||
void SetMainRoute(const std::string &entry);
|
||||
const std::string &GetMainRoute() const;
|
||||
void AddActionRoute(const std::string &action, const std::string &entry);
|
||||
std::string MatchRoute(const std::string &action);
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
std::string mainEntry_ {};
|
||||
std::map<std::string, std::string> actionEntries_ {};
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_SLICE_ROUTE_H
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_SLICE_SCHEDULER_H
|
||||
#define OHOS_ABILITY_SLICE_SCHEDULER_H
|
||||
|
||||
#include <want.h>
|
||||
|
||||
#include "ability_slice_manager.h"
|
||||
#include "ability_slice_route.h"
|
||||
#include "ability_slice_stack.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilitySliceScheduler {
|
||||
public:
|
||||
explicit AbilitySliceScheduler(AbilitySliceManager &abilitySliceManager);
|
||||
~AbilitySliceScheduler();
|
||||
|
||||
void HandleStartAbilitySlice(const Want &want);
|
||||
void HandleInactiveAbilitySlice();
|
||||
void HandleActiveAbilitySlice(const Want &want);
|
||||
void HandleMoveAbilitySliceToBackground();
|
||||
void HandleStopAbilitySlice();
|
||||
|
||||
void AddAbilitySlice(const AbilitySlice &caller, AbilitySlice &target, const Want &want);
|
||||
void RemoveAbilitySlice(AbilitySlice &slice);
|
||||
|
||||
void SetMainRoute(const std::string &entry);
|
||||
void AddActionRoute(const std::string &action, const std::string &entry);
|
||||
|
||||
const std::string GetSliceStackInfo() const;
|
||||
private:
|
||||
AbilitySlice *GetTargetAbilitySlice() const;
|
||||
bool CheckLegalForAdd(const AbilitySlice &caller, AbilitySlice &target, const Want &want);
|
||||
bool CheckLegalForRemove(const AbilitySlice &slice);
|
||||
|
||||
AbilitySliceRoute *abilitySliceRoute_ { nullptr };
|
||||
AbilitySliceStack *abilitySliceStack_ { nullptr };
|
||||
AbilitySlice *topAbilitySlice_ { nullptr };
|
||||
AbilitySliceManager &abilitySliceManager_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_SLICE_SCHEDULER_H
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_SLICE_STACK_H
|
||||
#define OHOS_ABILITY_SLICE_STACK_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilitySlice;
|
||||
|
||||
class AbilitySliceStack : public NoCopyable {
|
||||
public:
|
||||
AbilitySliceStack() = default;
|
||||
~AbilitySliceStack() override;
|
||||
|
||||
bool IsEmpty() const;
|
||||
int Size() const;
|
||||
bool Exist(const AbilitySlice *slice) const;
|
||||
void Remove(AbilitySlice *slice);
|
||||
const AbilitySlice *Top() const;
|
||||
AbilitySlice *Pop();
|
||||
void Push(AbilitySlice *slice);
|
||||
std::list<AbilitySlice *> GetAllSlices() const;
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
std::list<AbilitySlice *> slices_ {};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // OHOS_ABILITY_SLICE_STACK_H
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_THREAD_H
|
||||
#define OHOS_ABILITY_THREAD_H
|
||||
|
||||
#include <ability.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "abilityms_client.h"
|
||||
#include "ability_scheduler.h"
|
||||
#include "ability_event_handler.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityThread : public Scheduler, public NoCopyable {
|
||||
public:
|
||||
~AbilityThread() override;
|
||||
static void ThreadMain(uint64_t token);
|
||||
|
||||
private:
|
||||
AbilityThread() = default;
|
||||
|
||||
void PerformAppInit(const AppInfo &appInfo) override;
|
||||
void PerformAppExit() override;
|
||||
void PerformTransactAbilityState(const Want &want, int state, uint64_t token, int abilityType) override;
|
||||
void PerformConnectAbility(const Want &want, uint64_t token) override;
|
||||
void PerformDisconnectAbility(const Want &want, uint64_t token) override;
|
||||
void PerformDumpAbility(const Want &want, uint64_t token) override;
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
static void *UITaskPost(void *arg);
|
||||
void InitUITaskEnv();
|
||||
#endif
|
||||
void StartAbilityCallback(const Want &want);
|
||||
static void HandleLifecycleTransaction(Ability &ability, const Want &want, int state);
|
||||
void AttachBundle(uint64_t token);
|
||||
void Run();
|
||||
|
||||
AbilityEventHandler *eventHandler_ { nullptr };
|
||||
AbilityScheduler *abilityScheduler_ { nullptr };
|
||||
std::map<uint64_t, Ability *> abilities_ {};
|
||||
SvcIdentity *identity_ { nullptr };
|
||||
std::list<void *> handle_ {};
|
||||
static bool isNativeApp_;
|
||||
static bool isAppRunning_;
|
||||
static bool isDisplayInited_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_THREAD_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_WINDOW_H
|
||||
#define OHOS_ABILITY_WINDOW_H
|
||||
|
||||
#include <window/window.h>
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityWindow : public NoCopyable {
|
||||
public:
|
||||
AbilityWindow() = default;
|
||||
~AbilityWindow() override = default;
|
||||
|
||||
void SetRootView(RootView *rootView, int16_t x = 0, int16_t y = 0);
|
||||
|
||||
void OnPostAbilityStart();
|
||||
void OnPostAbilityActive();
|
||||
void OnPostAbilityBackground();
|
||||
void OnPostAbilityStop();
|
||||
private:
|
||||
void EnsureLatestUIAttached() const;
|
||||
|
||||
Window *window_ { nullptr };
|
||||
bool isWindowAttached_ { false };
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_WINDOW_H
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_APP_INFO_H
|
||||
#define OHOS_APP_INFO_H
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
typedef struct {
|
||||
std::string bundleName;
|
||||
std::string srcPath;
|
||||
std::string dataPath;
|
||||
bool isNativeApp;
|
||||
std::list<std::string> moduleNames;
|
||||
} AppInfo;
|
||||
|
||||
#endif // OHOS_APP_INFO_H
|
||||
Executable
+285
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability.h"
|
||||
|
||||
#include <ability_kit_command.h>
|
||||
#include <ability_state.h>
|
||||
#include <log.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "ability_loader.h"
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
#include "ability_slice_manager.h"
|
||||
#include "ability_window.h"
|
||||
#endif
|
||||
#include "adapter.h"
|
||||
#include "liteipc_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
void Ability::OnStart(const Want &want)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Ability OnStart");
|
||||
if (abilityState_ != STATE_INITIAL) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "Start ability error, state: %{public}d", abilityState_);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
DeliverAbilityLifecycle(START, &want);
|
||||
if (abilityWindow_ != nullptr) {
|
||||
abilityWindow_->OnPostAbilityStart();
|
||||
}
|
||||
#endif
|
||||
abilityState_ = STATE_INACTIVE;
|
||||
}
|
||||
|
||||
void Ability::OnInactive()
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Ability OnInactive");
|
||||
if (abilityState_ != STATE_ACTIVE) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "Inactive ability error, state: %{public}d", abilityState_);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
DeliverAbilityLifecycle(INACTIVE);
|
||||
#endif
|
||||
abilityState_ = STATE_INACTIVE;
|
||||
}
|
||||
|
||||
void Ability::OnActive(const Want &want)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Ability OnActive");
|
||||
if ((abilityState_ != STATE_INACTIVE) && (abilityState_ != STATE_BACKGROUND)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "Active ability error, state: %{public}d", abilityState_);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
DeliverAbilityLifecycle(ACTIVE, &want);
|
||||
if ((abilityWindow_ != nullptr) && (abilityState_ == STATE_BACKGROUND)) {
|
||||
abilityWindow_->OnPostAbilityActive();
|
||||
}
|
||||
#endif
|
||||
abilityState_ = STATE_ACTIVE;
|
||||
}
|
||||
|
||||
void Ability::OnBackground()
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Ability OnBackground");
|
||||
if (abilityState_ != STATE_INACTIVE) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "Background ability error, state: %{public}d", abilityState_);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
DeliverAbilityLifecycle(BACKGROUND);
|
||||
if (abilityWindow_ != nullptr) {
|
||||
abilityWindow_->OnPostAbilityBackground();
|
||||
}
|
||||
#endif
|
||||
abilityState_ = STATE_BACKGROUND;
|
||||
}
|
||||
|
||||
void Ability::OnStop()
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Ability OnStop");
|
||||
if (abilityState_ != STATE_BACKGROUND) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "Stop ability error, state: %{public}d", abilityState_);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
DeliverAbilityLifecycle(STOP);
|
||||
if (abilityWindow_ != nullptr) {
|
||||
abilityWindow_->OnPostAbilityStop();
|
||||
delete abilityWindow_;
|
||||
}
|
||||
delete abilitySliceManager_;
|
||||
abilitySliceManager_ = nullptr;
|
||||
abilityWindow_ = nullptr;
|
||||
#endif
|
||||
abilityState_ = STATE_INITIAL;
|
||||
}
|
||||
|
||||
const SvcIdentity *Ability::OnConnect(const Want &want)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Ability Connect");
|
||||
sid_ = static_cast<SvcIdentity *>(AdapterMalloc(sizeof(SvcIdentity)));
|
||||
if (sid_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "malloc memory error, sid_ is null");
|
||||
return nullptr;
|
||||
}
|
||||
int32_t ret = RegisterIpcCallback(Ability::MsgHandleInner, 0, IPC_WAIT_FOREVER, sid_, this);
|
||||
if (ret != 0) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "register ipc callback error, ret is %{public}d", ret);
|
||||
AdapterFree(sid_);
|
||||
sid_ = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
return sid_;
|
||||
}
|
||||
|
||||
void Ability::OnDisconnect(const Want &want)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Ability OnDisconnect");
|
||||
|
||||
// clear
|
||||
UnregisterIpcCallback(*sid_);
|
||||
AdapterFree(sid_);
|
||||
sid_ = nullptr;
|
||||
}
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
void Ability::SetMainRoute(const std::string &entry)
|
||||
{
|
||||
if (abilitySliceManager_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "AbilitySliceManager is null, fail to set main route");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
abilitySliceManager_->SetMainRoute(entry);
|
||||
}
|
||||
|
||||
void Ability::SetUIContent(RootView *rootView)
|
||||
{
|
||||
if (abilityWindow_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "AbilityWindow is null, fail to SetUIContent");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
abilityWindow_->SetRootView(rootView);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Ability::MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply)
|
||||
{
|
||||
}
|
||||
|
||||
void Ability::Dump(const std::string &extra)
|
||||
{
|
||||
}
|
||||
|
||||
void Ability::Init(uint64_t token, int abilityType, bool isNativeApp)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Ability Init");
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
if (abilityType == PAGE) {
|
||||
if (isNativeApp) {
|
||||
abilitySliceManager_ = new AbilitySliceManager(*this);
|
||||
}
|
||||
abilityWindow_ = new AbilityWindow();
|
||||
}
|
||||
#endif
|
||||
|
||||
abilityType_ = abilityType;
|
||||
token_ = token;
|
||||
AbilityContext::token_ = token;
|
||||
abilityState_ = STATE_INITIAL;
|
||||
}
|
||||
|
||||
int Ability::GetState() const
|
||||
{
|
||||
return abilityState_;
|
||||
}
|
||||
|
||||
std::string Ability::GetDumpInfo() const
|
||||
{
|
||||
std::string dumpInfo;
|
||||
dumpInfo += "Ability Type: [" + std::to_string(abilityType_) + "]\n";
|
||||
dumpInfo += "Ability State: [" + std::to_string(abilityState_) + "]\n";
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
dumpInfo += "AbilitySlice stack:\n";
|
||||
if ((abilityType_ == PAGE) && (abilitySliceManager_ != nullptr)) {
|
||||
// Add slice stack information
|
||||
dumpInfo += abilitySliceManager_->GetSliceStackInfo();
|
||||
} else {
|
||||
dumpInfo += " none";
|
||||
}
|
||||
#endif
|
||||
|
||||
return dumpInfo;
|
||||
}
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
void Ability::DeliverAbilityLifecycle(Action action, const Want *want)
|
||||
{
|
||||
if (abilitySliceManager_ == nullptr) {
|
||||
HILOG_WARN(HILOG_MODULE_APP, "AbilitySliceManager is null, no need to dispatch lifecycle state change");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((action == START || action == ACTIVE) && want == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "want is null");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case START:
|
||||
abilitySliceManager_->OnAbilityStart(*want);
|
||||
break;
|
||||
case INACTIVE:
|
||||
abilitySliceManager_->OnAbilityInactive();
|
||||
break;
|
||||
case ACTIVE:
|
||||
abilitySliceManager_->OnAbilityActive(*want);
|
||||
break;
|
||||
case BACKGROUND:
|
||||
abilitySliceManager_->OnAbilityBackground();
|
||||
break;
|
||||
case STOP:
|
||||
abilitySliceManager_->OnAbilityStop();
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "action is error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t Ability::MsgHandleInner(const IpcContext* context, void *ipcMsg, IpcIo *data, void *arg)
|
||||
{
|
||||
auto ability = static_cast<Ability *>(arg);
|
||||
if (ability == nullptr) {
|
||||
HILOG_INFO(HILOG_MODULE_APP, "handle message error, ability is null");
|
||||
FreeBuffer(nullptr, ipcMsg);
|
||||
return LITEIPC_EINVAL;
|
||||
}
|
||||
uint32_t fundId = 0;
|
||||
int32_t ret = GetCode(ipcMsg, &fundId);
|
||||
if (ret == LITEIPC_EINVAL) {
|
||||
FreeBuffer(nullptr, ipcMsg);
|
||||
return LITEIPC_EINVAL;
|
||||
}
|
||||
|
||||
IpcIo reply;
|
||||
char buffer[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&reply, buffer, IPC_IO_DATA_MAX, MAX_OBJECTS);
|
||||
|
||||
// call user method
|
||||
ability->MsgHandle(fundId, data, &reply);
|
||||
|
||||
uint32_t flag = 0;
|
||||
GetFlag(ipcMsg, &flag);
|
||||
if (flag == LITEIPC_FLAG_DEFAULT) {
|
||||
SendReply(nullptr, ipcMsg, &reply);
|
||||
} else {
|
||||
FreeBuffer(nullptr, ipcMsg);
|
||||
}
|
||||
return LITEIPC_OK;
|
||||
}
|
||||
} // namespace OHOS
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_context.h"
|
||||
|
||||
#include "ability_service_interface.h"
|
||||
#include "ability_service_manager.h"
|
||||
#include "abilityms_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
int AbilityContext::StartAbility(const Want &want)
|
||||
{
|
||||
return AbilityMsClient::GetInstance().ScheduleAms(&want, 0, nullptr, START_ABILITY);
|
||||
}
|
||||
|
||||
int AbilityContext::TerminateAbility()
|
||||
{
|
||||
return AbilityMsClient::GetInstance().ScheduleAms(nullptr, token_, nullptr, TERMINATE_ABILITY);
|
||||
}
|
||||
|
||||
int AbilityContext::StopAbility(const Want &want)
|
||||
{
|
||||
return AbilityMsClient::GetInstance().ScheduleAms(&want, 0, nullptr, TERMINATE_SERVICE);
|
||||
}
|
||||
|
||||
int AbilityContext::ConnectAbility(const Want &want, const IAbilityConnection &conn, void *storeArg)
|
||||
{
|
||||
return AbilityServiceManager::GetInstance().ConnectAbility(want, conn, token_, storeArg);
|
||||
}
|
||||
|
||||
int AbilityContext::DisconnectAbility(const IAbilityConnection &conn)
|
||||
{
|
||||
return AbilityServiceManager::GetInstance().DisconnectAbility(conn, token_);
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#include "ability_env.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ability_env_impl.h"
|
||||
|
||||
extern "C" {
|
||||
const char *GetBundleName()
|
||||
{
|
||||
const std::string &bundleName = OHOS::AbilityEnvImpl::GetInstance().GetBundleName();
|
||||
return bundleName.c_str();
|
||||
}
|
||||
|
||||
const char *GetSrcPath()
|
||||
{
|
||||
const std::string &srcPath = OHOS::AbilityEnvImpl::GetInstance().GetSrcPath();
|
||||
return srcPath.c_str();
|
||||
}
|
||||
|
||||
const char *GetDataPath()
|
||||
{
|
||||
const std::string &dataPath = OHOS::AbilityEnvImpl::GetInstance().GetDataPath();
|
||||
return dataPath.c_str();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_env_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
constexpr static char PATH_SEPARATOR[] = "/";
|
||||
|
||||
void AbilityEnvImpl::SetAppInfo(const AppInfo& appInfo)
|
||||
{
|
||||
bundleName_ = appInfo.bundleName;
|
||||
dataPath_ = appInfo.dataPath;
|
||||
srcPath_ = appInfo.srcPath;
|
||||
if (!appInfo.isNativeApp && !appInfo.moduleNames.empty()) {
|
||||
srcPath_ += PATH_SEPARATOR + appInfo.moduleNames.front();
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& AbilityEnvImpl::GetBundleName() const
|
||||
{
|
||||
return bundleName_;
|
||||
}
|
||||
|
||||
const std::string& AbilityEnvImpl::GetSrcPath() const
|
||||
{
|
||||
return srcPath_;
|
||||
}
|
||||
|
||||
const std::string& AbilityEnvImpl::GetDataPath() const
|
||||
{
|
||||
return dataPath_;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_event_handler.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
thread_local AbilityEventHandler* g_currentHandler;
|
||||
}
|
||||
|
||||
AbilityEventHandler::AbilityEventHandler()
|
||||
{
|
||||
g_currentHandler = this;
|
||||
(void) pthread_mutex_init(&queueMutex_, nullptr);
|
||||
(void) pthread_cond_init(&pthreadCond_, nullptr);
|
||||
}
|
||||
|
||||
AbilityEventHandler::~AbilityEventHandler()
|
||||
{
|
||||
(void) pthread_mutex_destroy(&queueMutex_);
|
||||
(void) pthread_cond_destroy(&pthreadCond_);
|
||||
|
||||
g_currentHandler = nullptr;
|
||||
}
|
||||
|
||||
void AbilityEventHandler::Run()
|
||||
{
|
||||
while (!quit_) {
|
||||
(void) pthread_mutex_lock(&queueMutex_);
|
||||
if (taskQueue_.empty()) {
|
||||
(void) pthread_cond_wait(&pthreadCond_, &queueMutex_);
|
||||
}
|
||||
Task task = std::move(taskQueue_.front());
|
||||
taskQueue_.pop();
|
||||
(void) pthread_mutex_unlock(&queueMutex_);
|
||||
task();
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityEventHandler::PostTask(const Task& task)
|
||||
{
|
||||
(void) pthread_mutex_lock(&queueMutex_);
|
||||
taskQueue_.push(task);
|
||||
(void) pthread_mutex_unlock(&queueMutex_);
|
||||
|
||||
(void) pthread_cond_signal(&pthreadCond_);
|
||||
}
|
||||
|
||||
void AbilityEventHandler::PostQuit()
|
||||
{
|
||||
Task task = [this]() {
|
||||
quit_ = true;
|
||||
};
|
||||
PostTask(task);
|
||||
}
|
||||
|
||||
AbilityEventHandler* AbilityEventHandler::GetCurrentHandler()
|
||||
{
|
||||
return g_currentHandler;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
void AbilityLoader::RegisterAbility(const std::string &abilityName, const CreateAblity &createFunc)
|
||||
{
|
||||
abilities_.emplace(abilityName, createFunc);
|
||||
HILOG_INFO(HILOG_MODULE_APP, "RegisterAbility %s", abilityName.c_str());
|
||||
}
|
||||
|
||||
Ability *AbilityLoader::GetAbilityByName(const std::string &abilityName)
|
||||
{
|
||||
auto it = abilities_.find(abilityName);
|
||||
if (it == abilities_.end()) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "GetAbilityByName failed: %s", abilityName.c_str());
|
||||
return nullptr;
|
||||
} else {
|
||||
return it->second();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
void AbilityLoader::RegisterAbilitySlice(const std::string &sliceName, const CreateSlice &createFunc)
|
||||
{
|
||||
slices_.emplace(sliceName, createFunc);
|
||||
HILOG_INFO(HILOG_MODULE_APP, "RegisterAbilitySlice %s", sliceName.c_str());
|
||||
}
|
||||
|
||||
AbilitySlice *AbilityLoader::GetAbilitySliceByName(const std::string &sliceName)
|
||||
{
|
||||
auto it = slices_.find(sliceName);
|
||||
if (it == slices_.end()) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "GetAbilitySliceByName failed: %s", sliceName.c_str());
|
||||
return nullptr;
|
||||
} else {
|
||||
return it->second();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_main.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <climits>
|
||||
|
||||
#include "ability_thread.h"
|
||||
#include "liteipc_pri.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace {
|
||||
constexpr int HEX = 10;
|
||||
}
|
||||
|
||||
int AbilityMain(const char *token)
|
||||
{
|
||||
if (token == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ResetLiteIpc();
|
||||
char *endPtr = nullptr;
|
||||
errno = 0;
|
||||
uint64_t tokenId = std::strtoull(token, &endPtr, HEX);
|
||||
if ((errno == ERANGE && tokenId == ULLONG_MAX) || (errno != 0 && tokenId == 0) ||
|
||||
endPtr == nullptr || *endPtr != '\0') {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "token is invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
OHOS::AbilityThread::ThreadMain(tokenId);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_scheduler.h"
|
||||
|
||||
#include <log.h>
|
||||
#include <utils.h>
|
||||
|
||||
#include "ability_errors.h"
|
||||
#include "ability_kit_command.h"
|
||||
#include "ability_service_interface.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "want_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
const int MAX_MODULE_SIZE = 16;
|
||||
AbilityScheduler::AbilityScheduler(AbilityEventHandler &eventHandler, Scheduler &scheduler)
|
||||
: eventHandler_(eventHandler), scheduler_(scheduler)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t AbilityScheduler::AmsCallback(const IpcContext* context, void *ipcMsg, IpcIo *data, void *arg)
|
||||
{
|
||||
if (ipcMsg == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "ams call back error, ipcMsg is null");
|
||||
return PARAM_NULL_ERROR;
|
||||
}
|
||||
|
||||
auto scheduler = static_cast<AbilityScheduler *>(arg);
|
||||
if (scheduler == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "ams call back error, scheduler is null");
|
||||
// if you need to send reply to the client, please use SendReply method
|
||||
ClearIpcMsg(ipcMsg);
|
||||
return PARAM_NULL_ERROR;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
uint32_t funcId = COMMAND_ERROR;
|
||||
GetCode(ipcMsg, &funcId);
|
||||
switch (funcId) {
|
||||
case SCHEDULER_APP_INIT: {
|
||||
AppInfo appInfo = {};
|
||||
char *bundleName = reinterpret_cast<char *>(IpcIoPopString(data, nullptr));
|
||||
char *srcPath = reinterpret_cast<char *>(IpcIoPopString(data, nullptr));
|
||||
char *dataPath = reinterpret_cast<char *>(IpcIoPopString(data, nullptr));
|
||||
if ((bundleName == nullptr) || (srcPath == nullptr) || (dataPath == nullptr)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "ams call back error, bundleName, srcPath or dataPath is null");
|
||||
ClearIpcMsg(ipcMsg);
|
||||
return PARAM_NULL_ERROR;
|
||||
}
|
||||
appInfo.bundleName = bundleName;
|
||||
appInfo.srcPath = srcPath;
|
||||
appInfo.dataPath = dataPath;
|
||||
appInfo.isNativeApp = IpcIoPopBool(data);
|
||||
int moduleSize = IpcIoPopInt32(data);
|
||||
if (moduleSize > MAX_MODULE_SIZE) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "moduleSize is too big");
|
||||
ClearIpcMsg(ipcMsg);
|
||||
return COMMAND_ERROR;
|
||||
}
|
||||
for (int i = 0; i < moduleSize; i++) {
|
||||
char *moduleName = reinterpret_cast<char *>(IpcIoPopString(data, nullptr));
|
||||
if ((moduleName != nullptr) && (strlen(moduleName) > 0)) {
|
||||
appInfo.moduleNames.emplace_front(moduleName);
|
||||
}
|
||||
}
|
||||
scheduler->PerformAppInit(appInfo);
|
||||
break;
|
||||
}
|
||||
case SCHEDULER_ABILITY_LIFECYCLE: {
|
||||
int state = IpcIoPopInt32(data);
|
||||
uint64_t token = IpcIoPopUint64(data);
|
||||
int abilityType = IpcIoPopInt32(data);
|
||||
Want want = { nullptr, nullptr, nullptr, 0 };
|
||||
if (!DeserializeWant(&want, data)) {
|
||||
result = SERIALIZE_ERROR;
|
||||
break;
|
||||
}
|
||||
scheduler->PerformTransactAbilityState(want, state, token, abilityType);
|
||||
break;
|
||||
}
|
||||
case SCHEDULER_ABILITY_CONNECT: {
|
||||
uint64_t token = IpcIoPopUint64(data);
|
||||
Want want = { nullptr, nullptr, nullptr, 0 };
|
||||
if (!DeserializeWant(&want, data)) {
|
||||
result = SERIALIZE_ERROR;
|
||||
break;
|
||||
}
|
||||
scheduler->PerformConnectAbility(want, token);
|
||||
break;
|
||||
}
|
||||
case SCHEDULER_ABILITY_DISCONNECT: {
|
||||
uint64_t token = IpcIoPopUint64(data);
|
||||
Want want = { nullptr, nullptr, nullptr, 0 };
|
||||
if (!DeserializeWant(&want, data)) {
|
||||
result = SERIALIZE_ERROR;
|
||||
break;
|
||||
}
|
||||
scheduler->PerformDisconnectAbility(want, token);
|
||||
break;
|
||||
}
|
||||
case SCHEDULER_APP_EXIT: {
|
||||
scheduler->PerformAppExit();
|
||||
break;
|
||||
}
|
||||
case SCHEDULER_DUMP_ABILITY: {
|
||||
Want want = {};
|
||||
if (!DeserializeWant(&want, data)) {
|
||||
result = SERIALIZE_ERROR;
|
||||
break;
|
||||
}
|
||||
uint64_t token = IpcIoPopUint64(data);
|
||||
scheduler->PerformDumpAbility(want, token);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
result = COMMAND_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ClearIpcMsg(ipcMsg);
|
||||
return result;
|
||||
}
|
||||
|
||||
void AbilityScheduler::PerformAppInit(const AppInfo &appInfo)
|
||||
{
|
||||
auto task = [this, appInfo] {
|
||||
scheduler_.PerformAppInit(appInfo);
|
||||
};
|
||||
eventHandler_.PostTask(task);
|
||||
}
|
||||
|
||||
void AbilityScheduler::PerformTransactAbilityState(const Want &want, int state, uint64_t token, int abilityType)
|
||||
{
|
||||
auto task = [this, want, state, token, abilityType] {
|
||||
scheduler_.PerformTransactAbilityState(want, state, token, abilityType);
|
||||
ClearWant(const_cast<Want *>(&want));
|
||||
};
|
||||
eventHandler_.PostTask(task);
|
||||
}
|
||||
|
||||
void AbilityScheduler::PerformConnectAbility(const Want &want, uint64_t token)
|
||||
{
|
||||
auto task = [this, want, token] {
|
||||
scheduler_.PerformConnectAbility(want, token);
|
||||
ClearWant(const_cast<Want *>(&want));
|
||||
};
|
||||
eventHandler_.PostTask(task);
|
||||
}
|
||||
|
||||
void AbilityScheduler::PerformDisconnectAbility(const Want &want, uint64_t token)
|
||||
{
|
||||
auto task = [this, want, token] {
|
||||
scheduler_.PerformDisconnectAbility(want, token);
|
||||
ClearWant(const_cast<Want *>(&want));
|
||||
};
|
||||
eventHandler_.PostTask(task);
|
||||
}
|
||||
|
||||
void AbilityScheduler::PerformAppExit()
|
||||
{
|
||||
auto task = [this] {
|
||||
scheduler_.PerformAppExit();
|
||||
};
|
||||
eventHandler_.PostTask(task);
|
||||
}
|
||||
|
||||
void AbilityScheduler::PerformDumpAbility(const Want &want, uint64_t token)
|
||||
{
|
||||
#ifdef __LINUX__
|
||||
if (want.sid == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "svcId is invalid when dump ability");
|
||||
return;
|
||||
}
|
||||
BinderAcquire(want.sid->ipcContext, want.sid->handle);
|
||||
#endif
|
||||
auto task = [this, want, token] {
|
||||
scheduler_.PerformDumpAbility(want, token);
|
||||
ClearWant(const_cast<Want *>(&want));
|
||||
};
|
||||
eventHandler_.PostTask(task);
|
||||
}
|
||||
|
||||
void AbilityScheduler::ClearIpcMsg(void *ipcMsg)
|
||||
{
|
||||
if (ipcMsg == nullptr) {
|
||||
return;
|
||||
}
|
||||
uint32_t flag = 0;
|
||||
GetFlag(ipcMsg, &flag);
|
||||
if (flag == LITEIPC_FLAG_DEFAULT) {
|
||||
// send reply to client, the second param is reply
|
||||
SendReply(nullptr, ipcMsg, nullptr);
|
||||
} else {
|
||||
FreeBuffer(nullptr, ipcMsg);
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_slice.h"
|
||||
|
||||
#include <ability_state.h>
|
||||
#include <log.h>
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "ability_slice_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
void AbilitySlice::Init(AbilitySliceManager &abilitySliceManager)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice Init");
|
||||
abilitySliceManager_ = &abilitySliceManager;
|
||||
sliceState_ = STATE_INITIAL;
|
||||
AbilityContext::token_ = abilitySliceManager.GetToken();
|
||||
}
|
||||
|
||||
void AbilitySlice::Present(AbilitySlice &abilitySlice, const Want &want)
|
||||
{
|
||||
if (abilitySliceManager_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "AbilitySlice Present failed");
|
||||
return;
|
||||
}
|
||||
abilitySliceManager_->Present(*this, abilitySlice, want);
|
||||
}
|
||||
|
||||
void AbilitySlice::Terminate()
|
||||
{
|
||||
if (abilitySliceManager_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "AbilitySlice Terminate failed");
|
||||
return;
|
||||
}
|
||||
abilitySliceManager_->Terminate(*this);
|
||||
}
|
||||
|
||||
void AbilitySlice::SetUIContent(RootView *rootView)
|
||||
{
|
||||
if (abilitySliceManager_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "AbilitySlice SetUIContent failed");
|
||||
return;
|
||||
}
|
||||
curRootView_ = rootView;
|
||||
abilitySliceManager_->SetUIContent(rootView);
|
||||
}
|
||||
|
||||
void AbilitySlice::OnStart(const Want &want)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice OnStart");
|
||||
sliceState_ = STATE_INACTIVE;
|
||||
}
|
||||
|
||||
void AbilitySlice::OnInactive()
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice OnInactive");
|
||||
sliceState_ = STATE_INACTIVE;
|
||||
}
|
||||
|
||||
void AbilitySlice::OnActive(const Want &want)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice OnActive");
|
||||
if ((sliceState_ == STATE_BACKGROUND) && (curRootView_ != nullptr)) {
|
||||
SetUIContent(curRootView_);
|
||||
}
|
||||
sliceState_ = STATE_ACTIVE;
|
||||
}
|
||||
|
||||
void AbilitySlice::OnBackground()
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice OnBackground");
|
||||
sliceState_ = STATE_BACKGROUND;
|
||||
}
|
||||
|
||||
void AbilitySlice::OnStop()
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "AbilitySlice OnStop");
|
||||
sliceState_ = STATE_INITIAL;
|
||||
}
|
||||
|
||||
int AbilitySlice::GetState() const
|
||||
{
|
||||
return sliceState_;
|
||||
}
|
||||
} // namespace OHOS
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_slice_manager.h"
|
||||
|
||||
#include <ability.h>
|
||||
|
||||
#include "ability_slice_scheduler.h"
|
||||
#include "ability_window.h"
|
||||
|
||||
namespace OHOS {
|
||||
AbilitySliceManager::AbilitySliceManager(Ability &ability) : ability_(ability)
|
||||
{
|
||||
abilitySliceScheduler_ = new AbilitySliceScheduler(*this);
|
||||
}
|
||||
|
||||
AbilitySliceManager::~AbilitySliceManager()
|
||||
{
|
||||
delete abilitySliceScheduler_;
|
||||
abilitySliceScheduler_ = nullptr;
|
||||
}
|
||||
|
||||
void AbilitySliceManager::OnAbilityStart(const Want &want)
|
||||
{
|
||||
abilitySliceScheduler_->HandleStartAbilitySlice(want);
|
||||
}
|
||||
|
||||
void AbilitySliceManager::OnAbilityInactive()
|
||||
{
|
||||
abilitySliceScheduler_->HandleInactiveAbilitySlice();
|
||||
}
|
||||
|
||||
void AbilitySliceManager::OnAbilityActive(const Want &want)
|
||||
{
|
||||
abilitySliceScheduler_->HandleActiveAbilitySlice(want);
|
||||
}
|
||||
|
||||
void AbilitySliceManager::OnAbilityBackground()
|
||||
{
|
||||
abilitySliceScheduler_->HandleMoveAbilitySliceToBackground();
|
||||
}
|
||||
|
||||
void AbilitySliceManager::OnAbilityStop()
|
||||
{
|
||||
abilitySliceScheduler_->HandleStopAbilitySlice();
|
||||
}
|
||||
|
||||
void AbilitySliceManager::Present(const AbilitySlice &caller, AbilitySlice &target, const Want &want)
|
||||
{
|
||||
abilitySliceScheduler_->AddAbilitySlice(caller, target, want);
|
||||
}
|
||||
|
||||
void AbilitySliceManager::Terminate(AbilitySlice &slice)
|
||||
{
|
||||
abilitySliceScheduler_->RemoveAbilitySlice(slice);
|
||||
}
|
||||
|
||||
void AbilitySliceManager::SetMainRoute(const std::string &entry)
|
||||
{
|
||||
abilitySliceScheduler_->SetMainRoute(entry);
|
||||
}
|
||||
|
||||
void AbilitySliceManager::AddActionRoute(const std::string &action, const std::string &entry)
|
||||
{
|
||||
abilitySliceScheduler_->AddActionRoute(action, entry);
|
||||
}
|
||||
|
||||
void AbilitySliceManager::SetUIContent(RootView *rootView)
|
||||
{
|
||||
ability_.SetUIContent(rootView);
|
||||
}
|
||||
|
||||
int AbilitySliceManager::GetAbilityState()
|
||||
{
|
||||
return ability_.GetState();
|
||||
}
|
||||
|
||||
int AbilitySliceManager::TerminateAbility()
|
||||
{
|
||||
return ability_.TerminateAbility();
|
||||
}
|
||||
|
||||
std::string AbilitySliceManager::GetSliceStackInfo() const
|
||||
{
|
||||
return abilitySliceScheduler_->GetSliceStackInfo();
|
||||
}
|
||||
|
||||
uint64_t AbilitySliceManager::GetToken() const
|
||||
{
|
||||
return ability_.token_;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_slice_route.h"
|
||||
|
||||
namespace OHOS {
|
||||
AbilitySliceRoute::~AbilitySliceRoute()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void AbilitySliceRoute::SetMainRoute(const std::string &entry)
|
||||
{
|
||||
if (entry.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainEntry_ = entry;
|
||||
}
|
||||
|
||||
const std::string &AbilitySliceRoute::GetMainRoute() const
|
||||
{
|
||||
return mainEntry_;
|
||||
}
|
||||
|
||||
void AbilitySliceRoute::AddActionRoute(const std::string &action, const std::string &entry)
|
||||
{
|
||||
if (action.empty() || entry.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
actionEntries_[action] = entry;
|
||||
}
|
||||
|
||||
std::string AbilitySliceRoute::MatchRoute(const std::string &action)
|
||||
{
|
||||
auto iter = actionEntries_.find(action);
|
||||
if (iter != actionEntries_.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void AbilitySliceRoute::Clear()
|
||||
{
|
||||
mainEntry_.clear();
|
||||
actionEntries_.clear();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_slice_scheduler.h"
|
||||
|
||||
#include <ability_state.h>
|
||||
#include <log.h>
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "ability_slice_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
AbilitySliceScheduler::AbilitySliceScheduler(AbilitySliceManager &abilitySliceManager)
|
||||
: abilitySliceManager_(abilitySliceManager)
|
||||
{
|
||||
abilitySliceRoute_ = new AbilitySliceRoute();
|
||||
abilitySliceStack_ = new AbilitySliceStack();
|
||||
}
|
||||
|
||||
AbilitySliceScheduler::~AbilitySliceScheduler()
|
||||
{
|
||||
delete abilitySliceRoute_;
|
||||
abilitySliceRoute_ = nullptr;
|
||||
delete abilitySliceStack_;
|
||||
abilitySliceStack_ = nullptr;
|
||||
}
|
||||
|
||||
void AbilitySliceScheduler::HandleStartAbilitySlice(const Want &want)
|
||||
{
|
||||
if (topAbilitySlice_ == nullptr) {
|
||||
topAbilitySlice_ = GetTargetAbilitySlice();
|
||||
if (topAbilitySlice_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "Cannot get slice [%{public}s]", abilitySliceRoute_->GetMainRoute().c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
topAbilitySlice_->Init(abilitySliceManager_);
|
||||
|
||||
topAbilitySlice_->OnStart(want);
|
||||
}
|
||||
|
||||
void AbilitySliceScheduler::HandleInactiveAbilitySlice()
|
||||
{
|
||||
if (topAbilitySlice_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
topAbilitySlice_->OnInactive();
|
||||
}
|
||||
|
||||
void AbilitySliceScheduler::HandleActiveAbilitySlice(const Want &want)
|
||||
{
|
||||
if (topAbilitySlice_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "top ability slice is null, active slice error");
|
||||
return;
|
||||
}
|
||||
|
||||
// add want when implicit match, not support jump by want temporary.
|
||||
|
||||
topAbilitySlice_->OnActive(want);
|
||||
}
|
||||
|
||||
void AbilitySliceScheduler::HandleMoveAbilitySliceToBackground()
|
||||
{
|
||||
if (topAbilitySlice_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
topAbilitySlice_->OnBackground();
|
||||
}
|
||||
|
||||
void AbilitySliceScheduler::HandleStopAbilitySlice()
|
||||
{
|
||||
if (topAbilitySlice_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
topAbilitySlice_->OnStop();
|
||||
while (!abilitySliceStack_->IsEmpty()) {
|
||||
auto abilitySlice = abilitySliceStack_->Pop();
|
||||
if (abilitySlice != nullptr) {
|
||||
abilitySlice->OnStop();
|
||||
}
|
||||
}
|
||||
delete topAbilitySlice_;
|
||||
topAbilitySlice_ = nullptr;
|
||||
}
|
||||
|
||||
void AbilitySliceScheduler::AddAbilitySlice(const AbilitySlice &caller, AbilitySlice &target, const Want &want)
|
||||
{
|
||||
// Check if this jump is legal.
|
||||
if (!CheckLegalForAdd(caller, target, want)) {
|
||||
HILOG_WARN(HILOG_MODULE_APP, "Cannot jump to target AbilitySlice");
|
||||
return;
|
||||
}
|
||||
|
||||
// Scheduler top slice to inactive.
|
||||
if (topAbilitySlice_->GetState() == STATE_ACTIVE) {
|
||||
topAbilitySlice_->OnInactive();
|
||||
}
|
||||
|
||||
// Scheduler target slice to Active.
|
||||
if (target.GetState() == STATE_UNINITIALIZED) {
|
||||
target.Init(abilitySliceManager_);
|
||||
}
|
||||
if (target.GetState() == STATE_INITIAL) {
|
||||
target.OnStart(want);
|
||||
}
|
||||
target.OnActive(want);
|
||||
|
||||
// Scheduler top slice to background.
|
||||
if (topAbilitySlice_->GetState() == STATE_INACTIVE) {
|
||||
topAbilitySlice_->OnBackground();
|
||||
}
|
||||
|
||||
// Update the topAbilitySlice and stack.
|
||||
abilitySliceStack_->Push(topAbilitySlice_);
|
||||
topAbilitySlice_ = ⌖
|
||||
}
|
||||
|
||||
void AbilitySliceScheduler::RemoveAbilitySlice(AbilitySlice &slice)
|
||||
{
|
||||
// Check if this slice is legal.
|
||||
if (!CheckLegalForRemove(slice)) {
|
||||
HILOG_WARN(HILOG_MODULE_APP, "Cannot terminate target AbilitySlice");
|
||||
return;
|
||||
}
|
||||
|
||||
if (&slice == topAbilitySlice_) {
|
||||
// Scheduler the slice need to exit to inactive.
|
||||
topAbilitySlice_->OnInactive();
|
||||
|
||||
Want want { nullptr, nullptr, nullptr, 0 };
|
||||
// Scheduler the top slice in the stack to Active.
|
||||
auto next = abilitySliceStack_->Pop();
|
||||
if (next == nullptr) {
|
||||
topAbilitySlice_->OnActive(want);
|
||||
return;
|
||||
}
|
||||
next->OnActive(want);
|
||||
|
||||
// Scheduler the slice need to exit(State:initial).
|
||||
topAbilitySlice_->OnBackground();
|
||||
topAbilitySlice_->OnStop();
|
||||
|
||||
// Update the topAbilitySLice and stack.
|
||||
topAbilitySlice_ = next;
|
||||
} else {
|
||||
// Scheduler the background slice to stop
|
||||
slice.OnStop();
|
||||
abilitySliceStack_->Remove(&slice);
|
||||
}
|
||||
}
|
||||
|
||||
void AbilitySliceScheduler::SetMainRoute(const std::string &entry)
|
||||
{
|
||||
abilitySliceRoute_->SetMainRoute(entry);
|
||||
}
|
||||
|
||||
void AbilitySliceScheduler::AddActionRoute(const std::string &action, const std::string &entry)
|
||||
{
|
||||
abilitySliceRoute_->AddActionRoute(action, entry);
|
||||
}
|
||||
|
||||
AbilitySlice *AbilitySliceScheduler::GetTargetAbilitySlice() const
|
||||
{
|
||||
std::string mainEntry = abilitySliceRoute_->GetMainRoute();
|
||||
|
||||
return AbilityLoader::GetInstance().GetAbilitySliceByName(mainEntry);
|
||||
}
|
||||
|
||||
bool AbilitySliceScheduler::CheckLegalForAdd(const AbilitySlice &caller, AbilitySlice &target, const Want &want)
|
||||
{
|
||||
if (topAbilitySlice_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (abilitySliceManager_.GetAbilityState() != STATE_ACTIVE) {
|
||||
return false;
|
||||
}
|
||||
if (caller.GetState() <= STATE_INITIAL) {
|
||||
return false;
|
||||
}
|
||||
if (target.GetState() == STATE_ACTIVE) {
|
||||
return false;
|
||||
}
|
||||
if (&target == topAbilitySlice_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AbilitySliceScheduler::CheckLegalForRemove(const AbilitySlice &slice)
|
||||
{
|
||||
if (topAbilitySlice_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (abilitySliceManager_.GetAbilityState() != STATE_ACTIVE) {
|
||||
return false;
|
||||
}
|
||||
if ((!abilitySliceStack_->Exist(&slice)) && (&slice != topAbilitySlice_)) {
|
||||
return false;
|
||||
}
|
||||
if (slice.GetState() <= STATE_INITIAL) {
|
||||
return false;
|
||||
}
|
||||
if (abilitySliceStack_->IsEmpty()) {
|
||||
abilitySliceManager_.TerminateAbility();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string AbilitySliceScheduler::GetSliceStackInfo() const
|
||||
{
|
||||
if (topAbilitySlice_ == nullptr) {
|
||||
return " none";
|
||||
}
|
||||
std::string buff;
|
||||
buff += " [" + std::string(typeid(*topAbilitySlice_).name()) +
|
||||
"] State: [" + std::to_string(topAbilitySlice_->GetState()) + "]\n";
|
||||
auto slices = abilitySliceStack_->GetAllSlices();
|
||||
for (auto slice : slices) {
|
||||
buff += " [" + std::string(typeid(*slice).name()) + "] State: [" + std::to_string(slice->GetState()) + "]\n";
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_slice_stack.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "ability_slice.h"
|
||||
|
||||
namespace OHOS {
|
||||
AbilitySliceStack::~AbilitySliceStack()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
bool AbilitySliceStack::IsEmpty() const
|
||||
{
|
||||
return slices_.empty();
|
||||
}
|
||||
|
||||
int AbilitySliceStack::Size() const
|
||||
{
|
||||
return slices_.size();
|
||||
}
|
||||
|
||||
bool AbilitySliceStack::Exist(const AbilitySlice *slice) const
|
||||
{
|
||||
return std::find(slices_.begin(), slices_.end(), slice) != slices_.end();
|
||||
}
|
||||
|
||||
void AbilitySliceStack::Remove(AbilitySlice *slice)
|
||||
{
|
||||
slices_.remove(slice);
|
||||
}
|
||||
|
||||
const AbilitySlice *AbilitySliceStack::Top() const
|
||||
{
|
||||
if (slices_.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return slices_.front();
|
||||
}
|
||||
|
||||
AbilitySlice *AbilitySliceStack::Pop()
|
||||
{
|
||||
if (slices_.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AbilitySlice *topSlice = slices_.front();
|
||||
slices_.pop_front();
|
||||
return topSlice;
|
||||
}
|
||||
|
||||
void AbilitySliceStack::Push(AbilitySlice *slice)
|
||||
{
|
||||
slices_.push_front(slice);
|
||||
}
|
||||
|
||||
std::list<AbilitySlice *> AbilitySliceStack::GetAllSlices() const
|
||||
{
|
||||
return slices_;
|
||||
}
|
||||
|
||||
void AbilitySliceStack::Clear()
|
||||
{
|
||||
for (auto node : slices_) {
|
||||
delete node;
|
||||
}
|
||||
slices_.clear();
|
||||
}
|
||||
}
|
||||
+385
@@ -0,0 +1,385 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_thread.h"
|
||||
|
||||
#include <ability.h>
|
||||
#include <ability_kit_command.h>
|
||||
#include <ability_service_interface.h>
|
||||
#include <ability_state.h>
|
||||
#include <climits>
|
||||
#include <cstring>
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
#include <common/graphic_startup.h>
|
||||
#include <common/task_manager.h>
|
||||
#include <dock/screen_device_proxy.h>
|
||||
#include <font/ui_font_header.h>
|
||||
#include <sys/prctl.h>
|
||||
#endif
|
||||
#include <dlfcn.h>
|
||||
#include <kvstore_env.h>
|
||||
|
||||
#include "ability_env.h"
|
||||
#include "ability_env_impl.h"
|
||||
#include "ability_info.h"
|
||||
#include "ability_loader.h"
|
||||
#include "ability_service_interface.h"
|
||||
#include "adapter.h"
|
||||
#include "element_name_utils.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr static char PATH_SEPARATOR[] = "/";
|
||||
constexpr static char LIB_PREFIX[] = "/lib";
|
||||
constexpr static char LIB_SUFFIX[] = ".so";
|
||||
constexpr static char ACE_ABILITY_NAME[] = "AceAbility";
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
#ifdef OPENHARMONY_FONT_PATH
|
||||
constexpr static char FONT_PATH[] = "/storage/data/";
|
||||
#else
|
||||
constexpr static char FONT_PATH[] = "/sdcard/data/";
|
||||
#endif
|
||||
constexpr static int UI_TASK_HANDLER_PERIOD = 10 * 1000; // UI task execute period is 10ms
|
||||
constexpr static char UI_TASK_THREAD_NAME[] = "UITaskPost";
|
||||
static uint32_t g_fontPsramBaseAddr[MIN_FONT_PSRAM_LENGTH / 4];
|
||||
#endif
|
||||
}
|
||||
bool AbilityThread::isAppRunning_ = true;
|
||||
bool AbilityThread::isNativeApp_ = true;
|
||||
bool AbilityThread::isDisplayInited_ = false;
|
||||
|
||||
AbilityThread::~AbilityThread()
|
||||
{
|
||||
AdapterFree(identity_);
|
||||
delete abilityScheduler_;
|
||||
abilityScheduler_ = nullptr;
|
||||
delete eventHandler_;
|
||||
eventHandler_ = nullptr;
|
||||
}
|
||||
|
||||
void AbilityThread::ThreadMain(uint64_t token)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "AbilityThread::ThreadMain enter");
|
||||
|
||||
AbilityThread abilityThread;
|
||||
abilityThread.AttachBundle(token);
|
||||
|
||||
HILOG_INFO(HILOG_MODULE_APP, "AbilityThread::ThreadMain start loop");
|
||||
abilityThread.Run();
|
||||
}
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
void *AbilityThread::UITaskPost(void *arg)
|
||||
{
|
||||
prctl(PR_SET_NAME, UI_TASK_THREAD_NAME);
|
||||
|
||||
auto handler = static_cast<AbilityEventHandler *>(arg);
|
||||
if (handler == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "EventHandler is nullptr, fail to start loop");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int ret = pthread_detach(pthread_self());
|
||||
if (ret != 0) {
|
||||
HILOG_WARN(HILOG_MODULE_APP, "UITaskPost detach failed: %{public}d", ret);
|
||||
}
|
||||
|
||||
HILOG_INFO(HILOG_MODULE_APP, "start UITaskPost loop");
|
||||
while (isAppRunning_) {
|
||||
handler->PostTask([] {
|
||||
TaskManager::GetInstance()->TaskHandler();
|
||||
});
|
||||
usleep(UI_TASK_HANDLER_PERIOD);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void AbilityThread::InitUITaskEnv()
|
||||
{
|
||||
if (isDisplayInited_) {
|
||||
return;
|
||||
}
|
||||
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Hal and UI init");
|
||||
GraphicStartUp::Init();
|
||||
GraphicStartUp::InitFontEngine(reinterpret_cast<uintptr_t>(g_fontPsramBaseAddr), MIN_FONT_PSRAM_LENGTH,
|
||||
const_cast<char *>(FONT_PATH), DEFAULT_VECTOR_FONT_FILENAME);
|
||||
auto screenDevice = new ScreenDevice();
|
||||
ScreenDeviceProxy::GetInstance()->SetDevice(screenDevice);
|
||||
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Create UITaskPost thread");
|
||||
pthread_t tid;
|
||||
int ret = pthread_create(&tid, nullptr, AbilityThread::UITaskPost, eventHandler_);
|
||||
if (ret != 0) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "create UI post thread error, %{public}d", ret);
|
||||
exit(-1);
|
||||
}
|
||||
isDisplayInited_ = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void AbilityThread::StartAbilityCallback(const Want &want)
|
||||
{
|
||||
if ((want.sid == nullptr) || (want.element == nullptr)) {
|
||||
return;
|
||||
}
|
||||
HILOG_INFO(HILOG_MODULE_APP, "start ability callback");
|
||||
IpcIo io;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&io, data, IPC_IO_DATA_MAX, 0);
|
||||
if (!SerializeElement(&io, want.element)) {
|
||||
return;
|
||||
}
|
||||
IpcIoPushInt32(&io, EC_SUCCESS);
|
||||
if (Transact(nullptr, *(want.sid), SCHEDULER_APP_INIT, &io, nullptr, LITEIPC_FLAG_ONEWAY, nullptr) != LITEIPC_OK) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "start ability callback failed, ipc error");
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityThread::PerformAppInit(const AppInfo &appInfo)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Start app init");
|
||||
if ((appInfo.bundleName.empty()) || (appInfo.srcPath.empty())) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "appInfo is null");
|
||||
return;
|
||||
}
|
||||
if (!appInfo.isNativeApp && (appInfo.moduleNames.size() != 1)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "only native app support multi hap");
|
||||
return;
|
||||
}
|
||||
AbilityEnvImpl::GetInstance().SetAppInfo(appInfo);
|
||||
AbilityThread::isNativeApp_ = appInfo.isNativeApp;
|
||||
|
||||
for (const auto &module : appInfo.moduleNames) {
|
||||
std::string modulePath;
|
||||
if (appInfo.isNativeApp) {
|
||||
modulePath = appInfo.srcPath + PATH_SEPARATOR + module + LIB_PREFIX + module + LIB_SUFFIX;
|
||||
if (modulePath.size() > PATH_MAX) {
|
||||
continue;
|
||||
}
|
||||
char realPath[PATH_MAX + 1] = { 0 };
|
||||
if (realpath(modulePath.c_str(), realPath) == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "Fail to get realpath of %{public}s", modulePath.c_str());
|
||||
continue;
|
||||
}
|
||||
void *handle = dlopen(static_cast<char *>(realPath), RTLD_NOW | RTLD_GLOBAL);
|
||||
if (handle == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "Fail to dlopen %{public}s, [%{public}s]", modulePath.c_str(), dlerror());
|
||||
exit(-1);
|
||||
}
|
||||
handle_.emplace_front(handle);
|
||||
}
|
||||
}
|
||||
|
||||
int ret = UtilsSetEnv(GetDataPath());
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Set env ret: %{public}d, App init end", ret);
|
||||
}
|
||||
|
||||
void AbilityThread::PerformAppExit()
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "perform app exit");
|
||||
eventHandler_->PostTask([] {
|
||||
AbilityThread::isAppRunning_ = false;
|
||||
});
|
||||
for (auto handle : handle_) {
|
||||
dlclose(handle);
|
||||
}
|
||||
eventHandler_->PostQuit();
|
||||
handle_.clear();
|
||||
}
|
||||
|
||||
void AbilityThread::PerformTransactAbilityState(const Want &want, int state, uint64_t token, int abilityType)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "perform transact ability state to [%{public}d]", state);
|
||||
Ability *ability = nullptr;
|
||||
auto iter = abilities_.find(token);
|
||||
if ((iter == abilities_.end()) || (iter->second == nullptr)) {
|
||||
if (want.element == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "element name is null, fail to load ability");
|
||||
AbilityMsClient::GetInstance().SchedulerLifecycleDone(token, STATE_INITIAL);
|
||||
return;
|
||||
}
|
||||
auto abilityName = isNativeApp_ ? want.element->abilityName : ACE_ABILITY_NAME;
|
||||
ability = AbilityLoader::GetInstance().GetAbilityByName(abilityName);
|
||||
if (ability == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "fail to load ability: %{public}s", abilityName);
|
||||
AbilityMsClient::GetInstance().SchedulerLifecycleDone(token, STATE_INITIAL);
|
||||
return;
|
||||
}
|
||||
HILOG_INFO(HILOG_MODULE_APP, "Create ability success [%{public}s]", want.element->abilityName);
|
||||
|
||||
// Only page ability need to init display
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
if (abilityType == PAGE) {
|
||||
InitUITaskEnv();
|
||||
}
|
||||
#endif
|
||||
ability->Init(token, abilityType, AbilityThread::isNativeApp_);
|
||||
abilities_[token] = ability;
|
||||
} else {
|
||||
ability = iter->second;
|
||||
}
|
||||
|
||||
if (ability->GetState() != state) {
|
||||
HandleLifecycleTransaction(*ability, want, state);
|
||||
}
|
||||
|
||||
HILOG_INFO(HILOG_MODULE_APP, "perform transact ability state done [%{public}d]", ability->GetState());
|
||||
AbilityMsClient::GetInstance().SchedulerLifecycleDone(token, ability->GetState());
|
||||
if (ability->GetState() == STATE_ACTIVE) {
|
||||
StartAbilityCallback(want);
|
||||
}
|
||||
|
||||
if (ability->GetState() == STATE_INITIAL) {
|
||||
abilities_.erase(token);
|
||||
delete ability;
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityThread::PerformConnectAbility(const Want &want, uint64_t token)
|
||||
{
|
||||
auto iter = abilities_.find(token);
|
||||
if (iter == abilities_.end() || iter->second == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "app has been stopped");
|
||||
return;
|
||||
}
|
||||
const SvcIdentity *sid = iter->second->OnConnect(want);
|
||||
AbilityMsClient::GetInstance().ScheduleAms(nullptr, token, sid, CONNECT_ABILITY_DONE);
|
||||
}
|
||||
|
||||
void AbilityThread::PerformDisconnectAbility(const Want &want, uint64_t token)
|
||||
{
|
||||
auto iter = abilities_.find(token);
|
||||
if (iter == abilities_.end() || iter->second == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "app has been stopped");
|
||||
return;
|
||||
}
|
||||
iter->second->OnDisconnect(want);
|
||||
AbilityMsClient::GetInstance().ScheduleAms(nullptr, token, nullptr, DISCONNECT_ABILITY_DONE);
|
||||
}
|
||||
|
||||
void AbilityThread::PerformDumpAbility(const Want &want, uint64_t token)
|
||||
{
|
||||
auto iter = abilities_.find(token);
|
||||
if (iter == abilities_.end() || iter->second == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "app has been stopped");
|
||||
return;
|
||||
}
|
||||
if (want.sid == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "SvcIdentity is null, dump failed");
|
||||
return;
|
||||
}
|
||||
std::string extra("");
|
||||
if (want.data != nullptr) {
|
||||
auto str = static_cast<char *>(want.data);
|
||||
if (want.dataLength == strlen(str) + 1) {
|
||||
extra = str;
|
||||
}
|
||||
}
|
||||
iter->second->Dump(extra);
|
||||
std::string dumpInfo = iter->second->GetDumpInfo();
|
||||
IpcIo io;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&io, data, IPC_IO_DATA_MAX, 1);
|
||||
#ifdef __LINUX__
|
||||
IpcIoPushString(&io, dumpInfo.c_str());
|
||||
#else
|
||||
BuffPtr dataBuff = {
|
||||
.buffSz = dumpInfo.length() + 1, // include \0
|
||||
.buff = const_cast<char *>(dumpInfo.c_str()),
|
||||
};
|
||||
IpcIoPushDataBuff(&io, &dataBuff);
|
||||
#endif
|
||||
if (Transact(nullptr, *(want.sid), SCHEDULER_DUMP_ABILITY, &io, nullptr, LITEIPC_FLAG_ONEWAY, nullptr) !=
|
||||
LITEIPC_OK) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "dump ability failed, ipc error");
|
||||
}
|
||||
#ifdef __LINUX__
|
||||
BinderRelease(want.sid->ipcContext, want.sid->handle);
|
||||
#endif
|
||||
}
|
||||
|
||||
void AbilityThread::HandleLifecycleTransaction(Ability &ability, const Want &want, int state)
|
||||
{
|
||||
// Switch INITIAL state to INACTIVE state
|
||||
if (ability.GetState() == STATE_INITIAL) {
|
||||
ability.OnStart(want);
|
||||
}
|
||||
|
||||
// Switch ACTIVE state to INACTIVE state
|
||||
if (ability.GetState() == STATE_ACTIVE) {
|
||||
ability.OnInactive();
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case STATE_INITIAL: {
|
||||
if (ability.GetState() == STATE_INACTIVE) {
|
||||
ability.OnBackground();
|
||||
}
|
||||
ability.OnStop();
|
||||
break;
|
||||
}
|
||||
case STATE_INACTIVE: {
|
||||
// Not support transact from BACKGROUND to INACTIVE state
|
||||
break;
|
||||
}
|
||||
case STATE_ACTIVE: {
|
||||
ability.OnActive(want);
|
||||
break;
|
||||
}
|
||||
case STATE_BACKGROUND: {
|
||||
if (ability.GetState() == STATE_INACTIVE) {
|
||||
ability.OnBackground();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "Unknown target state: %{public}d", state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityThread::AttachBundle(uint64_t token)
|
||||
{
|
||||
eventHandler_ = new AbilityEventHandler();
|
||||
abilityScheduler_ = new AbilityScheduler(*eventHandler_, *this);
|
||||
if (!AbilityMsClient::GetInstance().Initialize()) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "ams feature is null");
|
||||
return;
|
||||
}
|
||||
|
||||
identity_ = static_cast<SvcIdentity *>(AdapterMalloc(sizeof(SvcIdentity)));
|
||||
if (identity_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "ams identity is null");
|
||||
return;
|
||||
}
|
||||
int32_t ret = RegisterIpcCallback(AbilityScheduler::AmsCallback, 0, IPC_WAIT_FOREVER, identity_, abilityScheduler_);
|
||||
if (ret != 0) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "RegisterIpcCallback failed");
|
||||
AdapterFree(identity_);
|
||||
return;
|
||||
}
|
||||
|
||||
AbilityMsClient::GetInstance().ScheduleAms(nullptr, token, identity_, ATTACH_BUNDLE);
|
||||
}
|
||||
|
||||
void AbilityThread::Run()
|
||||
{
|
||||
eventHandler_->Run();
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_window.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
void AbilityWindow::SetRootView(RootView *rootView, int16_t x, int16_t y)
|
||||
{
|
||||
if (rootView == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (window_ == nullptr) {
|
||||
WindowConfig config = {};
|
||||
config.rect = rootView->GetRect();
|
||||
config.rect.SetPosition(x, y);
|
||||
window_ = Window::CreateWindow(config);
|
||||
if (window_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Rect rect = rootView->GetRect();
|
||||
window_->Resize(rect.GetWidth(), rect.GetHeight());
|
||||
window_->MoveTo(x, y);
|
||||
}
|
||||
|
||||
window_->UnbindRootView();
|
||||
window_->BindRootView(rootView);
|
||||
rootView->Invalidate();
|
||||
|
||||
isWindowAttached_ = true;
|
||||
}
|
||||
|
||||
void AbilityWindow::EnsureLatestUIAttached() const
|
||||
{
|
||||
if (!isWindowAttached_ || (window_ == nullptr)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "Should SetUIContent before slice active");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityWindow::OnPostAbilityStart()
|
||||
{
|
||||
EnsureLatestUIAttached();
|
||||
|
||||
window_->Show();
|
||||
}
|
||||
|
||||
void AbilityWindow::OnPostAbilityActive()
|
||||
{
|
||||
EnsureLatestUIAttached();
|
||||
|
||||
window_->RaiseToTop();
|
||||
window_->Show();
|
||||
}
|
||||
|
||||
void AbilityWindow::OnPostAbilityBackground()
|
||||
{
|
||||
EnsureLatestUIAttached();
|
||||
|
||||
window_->Hide();
|
||||
}
|
||||
|
||||
void AbilityWindow::OnPostAbilityStop()
|
||||
{
|
||||
EnsureLatestUIAttached();
|
||||
|
||||
window_->UnbindRootView();
|
||||
Window::DestoryWindow(window_);
|
||||
window_ = nullptr;
|
||||
}
|
||||
} // namespace OHOS
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#include "lite_context.h"
|
||||
|
||||
#include "ability_state.h"
|
||||
#include "abilityms_slite_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
int LiteContext::StartAbility(const Want &want)
|
||||
{
|
||||
return AbilityMsClient::GetInstance().StartAbility(&want);
|
||||
}
|
||||
|
||||
int LiteContext::TerminateAbility()
|
||||
{
|
||||
return AbilityMsClient::GetInstance().TerminateAbility(token_);
|
||||
}
|
||||
} // namespace OHOS
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#include "slite_ability.h"
|
||||
|
||||
#include "ability_state.h"
|
||||
#include "abilityms_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
void SliteAbility::OnStart(const Want &want)
|
||||
{
|
||||
abilityState_ = STATE_INITIAL;
|
||||
(void) AbilityMsClient::GetInstance().SchedulerLifecycleDone(token_, STATE_INITIAL);
|
||||
}
|
||||
|
||||
void SliteAbility::OnInactive()
|
||||
{
|
||||
abilityState_ = STATE_INACTIVE;
|
||||
(void) AbilityMsClient::GetInstance().SchedulerLifecycleDone(token_, STATE_INACTIVE);
|
||||
}
|
||||
|
||||
void SliteAbility::OnActive(const Want &want)
|
||||
{
|
||||
abilityState_ = STATE_ACTIVE;
|
||||
(void) AbilityMsClient::GetInstance().SchedulerLifecycleDone(token_, STATE_ACTIVE);
|
||||
}
|
||||
|
||||
void SliteAbility::OnBackground()
|
||||
{
|
||||
abilityState_ = STATE_BACKGROUND;
|
||||
(void) AbilityMsClient::GetInstance().SchedulerLifecycleDone(token_, STATE_BACKGROUND);
|
||||
}
|
||||
|
||||
int SliteAbility::GetState() const
|
||||
{
|
||||
return abilityState_;
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
# Copyright (c) 2020 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("//build/lite/config/component/lite_component.gni")
|
||||
import("//build/lite/config/subsystem/aafwk/config.gni")
|
||||
|
||||
lite_library("abilitymanager") {
|
||||
target_type = "shared_library"
|
||||
cflags = [ "-Wall" ]
|
||||
cflags_cc = cflags
|
||||
|
||||
sources = [
|
||||
"src/ability_manager.cpp",
|
||||
"src/ability_service_manager.cpp",
|
||||
"src/abilityms_client.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"${aafwk_lite_path}/frameworks/abilitymgr_lite/include",
|
||||
"${aafwk_lite_path}/frameworks/want_lite/include",
|
||||
"${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
"${aafwk_lite_path}/interfaces/kits/ability_lite",
|
||||
"${appexecfwk_lite_path}/utils/bundle_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite/include",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/registry",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
"//kernel/liteos_a/kernel/include",
|
||||
"//kernel/liteos_a/kernel/common",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//utils/native/lite/kv_store/innerkits",
|
||||
"//utils/native/lite/include",
|
||||
"./include",
|
||||
"./",
|
||||
]
|
||||
|
||||
defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ]
|
||||
}
|
||||
|
||||
lite_component("aafwk_abilityManager_lite") {
|
||||
features = [ ":abilitymanager" ]
|
||||
}
|
||||
Executable
+177
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITYKIT_H
|
||||
#define OHOS_ABILITYKIT_H
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
typedef int32_t (*SuccessCallback)(const void *data);
|
||||
typedef int32_t (*FailCallback)(const void *data, uint16_t dataLength, uint16_t errorCode);
|
||||
|
||||
namespace OHOS {
|
||||
struct FeatureAbilityDataInfo {
|
||||
char *bundleName { nullptr };
|
||||
void *message { nullptr };
|
||||
uint32_t messageLength { 0 };
|
||||
char *abilityName { nullptr };
|
||||
char *deviceID { nullptr };
|
||||
};
|
||||
|
||||
class AbilityKit {
|
||||
public:
|
||||
AbilityKit();
|
||||
~AbilityKit();
|
||||
|
||||
static int32_t RegisterReceiver(const char *bundleName, SuccessCallback success, FailCallback fail,
|
||||
uint32_t successCallbackFunc, uint32_t failCallbackFunc, uint32_t context);
|
||||
static int32_t UnregisterReceiver(const char *bundleName);
|
||||
static int32_t SendMsgToPeerApp(bool isLocalMsg, const char *callingPkgName, const char *calledPkgName,
|
||||
const uint8_t *msgBody, uint32_t length, uint32_t successCallbackFunc,
|
||||
uint32_t failCallbackFunc, uint32_t context);
|
||||
static int32_t DetectPhoneApp(const char *callingPkgName, const char *calledPkgName, uint32_t successCallbackFunc,
|
||||
uint32_t failCallbackFunc, uint32_t context);
|
||||
static int32_t DetectResourceRelease();
|
||||
static int32_t SendMsgResourceRelease();
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITYKIT_H
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_SERVICE_MANAGER_H
|
||||
#define OHOS_ABILITY_SERVICE_MANAGER_H
|
||||
|
||||
#include "ability_connection.h"
|
||||
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
|
||||
#include "nocopyable.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
typedef struct {
|
||||
const IAbilityConnection *conn;
|
||||
void *storeArg;
|
||||
SvcIdentity *sid;
|
||||
} StoreArgs;
|
||||
|
||||
class AbilityServiceManager {
|
||||
public:
|
||||
static AbilityServiceManager &GetInstance()
|
||||
{
|
||||
static AbilityServiceManager instance;
|
||||
return instance;
|
||||
}
|
||||
~AbilityServiceManager();
|
||||
int ConnectAbility(const Want &want, const IAbilityConnection &conn, uint64_t token, void *storeArg);
|
||||
int DisconnectAbility(const IAbilityConnection &conn, uint64_t token);
|
||||
|
||||
private:
|
||||
AbilityServiceManager() = default;
|
||||
StoreArgs *AddStoreArgs(const IAbilityConnection &conn, void *storeArg);
|
||||
StoreArgs *GetStoreArgs(const IAbilityConnection &conn) const;
|
||||
StoreArgs *RemoveStoreArgs(const IAbilityConnection *conn, StoreArgs *storeArgs);
|
||||
static int32_t ConnectAbilityCallBack(const IpcContext* context, void *ipcMsg, IpcIo *data, void *arg);
|
||||
static void ClearStore(StoreArgs *storeArgs);
|
||||
std::list<StoreArgs *> storeList_;
|
||||
std::mutex mutex_;
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(AbilityServiceManager);
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_SERVICE_MANAGER_H
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITYMS_CLIENT_H
|
||||
#define OHOS_ABILITYMS_CLIENT_H
|
||||
|
||||
#include "iproxy_client.h"
|
||||
#include "nocopyable.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityMsClient {
|
||||
public:
|
||||
static AbilityMsClient &GetInstance()
|
||||
{
|
||||
static AbilityMsClient instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
~AbilityMsClient() = default;
|
||||
|
||||
bool Initialize() const;
|
||||
|
||||
int SchedulerLifecycleDone(uint64_t token, int state) const;
|
||||
|
||||
int ScheduleAms(const Want *want, uint64_t token, const SvcIdentity *sid, int commandType) const;
|
||||
|
||||
private:
|
||||
AbilityMsClient() = default;
|
||||
|
||||
IClientProxy *amsProxy_ { nullptr };
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(AbilityMsClient);
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITYMS_CLIENT_H
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITYMS_SLITE_CLIENT_H
|
||||
#define OHOS_ABILITYMS_SLITE_CLIENT_H
|
||||
|
||||
#include "iproxy_client.h"
|
||||
#include "nocopyable.h"
|
||||
#include "want.h"
|
||||
#include "ability_service_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityMsClient {
|
||||
public:
|
||||
static AbilityMsClient &GetInstance()
|
||||
{
|
||||
static AbilityMsClient instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
~AbilityMsClient() = default;
|
||||
|
||||
bool Initialize() const;
|
||||
|
||||
int StartAbility(const Want *want) const;
|
||||
|
||||
int TerminateAbility(uint64_t token) const;
|
||||
|
||||
int SchedulerLifecycleDone(uint64_t token, int state) const;
|
||||
|
||||
private:
|
||||
AbilityMsClient() = default;
|
||||
|
||||
AmsSliteInterface *amsProxy_ { nullptr };
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(AbilityMsClient);
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITYMS_SLITE_CLIENT_H
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_kit.h"
|
||||
#include "ability_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
int32_t AbilityKit::RegisterReceiver(const char *bundleName, SuccessCallback success, FailCallback fail,
|
||||
uint32_t successCallbackFunc, uint32_t failCallbackFunc, uint32_t context)
|
||||
{
|
||||
return AbilityService::GetInstance().RegisterReceiver(bundleName, success, fail, successCallbackFunc,
|
||||
failCallbackFunc, context);
|
||||
}
|
||||
|
||||
int32_t AbilityKit::UnregisterReceiver(const char *bundleName)
|
||||
{
|
||||
return AbilityService::GetInstance().UnregisterReceiver(bundleName);
|
||||
}
|
||||
|
||||
int32_t AbilityKit::SendMsgToPeerApp(bool isLocalMsg, const char *callingPkgName,
|
||||
const char *calledPkgName, const uint8_t *msgBody, uint32_t length,
|
||||
uint32_t successCallbackFunc, uint32_t failCallbackFunc, uint32_t context)
|
||||
{
|
||||
return AbilityService::GetInstance().SendMsgToPeerApp(isLocalMsg, callingPkgName, calledPkgName,
|
||||
msgBody, length, successCallbackFunc, failCallbackFunc, context);
|
||||
}
|
||||
|
||||
int32_t AbilityKit::DetectPhoneApp(const char *callingPkgName, const char *calledPkgName, uint32_t successCallbackFunc,
|
||||
uint32_t failCallbackFunc, uint32_t context)
|
||||
{
|
||||
return AbilityService::GetInstance().DetectPhoneApp(callingPkgName, calledPkgName, successCallbackFunc,
|
||||
failCallbackFunc, context);
|
||||
}
|
||||
|
||||
int32_t AbilityKit::DetectResourceRelease()
|
||||
{
|
||||
return AbilityService::GetInstance().DetectResourceRelease();
|
||||
}
|
||||
|
||||
int32_t AbilityKit::SendMsgResourceRelease()
|
||||
{
|
||||
return AbilityService::GetInstance().SendMsgResourceRelease();
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
#ifdef APP_PLATFORM_WATCHGT
|
||||
extern "C" {
|
||||
int32_t RegisterReceiver(const char *bundleName, SuccessCallback success, FailCallback fail)
|
||||
{
|
||||
return OHOS::AbilityKit::RegisterReceiver(bundleName, success, fail, 0, 0, 0);
|
||||
}
|
||||
|
||||
int32_t UnregisterReceiver(const char *bundleName)
|
||||
{
|
||||
return OHOS::AbilityKit::UnregisterReceiver(bundleName);
|
||||
}
|
||||
|
||||
int32_t SendMsgToPeerApp(bool isLocalMsg, const char *callingPkgName, const char *calledPkgName,
|
||||
const uint8_t *msgBody, uint32_t length)
|
||||
{
|
||||
return OHOS::AbilityKit::SendMsgToPeerApp(isLocalMsg, callingPkgName, calledPkgName, msgBody, length, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
#endif // APP_PLATFORM_WATCHGT
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_manager.h"
|
||||
|
||||
#include <log.h>
|
||||
|
||||
#include "ability_service_interface.h"
|
||||
#include "ability_service_manager.h"
|
||||
#include "abilityms_client.h"
|
||||
|
||||
extern "C" {
|
||||
const int DEFAULT_TOKEN = 1;
|
||||
int StartAbility(const Want *want)
|
||||
{
|
||||
if (want == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "want is null, StartAbility failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
OHOS::AbilityMsClient::GetInstance().Initialize();
|
||||
return OHOS::AbilityMsClient::GetInstance().ScheduleAms(want, 0, nullptr, START_ABILITY);
|
||||
}
|
||||
|
||||
int StopAbility(const Want *want)
|
||||
{
|
||||
if (want == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "want is null, StopAbility failed");
|
||||
return -1;
|
||||
}
|
||||
OHOS::AbilityMsClient::GetInstance().Initialize();
|
||||
return OHOS::AbilityMsClient::GetInstance().ScheduleAms(want, 0, nullptr, TERMINATE_SERVICE);
|
||||
}
|
||||
|
||||
int ConnectAbility(const Want *want, const IAbilityConnection *conn, void *data)
|
||||
{
|
||||
if (want == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "want is null, ConnectAbility failed");
|
||||
return -1;
|
||||
}
|
||||
if (conn == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "conn is null, ConnectAbility failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return OHOS::AbilityServiceManager::GetInstance().ConnectAbility(*want, *conn, DEFAULT_TOKEN, data);
|
||||
}
|
||||
|
||||
int DisconnectAbility(const IAbilityConnection *conn)
|
||||
{
|
||||
if (conn == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "conn is null, DisconnectAbility failed");
|
||||
return LITEIPC_EINVAL;
|
||||
}
|
||||
return OHOS::AbilityServiceManager::GetInstance().DisconnectAbility(*conn, DEFAULT_TOKEN);
|
||||
}
|
||||
}
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "ability_service_manager.h"
|
||||
|
||||
#include <log.h>
|
||||
|
||||
#include "ability_kit_command.h"
|
||||
#include "ability_service_interface.h"
|
||||
#include "abilityms_client.h"
|
||||
#include "ohos_errno.h"
|
||||
#include "securec.h"
|
||||
#include "utils.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
AbilityServiceManager::~AbilityServiceManager()
|
||||
{
|
||||
for (const auto &storeArgs : storeList_) {
|
||||
if (storeArgs == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (storeArgs->sid != nullptr) {
|
||||
UnregisterIpcCallback(*(storeArgs->sid));
|
||||
delete storeArgs->sid;
|
||||
}
|
||||
delete storeArgs;
|
||||
}
|
||||
storeList_.clear();
|
||||
}
|
||||
|
||||
int AbilityServiceManager::ConnectAbility(const Want &want, const IAbilityConnection &conn, uint64_t token, void *storeArg)
|
||||
{
|
||||
if (conn.OnAbilityDisconnectDone == nullptr || conn.OnAbilityConnectDone == nullptr) {
|
||||
HILOG_INFO(HILOG_MODULE_APP, "IAbilityConnection callback func is null");
|
||||
return LITEIPC_EINVAL;
|
||||
}
|
||||
|
||||
StoreArgs *storeArgs = AddStoreArgs(conn, storeArg);
|
||||
if (storeArgs == nullptr) {
|
||||
return LITEIPC_EINVAL;
|
||||
}
|
||||
AbilityMsClient::GetInstance().Initialize();
|
||||
int32_t result = RegisterIpcCallback(ConnectAbilityCallBack, 0, IPC_WAIT_FOREVER, storeArgs->sid, storeArgs);
|
||||
if (result != LITEIPC_OK) {
|
||||
RemoveStoreArgs(nullptr, storeArgs);
|
||||
delete storeArgs->sid;
|
||||
delete storeArgs;
|
||||
return result;
|
||||
}
|
||||
result = AbilityMsClient::GetInstance().ScheduleAms(&want, token, storeArgs->sid, CONNECT_ABILITY);
|
||||
if (result != EC_SUCCESS) {
|
||||
UnregisterIpcCallback(*(storeArgs->sid));
|
||||
RemoveStoreArgs(nullptr, storeArgs);
|
||||
delete storeArgs->sid;
|
||||
delete storeArgs;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int AbilityServiceManager::DisconnectAbility(const IAbilityConnection &conn, uint64_t token)
|
||||
{
|
||||
StoreArgs *storeArgs = RemoveStoreArgs(&conn, nullptr);
|
||||
if (storeArgs == nullptr) {
|
||||
HILOG_INFO(HILOG_MODULE_APP, "no need to disconnect");
|
||||
return LITEIPC_EINVAL;
|
||||
}
|
||||
int result = AbilityMsClient::GetInstance().ScheduleAms(nullptr, token, storeArgs->sid, DISCONNECT_ABILITY);
|
||||
|
||||
ClearStore(storeArgs);
|
||||
return result;
|
||||
}
|
||||
|
||||
StoreArgs *AbilityServiceManager::AddStoreArgs(const IAbilityConnection &conn, void *storeArg)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (GetStoreArgs(conn) != nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "func has already used");
|
||||
return nullptr;
|
||||
}
|
||||
StoreArgs *storeArgs = new StoreArgs();
|
||||
storeArgs->conn = &conn;
|
||||
storeArgs->storeArg = storeArg;
|
||||
storeArgs->sid = new SvcIdentity();
|
||||
storeList_.emplace_back(storeArgs);
|
||||
|
||||
return storeArgs;
|
||||
}
|
||||
|
||||
StoreArgs *AbilityServiceManager::GetStoreArgs(const IAbilityConnection &conn) const
|
||||
{
|
||||
for (const auto storeArgs : storeList_) {
|
||||
if (storeArgs->conn == &conn) {
|
||||
return storeArgs;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
StoreArgs *AbilityServiceManager::RemoveStoreArgs(const IAbilityConnection *conn, StoreArgs *storeArgs)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (storeArgs == nullptr) {
|
||||
storeArgs = GetStoreArgs(*conn);
|
||||
}
|
||||
storeList_.remove(storeArgs);
|
||||
|
||||
return storeArgs;
|
||||
}
|
||||
|
||||
int32_t AbilityServiceManager::ConnectAbilityCallBack(const IpcContext* context, void *ipcMsg, IpcIo *data, void *arg)
|
||||
{
|
||||
// param check
|
||||
StoreArgs *storeArgs = static_cast<StoreArgs *>(arg);
|
||||
if (storeArgs == nullptr || ipcMsg == nullptr || storeArgs->conn == nullptr ||
|
||||
storeArgs->conn->OnAbilityConnectDone == nullptr || storeArgs->conn->OnAbilityDisconnectDone == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "storeArgs or callback func or ipcMsg is null");
|
||||
AbilityServiceManager::GetInstance().RemoveStoreArgs(nullptr, storeArgs);
|
||||
ClearStore(storeArgs);
|
||||
FreeBuffer(nullptr, ipcMsg);
|
||||
return LITEIPC_EINVAL;
|
||||
}
|
||||
|
||||
// parse funcId
|
||||
uint32_t funcId = 0;
|
||||
GetCode(ipcMsg, &funcId);
|
||||
int resultCode = (funcId != SCHEDULER_ABILITY_CONNECT_FAIL) ? 0 : -1;
|
||||
// parse service sid
|
||||
SvcIdentity *serviceSid = (funcId == SCHEDULER_ABILITY_CONNECT) ? IpcIoPopSvc(data) : nullptr;
|
||||
if ((funcId == SCHEDULER_ABILITY_CONNECT) && (serviceSid == nullptr)) {
|
||||
resultCode = -1;
|
||||
}
|
||||
// parse element
|
||||
ElementName elementName = { nullptr };
|
||||
if (!DeserializeElement(&elementName, data)) {
|
||||
resultCode = -1;
|
||||
}
|
||||
if (funcId == SCHEDULER_ABILITY_DISCONNECT) {
|
||||
storeArgs->conn->OnAbilityDisconnectDone(&elementName, resultCode, storeArgs->storeArg);
|
||||
} else {
|
||||
storeArgs->conn->OnAbilityConnectDone(&elementName, serviceSid, resultCode, storeArgs->storeArg);
|
||||
}
|
||||
if (funcId != SCHEDULER_ABILITY_CONNECT || resultCode == -1) {
|
||||
AbilityServiceManager::GetInstance().RemoveStoreArgs(nullptr, storeArgs);
|
||||
ClearStore(storeArgs);
|
||||
}
|
||||
#ifdef __LINUX__
|
||||
AdapterFree(serviceSid);
|
||||
serviceSid = nullptr;
|
||||
#endif
|
||||
ClearElement(&elementName);
|
||||
FreeBuffer(nullptr, ipcMsg);
|
||||
return LITEIPC_OK;
|
||||
}
|
||||
|
||||
void AbilityServiceManager::ClearStore(StoreArgs *storeArgs)
|
||||
{
|
||||
if ((storeArgs == nullptr) || (storeArgs->sid == nullptr)) {
|
||||
HILOG_INFO(HILOG_MODULE_APP, "no need to clear storeArgs");
|
||||
return;
|
||||
}
|
||||
UnregisterIpcCallback(*(storeArgs->sid));
|
||||
delete storeArgs->sid;
|
||||
delete storeArgs;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "abilityms_client.h"
|
||||
|
||||
#include "ability_errors.h"
|
||||
#include "ability_service_interface.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "log.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "serializer.h"
|
||||
#include "want_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
const unsigned int ERROR_SLEEP_TIMES = 300000;
|
||||
const unsigned int RETRY_TIMES = 20;
|
||||
|
||||
bool AbilityMsClient::Initialize() const
|
||||
{
|
||||
if (amsProxy_ != nullptr) {
|
||||
return true;
|
||||
}
|
||||
int retry = RETRY_TIMES;
|
||||
while (retry--) {
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(AMS_SERVICE, AMS_FEATURE);
|
||||
if (iUnknown == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "iUnknown is null");
|
||||
usleep(ERROR_SLEEP_TIMES); // sleep 300ms
|
||||
continue;
|
||||
}
|
||||
|
||||
(void)iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&amsProxy_);
|
||||
if (amsProxy_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "ams proxy is null");
|
||||
usleep(ERROR_SLEEP_TIMES); // sleep 300ms
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int AbilityMsClient::SchedulerLifecycleDone(uint64_t token, int state) const
|
||||
{
|
||||
if (amsProxy_ == nullptr) {
|
||||
return PARAM_NULL_ERROR;
|
||||
}
|
||||
IpcIo req;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&req, data, IPC_IO_DATA_MAX, 0);
|
||||
IpcIoPushUint64(&req, token);
|
||||
IpcIoPushInt32(&req, state);
|
||||
return amsProxy_->Invoke(amsProxy_, ABILITY_TRANSACTION_DONE, &req, nullptr, nullptr);
|
||||
}
|
||||
|
||||
int AbilityMsClient::ScheduleAms(const Want *want, uint64_t token, const SvcIdentity *sid, int commandType) const
|
||||
{
|
||||
if (amsProxy_ == nullptr) {
|
||||
return PARAM_NULL_ERROR;
|
||||
}
|
||||
IpcIo req;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&req, data, IPC_IO_DATA_MAX, 3);
|
||||
if (token != 0) {
|
||||
IpcIoPushUint64(&req, token);
|
||||
}
|
||||
if (sid != nullptr) {
|
||||
IpcIoPushSvc(&req, sid);
|
||||
#ifdef __LINUX__
|
||||
if (commandType == ATTACH_BUNDLE) {
|
||||
pid_t pid = getpid();
|
||||
IpcIoPushUint64(&req, pid);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (want != nullptr && !SerializeWant(&req, want)) {
|
||||
return SERIALIZE_ERROR;
|
||||
}
|
||||
return amsProxy_->Invoke(amsProxy_, commandType, &req, nullptr, nullptr);
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#include "ability_manager.h"
|
||||
|
||||
#include "abilityms_slite_client.h"
|
||||
|
||||
extern "C" {
|
||||
int StartAbility(const Want *want)
|
||||
{
|
||||
return OHOS::AbilityMsClient::GetInstance().StartAbility(want);
|
||||
}
|
||||
|
||||
int TerminateAbility(uint64_t token)
|
||||
{
|
||||
return OHOS::AbilityMsClient::GetInstance().TerminateAbility(token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#include "ability_manager_inner.h"
|
||||
|
||||
#include "abilityms_slite_client.h"
|
||||
|
||||
extern "C" {
|
||||
int RegAbilityCallback(StartCheckFunc startChecktCallback)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SchedulerLifecycleDone(uint64_t token, int state)
|
||||
{
|
||||
return OHOS::AbilityMsClient::GetInstance().SchedulerLifecycleDone(token, state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#include "abilityms_slite_client.h"
|
||||
|
||||
#include "ability_errors.h"
|
||||
#include "ability_mgr_service.h"
|
||||
#include "ability_service.h"
|
||||
#include "abilityms_log.h"
|
||||
#include "adapter.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "securec.h"
|
||||
#include "unistd.h"
|
||||
#include "want_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
bool AbilityMsClient::Initialize() const
|
||||
{
|
||||
if (amsProxy_ != nullptr) {
|
||||
return true;
|
||||
}
|
||||
int retry = RETRY_TIMES;
|
||||
while (retry--) {
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(AMS_SERVICE, AMS_SLITE_FEATURE);
|
||||
if (iUnknown == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "iUnknown is null");
|
||||
osDelay(ERROR_SLEEP_TIMES); // sleep 300ms
|
||||
continue;
|
||||
}
|
||||
|
||||
(void)iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&amsProxy_);
|
||||
if (amsProxy_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "ams proxy is null");
|
||||
osDelay(ERROR_SLEEP_TIMES); // sleep 300ms
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int AbilityMsClient::StartAbility(const Want *want) const
|
||||
{
|
||||
if (want == nullptr || want->element == nullptr || !Initialize()) {
|
||||
return PARAM_CHECK_ERROR;
|
||||
}
|
||||
|
||||
AbilityMgrService *service = AbilityMgrService::GetInstance();
|
||||
if (service == nullptr) {
|
||||
return PARAM_CHECK_ERROR;
|
||||
}
|
||||
|
||||
// 申请want内存,在服务端用完释放
|
||||
Want *info = static_cast<Want *>(AdapterMalloc(sizeof(Want)));
|
||||
if (info == nullptr) {
|
||||
return MEMORY_MALLOC_ERROR;
|
||||
}
|
||||
info->element = nullptr;
|
||||
info->data = nullptr;
|
||||
info->dataLength = 0;
|
||||
SetWantElement(info, *(want->element));
|
||||
SetWantData(info, want->data, want->dataLength);
|
||||
AbilityService::GetInstance().want_ = info;
|
||||
Request request = {
|
||||
.msgId = START_ABILITY,
|
||||
.data = nullptr,
|
||||
.len = 0,
|
||||
.msgValue = 0,
|
||||
};
|
||||
return SAMGR_SendRequest(service->GetIdentity(), &request, nullptr);
|
||||
}
|
||||
|
||||
int AbilityMsClient::TerminateAbility(uint64_t token) const
|
||||
{
|
||||
AbilityMgrService *service = AbilityMgrService::GetInstance();
|
||||
if (service == nullptr) {
|
||||
return PARAM_CHECK_ERROR;
|
||||
}
|
||||
Request request = {
|
||||
.msgId = TERMINATE_ABILITY,
|
||||
.data = nullptr,
|
||||
.len = 0,
|
||||
.msgValue = static_cast<uint32_t>(token & 0xFFFF),
|
||||
};
|
||||
return SAMGR_SendRequest(service->GetIdentity(), &request, nullptr);
|
||||
}
|
||||
|
||||
int AbilityMsClient::SchedulerLifecycleDone(uint64_t token, int state) const
|
||||
{
|
||||
AbilityMgrService *service = AbilityMgrService::GetInstance();
|
||||
if (service == nullptr) {
|
||||
return PARAM_CHECK_ERROR;
|
||||
}
|
||||
Request request = {
|
||||
.msgId = ABILITY_TRANSACTION_DONE,
|
||||
.data = nullptr,
|
||||
.len = 0,
|
||||
.msgValue = static_cast<uint32_t>((token & 0xFF) | (state << 8)),
|
||||
};
|
||||
return SAMGR_SendRequest(service->GetIdentity(), &request, nullptr);
|
||||
}
|
||||
} // namespace OHOS
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
# Copyright (c) 2020 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("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
generate_notice_file("want_notice_file") {
|
||||
module_name = "want"
|
||||
module_source_dir_list = [ "//third_party/bounds_checking_function" ]
|
||||
}
|
||||
|
||||
source_set("want") {
|
||||
sources = [ "src/want.cpp" ]
|
||||
cflags = [
|
||||
"-fPIC",
|
||||
"-Wall",
|
||||
]
|
||||
cflags_cc = cflags
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//utils/native/lite/include",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite/include",
|
||||
"${appexecfwk_lite_path}/utils/bundle_lite",
|
||||
"//foundation/communication/ipc_lite/interfaces/kits",
|
||||
"//kernel/liteos_a/kernel/include",
|
||||
"//kernel/liteos_a/kernel/common",
|
||||
]
|
||||
|
||||
defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ]
|
||||
}
|
||||
Executable
+177
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,2 @@
|
||||
## Introduction
|
||||
The cpp file is the implementation of Want class.
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_WANT_UTILS_H
|
||||
#define OHOS_WANT_UTILS_H
|
||||
|
||||
#include "want.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
#include <serializer.h>
|
||||
|
||||
bool SerializeWant(IpcIo *io, const Want *want);
|
||||
bool DeserializeWant(Want *want, IpcIo *io);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // OHOS_WANT_UTILS_H
|
||||
Executable
+325
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "want_utils.h"
|
||||
#include "element_name_utils.h"
|
||||
|
||||
#include <securec.h>
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
#include <string>
|
||||
#include <liteipc_adapter.h>
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
using UriKeyType = enum {
|
||||
BEGIN,
|
||||
DEVICE,
|
||||
BUNDLE,
|
||||
ABILITY,
|
||||
END,
|
||||
};
|
||||
|
||||
using UriProperties = struct {
|
||||
const char *key; /* key of uri property */
|
||||
uint8_t keyLen; /* key length of uri property */
|
||||
UriKeyType type; /* key type of uri property */
|
||||
};
|
||||
|
||||
const static UriProperties URI_PROPERTIES[] = {
|
||||
{ "#Want", 5, BEGIN },
|
||||
{ "device=", 7, DEVICE },
|
||||
{ "bundle=", 7, BUNDLE },
|
||||
{ "ability=", 8, ABILITY },
|
||||
{ "end", 3, END },
|
||||
};
|
||||
|
||||
constexpr static char URI_SEPARATOR = ';';
|
||||
constexpr static int VALUE_NULL = 0;
|
||||
constexpr static int VALUE_OBJECT = 1;
|
||||
constexpr static int DATA_LENGTH = 2048;
|
||||
#endif
|
||||
|
||||
void ClearWant(Want *want)
|
||||
{
|
||||
if (want == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
ClearElement(want->element);
|
||||
AdapterFree(want->element);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
AdapterFree(want->sid);
|
||||
#endif
|
||||
AdapterFree(want->data);
|
||||
}
|
||||
|
||||
bool SetWantElement(Want *want, ElementName element)
|
||||
{
|
||||
if (want == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ClearElement(want->element);
|
||||
AdapterFree(want->element);
|
||||
want->element = reinterpret_cast<ElementName *>(AdapterMalloc(sizeof(ElementName)));
|
||||
if (want->element == nullptr) {
|
||||
return false;
|
||||
}
|
||||
want->element->deviceId = OHOS::Utils::Strdup(element.deviceId);
|
||||
want->element->bundleName = OHOS::Utils::Strdup(element.bundleName);
|
||||
want->element->abilityName = OHOS::Utils::Strdup(element.abilityName);
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
bool SetWantSvcIdentity(Want *want, SvcIdentity sid)
|
||||
{
|
||||
if (want == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(want->sid);
|
||||
want->sid = reinterpret_cast<SvcIdentity *>(AdapterMalloc(sizeof(SvcIdentity)));
|
||||
if (want->sid == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (memcpy_s(want->sid, sizeof(SvcIdentity), &sid, sizeof(SvcIdentity)) != EOK) {
|
||||
AdapterFree(want->sid);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SetWantData(Want *want, const void *data, uint16_t dataLength)
|
||||
{
|
||||
if (want == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(want->data);
|
||||
want->data = OHOS::Utils::Memdup(data, dataLength);
|
||||
if (want->data == nullptr) {
|
||||
want->dataLength = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
want->dataLength = dataLength;
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
bool SerializeWant(IpcIo *io, const Want *want)
|
||||
{
|
||||
if ((io == nullptr) || (want == nullptr) || (want->dataLength > DATA_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (want->element == nullptr) {
|
||||
IpcIoPushInt32(io, VALUE_NULL);
|
||||
} else {
|
||||
IpcIoPushInt32(io, VALUE_OBJECT);
|
||||
if (!SerializeElement(io, want->element)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
IpcIoPushInt32(io, want->dataLength);
|
||||
if (want->dataLength > 0) {
|
||||
#ifdef __LINUX__
|
||||
IpcIoPushString(io, reinterpret_cast<char *>(want->data));
|
||||
#else
|
||||
const BuffPtr buff = {
|
||||
want->dataLength,
|
||||
want->data,
|
||||
};
|
||||
IpcIoPushDataBuff(io, &buff);
|
||||
#endif
|
||||
}
|
||||
if (want->sid == nullptr) {
|
||||
IpcIoPushInt32(io, VALUE_NULL);
|
||||
} else {
|
||||
IpcIoPushInt32(io, VALUE_OBJECT);
|
||||
IpcIoPushSvc(io, want->sid);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeserializeWant(Want *want, IpcIo *io)
|
||||
{
|
||||
if ((want == nullptr) || (io == nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IpcIoPopInt32(io) == VALUE_OBJECT) {
|
||||
want->element = reinterpret_cast<ElementName *>(AdapterMalloc(sizeof(ElementName)));
|
||||
if (want->element == nullptr ||
|
||||
memset_s(want->element, sizeof(ElementName), 0, sizeof(ElementName)) != EOK ||
|
||||
!DeserializeElement(want->element, io)) {
|
||||
AdapterFree(want->element);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (IpcIoPopInt32(io) > 0) {
|
||||
#ifdef __LINUX__
|
||||
size_t len = 0;
|
||||
char *data = reinterpret_cast<char *>(IpcIoPopString(io, &len));
|
||||
if (!SetWantData(want, data, len + 1)) {
|
||||
ClearWant(want);
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
BuffPtr *buff = IpcIoPopDataBuff(io);
|
||||
if (buff == nullptr) {
|
||||
ClearWant(want);
|
||||
return false;
|
||||
}
|
||||
if (!SetWantData(want, buff->buff, buff->buffSz)) {
|
||||
FreeBuffer(nullptr, buff->buff);
|
||||
ClearWant(want);
|
||||
return false;
|
||||
}
|
||||
FreeBuffer(nullptr, buff->buff);
|
||||
#endif
|
||||
}
|
||||
if (IpcIoPopInt32(io) == VALUE_OBJECT) {
|
||||
auto sid = IpcIoPopSvc(io);
|
||||
if ((sid == nullptr) || !SetWantSvcIdentity(want, *sid)) {
|
||||
#ifdef __LINUX__
|
||||
AdapterFree(sid);
|
||||
sid = nullptr;
|
||||
#endif
|
||||
ClearWant(want);
|
||||
return false;
|
||||
}
|
||||
#ifdef __LINUX__
|
||||
AdapterFree(sid);
|
||||
sid = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Want *WantParseUri(const char *uri)
|
||||
{
|
||||
if (uri == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
char *parseUri = OHOS::Utils::Strdup(uri);
|
||||
if (parseUri == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
ElementName element = { nullptr, nullptr, nullptr };
|
||||
char *beginIndex = parseUri;
|
||||
for (auto property : URI_PROPERTIES) {
|
||||
if (strstr(beginIndex, property.key) != beginIndex) {
|
||||
AdapterFree(parseUri);
|
||||
return nullptr;
|
||||
}
|
||||
if (property.type == END) {
|
||||
break;
|
||||
}
|
||||
char *endIndex = strchr(beginIndex, URI_SEPARATOR);
|
||||
if ((endIndex == nullptr) || (endIndex <= beginIndex)) {
|
||||
AdapterFree(parseUri);
|
||||
return nullptr;
|
||||
}
|
||||
*endIndex = '\0';
|
||||
beginIndex += property.keyLen;
|
||||
switch (property.type) {
|
||||
case DEVICE: {
|
||||
SetElementDeviceID(&element, beginIndex);
|
||||
break;
|
||||
}
|
||||
case BUNDLE: {
|
||||
SetElementBundleName(&element, beginIndex);
|
||||
break;
|
||||
}
|
||||
case ABILITY: {
|
||||
SetElementAbilityName(&element, beginIndex);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
beginIndex = endIndex + 1;
|
||||
}
|
||||
AdapterFree(parseUri);
|
||||
Want *want = new Want();
|
||||
if ((memset_s(want, sizeof(Want), 0, sizeof(Want)) != EOK) || !SetWantElement(want, element)) {
|
||||
ClearElement(&element);
|
||||
delete want;
|
||||
return nullptr;
|
||||
}
|
||||
ClearElement(&element);
|
||||
return want;
|
||||
}
|
||||
|
||||
const char *WantToUri(Want want)
|
||||
{
|
||||
std::string uriString;
|
||||
|
||||
for (auto property : URI_PROPERTIES) {
|
||||
uriString += property.key;
|
||||
switch (property.type) {
|
||||
case BEGIN: {
|
||||
uriString += URI_SEPARATOR;
|
||||
break;
|
||||
}
|
||||
case DEVICE: {
|
||||
if ((want.element != nullptr) && (want.element->deviceId != nullptr)) {
|
||||
uriString += want.element->deviceId;
|
||||
}
|
||||
uriString += URI_SEPARATOR;
|
||||
break;
|
||||
}
|
||||
case BUNDLE: {
|
||||
if ((want.element != nullptr) && (want.element->bundleName != nullptr)) {
|
||||
uriString += want.element->bundleName;
|
||||
}
|
||||
uriString += URI_SEPARATOR;
|
||||
break;
|
||||
}
|
||||
case ABILITY: {
|
||||
if ((want.element != nullptr) && (want.element->abilityName != nullptr)) {
|
||||
uriString += want.element->abilityName;
|
||||
}
|
||||
uriString += URI_SEPARATOR;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t len = uriString.size();
|
||||
char *uri = reinterpret_cast<char *>(AdapterMalloc(len + 1));
|
||||
if (uri == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (strncpy_s(uri, len + 1, uriString.c_str(), len) < 0) {
|
||||
AdapterFree(uri);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return uri;
|
||||
}
|
||||
#endif
|
||||
Executable
+177
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,2 @@
|
||||
## Features
|
||||
Ability manager is devoted to support some interface functions to other outside processes. By using these functions, other processes can start, stop, connect or disconnect ability of some one application.
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef OHOS_ABILITY_KIT_COMMAND_H
|
||||
#define OHOS_ABILITY_KIT_COMMAND_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
enum AbilityKitCommand {
|
||||
SCHEDULER_APP_INIT = 0,
|
||||
SCHEDULER_ABILITY_LIFECYCLE,
|
||||
SCHEDULER_ABILITY_CONNECT,
|
||||
SCHEDULER_ABILITY_DISCONNECT,
|
||||
SCHEDULER_APP_EXIT,
|
||||
SCHEDULER_DUMP_ABILITY,
|
||||
SCHEDULER_ABILITY_CONNECT_FAIL,
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif // OHOS_ABILITY_KIT_COMMAND_H
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_MAIN_H
|
||||
#define OHOS_ABILITY_MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
|
||||
int AbilityMain(const char *token);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // OHOS_ABILITY_MAIN_H
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_AMS_INTERFACE_H
|
||||
#define OHOS_AMS_INTERFACE_H
|
||||
|
||||
#include "feature.h"
|
||||
#include "iproxy_server.h"
|
||||
#include "want.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
const char AMS_SERVICE[] = "abilityms";
|
||||
const char AMS_FEATURE[] = "AmsFeature";
|
||||
const char AMS_SLITE_FEATURE[] = "AmsSliteFeature";
|
||||
const char AMS_INNER_FEATURE[] = "AmsInnerFeature";
|
||||
|
||||
enum AmsCommand {
|
||||
START_ABILITY = 0,
|
||||
TERMINATE_ABILITY,
|
||||
ATTACH_BUNDLE,
|
||||
CONNECT_ABILITY,
|
||||
CONNECT_ABILITY_DONE,
|
||||
DISCONNECT_ABILITY,
|
||||
DISCONNECT_ABILITY_DONE,
|
||||
ABILITY_TRANSACTION_DONE,
|
||||
TERMINATE_SERVICE,
|
||||
INNER_BEGIN,
|
||||
TERMINATE_APP = INNER_BEGIN,
|
||||
DUMP_ABILITY,
|
||||
COMMAND_END,
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose to start or terminate ability.
|
||||
*/
|
||||
struct AmsInterface {
|
||||
INHERIT_SERVER_IPROXY;
|
||||
int32 (*StartAbility)(const Want *want);
|
||||
int32 (*TerminateAbility)(uint64_t token);
|
||||
int32 (*ConnectAbility)(const Want *want, SvcIdentity *svc, uint64_t token);
|
||||
int32 (*DisconnectAbility)(SvcIdentity *svc, uint64_t token);
|
||||
int32 (*StopAbility)(const Want *want);
|
||||
};
|
||||
|
||||
struct AmsInnerInterface {
|
||||
INHERIT_SERVER_IPROXY;
|
||||
int32 (*StartKeepAliveApps)();
|
||||
int32 (*TerminateApp)(const char *bundleName);
|
||||
};
|
||||
|
||||
struct AmsSliteInterface {
|
||||
INHERIT_IUNKNOWN;
|
||||
int32 (*StartAbility)(const Want *want);
|
||||
int32 (*TerminateAbility)(uint64_t token);
|
||||
int32 (*SchedulerLifecycleDone)(uint64_t token, int state);
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif // OHOS_AMS_INTERFACE_H
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_MANAGER_INNER_H
|
||||
#define OHOS_ABILITY_MANAGER_INNER_H
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef int (*StartCheckFunc)(const char *bundleName);
|
||||
|
||||
int RegAbilityCallback(StartCheckFunc startChecktCallback);
|
||||
|
||||
int SchedulerLifecycleDone(uint64_t token, int state);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif // OHOS_ABILITY_MANAGER_INNER_H
|
||||
Executable
+177
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,3 @@
|
||||
## Introduction
|
||||
In order to support third developers to develop their java script applications, some interface functions are offered at here. By using these functions, third java script APPs can interactive with AMS `Ability Manager Service`. In addition, the life cycle of these applications ability will be managed by AMS, including, start, termination, stop, connection and disconnection.
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup AbilityKit
|
||||
* @{
|
||||
*
|
||||
* @brief Provides ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* Abilities are classified into Feature Abilities and Particle Abilities. Feature Abilities support the Page template,
|
||||
* and Particle Abilities support the Service template. An ability using the Page template is called a Page ability for
|
||||
* short and that using the Service template is called a Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ability.h
|
||||
*
|
||||
* @brief Declares ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* As the fundamental unit of OpenHarmony applications, abilities are classified into Feature Abilities and Particle
|
||||
* Abilities. Feature Abilities support the Page template, and Particle Abilities support the Service template.
|
||||
* An ability using the Page template is called Page ability for short and that using the Service template
|
||||
* is called Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OHOS_ABILITY_H
|
||||
#define OHOS_ABILITY_H
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
#include <components/root_view.h>
|
||||
#endif
|
||||
#include <string>
|
||||
|
||||
#include "ability_context.h"
|
||||
#include "ability_manager.h"
|
||||
#include "serializer.h"
|
||||
|
||||
namespace OHOS {
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
class AbilitySliceManager;
|
||||
class AbilityWindow;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Declares ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* As the fundamental unit of OpenHarmony applications, abilities are classified into Feature Abilities and Particle
|
||||
* Abilities. Feature Abilities support the Page template, and Particle Abilities support the Service template.
|
||||
* An ability using the Page template is called Page ability for short and that using the Service template
|
||||
* is called Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class Ability : public AbilityContext {
|
||||
public:
|
||||
Ability() = default;
|
||||
virtual ~Ability() = default;
|
||||
|
||||
/**
|
||||
* @brief Called when this ability is started. You must override this function if you want to perform some
|
||||
* initialization operations during ability startup.
|
||||
*
|
||||
* This function can be called only once in the entire lifecycle of an ability.
|
||||
* @param want Indicates the {@link Want} structure containing startup information about the ability.
|
||||
*/
|
||||
virtual void OnStart(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called when this ability enters the <b>STATE_INACTIVE</b> state.
|
||||
*
|
||||
* <b>STATE_INACTIVE</b> is an instantaneous state. The ability in this state may be visible but does not have
|
||||
* focus. You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnInactive();
|
||||
|
||||
/**
|
||||
* @brief Called when this ability enters the <b>STATE_ACTIVE</b> state.
|
||||
*
|
||||
* The ability in the <b>STATE_ACTIVE</b> state is visible and has focus.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
* @param want Indicates the {@link Want} structure containing activation information about the ability.
|
||||
*/
|
||||
virtual void OnActive(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called when this ability enters the <b>STATE_BACKGROUND</b> state.
|
||||
*
|
||||
*
|
||||
* The ability in the <b>STATE_BACKGROUND</b> state is invisible.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnBackground();
|
||||
|
||||
/**
|
||||
* @brief Called when this ability enters the <b>STATE_STOP</b> state.
|
||||
*
|
||||
* The ability in the <b>STATE_STOP</b> is being destroyed.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnStop();
|
||||
|
||||
/**
|
||||
* @brief Called when this Service ability is connected for the first time.
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
* @param want Indicates the {@link Want} structure containing connection information about the Service ability.
|
||||
* @return Returns a pointer to the <b>sid</b> of the connected Service ability.
|
||||
*/
|
||||
virtual const SvcIdentity *OnConnect(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called when all abilities connected to this Service ability are disconnected.
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
* @param want Indicates the {@link Want} structure containing disconnection information about the Service
|
||||
* ability.
|
||||
*/
|
||||
virtual void OnDisconnect(const Want &want);
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
/**
|
||||
* @brief Sets the main route for this ability.
|
||||
*
|
||||
* The main route, also called main entry, refers to the default <b>AbilitySlice</b> to present for this ability.
|
||||
* This function should be called only on Feature Abilities. If this function is not called in the
|
||||
* {@link OnStart(const Want &want)} function for a Feature Ability, the Feature Ability will fail to start.
|
||||
*
|
||||
* @param entry Indicates the main entry, which is the class name of the <b>AbilitySlice</b> instance to start.
|
||||
*/
|
||||
void SetMainRoute(const std::string &entry);
|
||||
|
||||
/**
|
||||
* @brief Sets the UI layout for this ability.
|
||||
* You can call {@link GetWindowRootView()} to create a layout and add controls.
|
||||
*
|
||||
* @param rootView Indicates the pointer to the custom layout view you have created.
|
||||
*/
|
||||
void SetUIContent(RootView *rootView);
|
||||
#endif
|
||||
/**
|
||||
* @brief Handles a message sent by the client to this Service ability.
|
||||
*
|
||||
* @param funcId Indicates the type of the message sent by the client.
|
||||
* @param request Indicates the pointer to the serialized request parameters sent by the client.
|
||||
* @param reply Indicates the pointer to the serialized result returned to the client.
|
||||
*/
|
||||
virtual void MsgHandle(uint32_t funcId, IpcIo *request, IpcIo *reply);
|
||||
|
||||
/**
|
||||
* @brief Prints ability information to the console.
|
||||
*
|
||||
* You can override this function to obtain or print extra parameters.
|
||||
*
|
||||
* @param extra Indicates the extra parameter to be obtained or printed to the console.
|
||||
*/
|
||||
virtual void Dump(const std::string &extra);
|
||||
|
||||
private:
|
||||
typedef enum {
|
||||
START,
|
||||
INACTIVE,
|
||||
ACTIVE,
|
||||
BACKGROUND,
|
||||
STOP,
|
||||
} Action;
|
||||
|
||||
void Init(uint64_t token, int abilityType, bool isNativeApp);
|
||||
int GetState() const;
|
||||
std::string GetDumpInfo() const;
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
void DeliverAbilityLifecycle(Action action, const Want *want = nullptr);
|
||||
#endif
|
||||
static int32_t MsgHandleInner(const IpcContext* context, void *ipcMsg, IpcIo *data, void *arg);
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
AbilitySliceManager *abilitySliceManager_ { nullptr };
|
||||
AbilityWindow *abilityWindow_ { nullptr };
|
||||
#endif
|
||||
int abilityState_ { 0 };
|
||||
int abilityType_ { 0 };
|
||||
uint64_t token_ { 0 };
|
||||
SvcIdentity *sid_ { nullptr };
|
||||
static const int MAX_OBJECTS = 6;
|
||||
|
||||
friend class AbilityThread;
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
friend class AbilitySliceManager;
|
||||
#endif
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_H
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup AbilityKit
|
||||
* @{
|
||||
*
|
||||
* @brief Provides ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* Abilities are classified into Feature Abilities and Particle Abilities. Feature Abilities support the Page template,
|
||||
* and Particle Abilities support the Service template. An ability using the Page template is called a Page ability for
|
||||
* short and that using the Service template is called a Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ability_connection.h
|
||||
* @brief Declares callbacks to be invoked when a remote Service ability is connected or disconnected.
|
||||
*
|
||||
* You must override the callbacks provided in {@link IAbilityConnection} to implement your processing logic for
|
||||
* Service connection and disconnection.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_CONNECTION_H
|
||||
#define OHOS_ABILITY_CONNECTION_H
|
||||
|
||||
#include "element_name.h"
|
||||
#include "liteipc_adapter.h"
|
||||
|
||||
typedef struct IAbilityConnection IAbilityConnection;
|
||||
|
||||
/**
|
||||
* @brief Provides callbacks to be invoked when a remote Service ability is connected or disconnected.
|
||||
*/
|
||||
struct IAbilityConnection {
|
||||
/**
|
||||
* @brief Called when a client is connected to a Service ability.
|
||||
*
|
||||
* This callback is invoked to receive the connection result after a client is connected to a Service ability.
|
||||
*
|
||||
* @param elementName Indicates the pointer to the information about the connected Service ability.
|
||||
* @param serviceSid Indicates the pointer to the remote proxy object of the Service ability.
|
||||
* @param resultCode Indicates the connection result code. The value <b>0</b> indicates a successful connection,
|
||||
* and any other value indicates a connection failure.
|
||||
* @param data Indicates the pointer to the data stored during the connection.
|
||||
*/
|
||||
void (*OnAbilityConnectDone)(ElementName *elementName, SvcIdentity *serviceSid, int resultCode, void *data);
|
||||
|
||||
/**
|
||||
* @brief Called after all connections to a Service ability are disconnected.
|
||||
*
|
||||
* This callback is invoked to receive the disconnection result after the connected Service ability crashes or is
|
||||
* killed. If the Service ability exits unexpectedly, all its connections are disconnected, and each ability
|
||||
* previously connected to it will call
|
||||
* {@link OnAbilityDisconnectDone(ElementName *elementName, int resultCode, void *data)}.
|
||||
*
|
||||
* @param elementName Indicates the pointer to the information about the disconnected Service ability.
|
||||
* @param resultCode Indicates the disconnection result code. The value <b>0</b> indicates a successful
|
||||
* disconnection, and any other value indicates a disconnection failure.
|
||||
* @param data Indicates the pointer to the data stored during the connection.
|
||||
*/
|
||||
void (*OnAbilityDisconnectDone)(ElementName *elementName, int resultCode, void *data);
|
||||
};
|
||||
#endif // OHOS_ABILITY_CONNECTION_H
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup AbilityKit
|
||||
* @{
|
||||
*
|
||||
* @brief Provides ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* Abilities are classified into Feature Abilities and Particle Abilities. Feature Abilities support the Page template,
|
||||
* and Particle Abilities support the Service template. An ability using the Page template is called a Page ability for
|
||||
* short and that using the Service template is called a Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ability_context.h
|
||||
*
|
||||
* @brief Declares functions for starting and stopping an ability.
|
||||
*
|
||||
* The {@link Ability} and {@link AbilitySlice} classes are inherited from the <b>AbilityContext</b> class for you to
|
||||
* call functions in this class for application development.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_CONTEXT_H
|
||||
#define OHOS_ABILITY_CONTEXT_H
|
||||
|
||||
#include <ability_manager.h>
|
||||
#include <want.h>
|
||||
#include "ability_connection.h"
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Provides functions for starting and stopping an ability.
|
||||
*
|
||||
* The {@link Ability} and {@link AbilitySlice} classes are inherited from the <b>AbilityContext</b> class for you to
|
||||
* call functions in this class for application development.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class AbilityContext {
|
||||
public:
|
||||
AbilityContext() = default;
|
||||
~AbilityContext() = default;
|
||||
|
||||
/**
|
||||
* @brief Starts an {@link Ability} based on the specified {@link Want} information.
|
||||
*
|
||||
* @param want Indicates the pointer to the {@link Want} structure containing information about the ability to
|
||||
* start.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
|
||||
*/
|
||||
int StartAbility(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Stops an {@link Ability} based on the specified {@link Want} information.
|
||||
*
|
||||
* This function takes effect only on Service abilities.
|
||||
*
|
||||
* @param want Indicates the pointer to the {@link Want} structure containing information about the ability to
|
||||
* stop.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
|
||||
*/
|
||||
int StopAbility(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Destroys this {@link Ability}.
|
||||
*
|
||||
* This function can be called only by this ability.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
|
||||
*/
|
||||
int TerminateAbility();
|
||||
|
||||
/**
|
||||
* @brief Connects to a Service ability based on the specified {@link Want} information.
|
||||
*
|
||||
* After the Service ability is connected, the Ability Manager Service invokes a particular callback and returns
|
||||
* the ID of the Service ability. The client can use this ID to communicate with the connected Service ability.
|
||||
*
|
||||
* @param want Indicates the pointer to the {@link Want} structure containing information about the Service
|
||||
* ability to connect.
|
||||
* @param conn Indicates the callback to be invoked when the connection is successful.
|
||||
* @param data Indicates the pointer to the data to be passed to the callback.
|
||||
* @return Returns <b>0</b> if this function is successfully called; returns another value otherwise.
|
||||
*/
|
||||
int ConnectAbility(const Want &want, const IAbilityConnection &conn, void *data);
|
||||
|
||||
/**
|
||||
* @brief Disconnects from a Service ability.
|
||||
*
|
||||
* @param conn Indicates the callback to be invoked when the connection is successful.
|
||||
* @return Returns <b>0</b> if this function is successfully called; returns another value otherwise.
|
||||
*/
|
||||
int DisconnectAbility(const IAbilityConnection &conn);
|
||||
|
||||
private:
|
||||
friend class Ability;
|
||||
friend class AbilitySlice;
|
||||
uint64_t token_ { 0 };
|
||||
};
|
||||
} // OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_CONTEXT_H
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup AbilityKit
|
||||
* @{
|
||||
*
|
||||
* @brief Provides ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* Abilities are classified into Feature Abilities and Particle Abilities. Feature Abilities support the Page template,
|
||||
* and Particle Abilities support the Service template. An ability using the Page template is called a Page ability for
|
||||
* short and that using the Service template is called a Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ability_env.h
|
||||
*
|
||||
* @brief Declares functions for obtaining information about the runtime environment of the application to which the
|
||||
* ability belongs, including the bundle name, source code path, and data path.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OHOS_ABILITY_ENV_H
|
||||
#define OHOS_ABILITY_ENV_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Obtains the bundle name of the application to which this ability belongs.
|
||||
*
|
||||
* @return Returns the pointer to the bundle name if the operation is successful; returns a null pointer otherwise.
|
||||
*/
|
||||
const char *GetBundleName();
|
||||
|
||||
/**
|
||||
* @brief Obtains the source code path of this ability.
|
||||
*
|
||||
* @return Returns the pointer to the source code path of this ability.
|
||||
*/
|
||||
const char *GetSrcPath();
|
||||
|
||||
/**
|
||||
* @brief Obtains the data path of this ability.
|
||||
*
|
||||
* @return Returns the pointer to the data path of this ability.
|
||||
*/
|
||||
const char *GetDataPath();
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // OHOS_ABILITY_ENV_H
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup AbilityKit
|
||||
* @{
|
||||
*
|
||||
* @brief Provides ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* Abilities are classified into Feature Abilities and Particle Abilities. Feature Abilities support the Page template,
|
||||
* and Particle Abilities support the Service template. An ability using the Page template is called a Page ability for
|
||||
* short and that using the Service template is called a Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ability_errors.h
|
||||
*
|
||||
* @brief Declares error codes returned by ability management functions.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_ERRORS_H
|
||||
#define OHOS_ABILITY_ERRORS_H
|
||||
|
||||
/**
|
||||
* @brief Declares error codes returned by ability management functions.
|
||||
*/
|
||||
enum {
|
||||
/** The function is successfully called. */
|
||||
ERR_OK = 0,
|
||||
|
||||
/** The parameter is null. */
|
||||
PARAM_NULL_ERROR,
|
||||
|
||||
/** Memory allocation error. */
|
||||
MEMORY_MALLOC_ERROR,
|
||||
|
||||
/** An error occurred during the execution of the <b>Dump</b> function. */
|
||||
DUMP_ABILITIES_ERROR,
|
||||
|
||||
/** IPC request error. */
|
||||
IPC_REQUEST_ERROR,
|
||||
|
||||
/** Serialization error. */
|
||||
SERIALIZE_ERROR,
|
||||
|
||||
/** Create app task error. */
|
||||
CREATE_APPTASK_ERROR,
|
||||
|
||||
/** Scheduler lifecycle error. */
|
||||
SCHEDULER_LIFECYCLE_ERROR,
|
||||
|
||||
/** The parameter is error. */
|
||||
PARAM_CHECK_ERROR,
|
||||
|
||||
/** Command error. */
|
||||
COMMAND_ERROR = 0x7fff,
|
||||
};
|
||||
#endif // OHOS_ABILITY_ERRORS_H
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup AbilityKit
|
||||
* @{
|
||||
*
|
||||
* @brief Provides ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* Abilities are classified into Feature Abilities and Particle Abilities. Feature Abilities support the Page template,
|
||||
* and Particle Abilities support the Service template. An ability using the Page template is called a Page ability for
|
||||
* short and that using the Service template is called a Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ability_event_handler.h
|
||||
*
|
||||
* @brief Declares functions for performing operations during inter-thread communication, including running and
|
||||
* quitting the event loop of the current thread and posting tasks to an asynchronous thread.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_EVENT_HANDLER_H
|
||||
#define OHOS_ABILITY_EVENT_HANDLER_H
|
||||
|
||||
#include <functional>
|
||||
#include <pthread.h>
|
||||
#include <queue>
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Declares functions for performing operations during inter-thread communication, including running and
|
||||
* quitting the event loop of the current thread and posting tasks to an asynchronous thread.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class AbilityEventHandler {
|
||||
public:
|
||||
using Task = std::function<void()>;
|
||||
|
||||
AbilityEventHandler();
|
||||
~AbilityEventHandler();
|
||||
|
||||
/**
|
||||
* @brief Starts running the event loop of the current thread.
|
||||
*/
|
||||
void Run();
|
||||
|
||||
/**
|
||||
* @brief Posts a task to an asynchronous thread.
|
||||
*
|
||||
* @param task Indicates the task to post.
|
||||
*/
|
||||
void PostTask(const Task &task);
|
||||
|
||||
/**
|
||||
* @brief Quits the event loop of the current thread.
|
||||
*/
|
||||
void PostQuit();
|
||||
|
||||
/**
|
||||
* @brief Obtains the event handler of the current thread.
|
||||
*
|
||||
* @return Returns the pointer to the {@link AbilityEventHandler} object of the current thread.
|
||||
*/
|
||||
static AbilityEventHandler* GetCurrentHandler();
|
||||
private:
|
||||
std::queue<Task> taskQueue_;
|
||||
|
||||
pthread_cond_t pthreadCond_ = PTHREAD_COND_INITIALIZER;
|
||||
pthread_mutex_t queueMutex_ = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
bool quit_ { false };
|
||||
|
||||
AbilityEventHandler(const AbilityEventHandler&) = delete;
|
||||
AbilityEventHandler& operator = (const AbilityEventHandler&) = delete;
|
||||
AbilityEventHandler(AbilityEventHandler&&) = delete;
|
||||
AbilityEventHandler& operator= (AbilityEventHandler&&) = delete;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_EVENT_HANDLER_H
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup AbilityKit
|
||||
* @{
|
||||
*
|
||||
* @brief Provides ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* Abilities are classified into Feature Abilities and Particle Abilities. Feature Abilities support the Page template,
|
||||
* and Particle Abilities support the Service template. An ability using the Page template is called a Page ability for
|
||||
* short and that using the Service template is called a Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ability_loader.h
|
||||
*
|
||||
* @brief Declares functions for registering the class names of {@link Ability} and {@link AbilitySlice} with the
|
||||
* ability management framework.
|
||||
*
|
||||
* After creating your own {@link Ability} and {@link AbilitySlice} child classes, you should register their class
|
||||
* names with the ability management framework so that the application can start <b>Ability</b> instances created in
|
||||
* the background.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_LOADER_H
|
||||
#define OHOS_ABILITY_LOADER_H
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "ability.h"
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
#include "ability_slice.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
using CreateAblity = std::function<Ability *(void)>;
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
using CreateSlice = std::function<AbilitySlice *(void)>;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Declares functions for registering the class names of {@link Ability} and {@link AbilitySlice} with the
|
||||
* ability management framework.
|
||||
*
|
||||
* After creating your own {@link Ability} and {@link AbilitySlice} child classes, you should register their class
|
||||
* names with the ability management framework so that the application can start <b>Ability</b> instances created in
|
||||
* the background.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class AbilityLoader {
|
||||
public:
|
||||
static AbilityLoader &GetInstance()
|
||||
{
|
||||
static AbilityLoader abilityLoader;
|
||||
return abilityLoader;
|
||||
}
|
||||
|
||||
~AbilityLoader() = default;
|
||||
|
||||
void RegisterAbility(const std::string &abilityName, const CreateAblity &createFunc);
|
||||
Ability *GetAbilityByName(const std::string &abilityName);
|
||||
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
void RegisterAbilitySlice(const std::string &sliceName, const CreateSlice &createFunc);
|
||||
AbilitySlice *GetAbilitySliceByName(const std::string &sliceName);
|
||||
#endif
|
||||
|
||||
private:
|
||||
AbilityLoader() = default;
|
||||
AbilityLoader(const AbilityLoader&) = delete;
|
||||
AbilityLoader &operator=(const AbilityLoader &) = delete;
|
||||
AbilityLoader(AbilityLoader &&) = delete;
|
||||
AbilityLoader &operator=(AbilityLoader &&) = delete;
|
||||
|
||||
std::unordered_map<std::string, CreateAblity> abilities_;
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
std::unordered_map<std::string, CreateSlice> slices_;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Registers the class name of an {@link Ability} child class.
|
||||
*
|
||||
* After implementing your own {@link Ability} class, you should call this function so that the ability management
|
||||
* framework can create <b>Ability</b> instances when loading your <b>Ability</b> class.
|
||||
*
|
||||
* @param className Indicates the {@link Ability} class name to register.
|
||||
*/
|
||||
#define REGISTER_AA(className) \
|
||||
__attribute__((constructor)) void RegisterAA##className() { \
|
||||
AbilityLoader::GetInstance().RegisterAbility(#className, []()->Ability* { \
|
||||
return new className; \
|
||||
}); \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Registers the class name of an {@link AbilitySlice} child class.
|
||||
*
|
||||
* After implementing your own {@link AbilitySlice} class, you should call this function so that the ability
|
||||
* management framework can create <b>AbilitySlice</b> instances when loading your <b>AbilitySlice</b> class.
|
||||
*
|
||||
* @param className Indicates the {@link AbilitySlice} class name to register.
|
||||
*/
|
||||
#ifdef ABILITY_WINDOW_SUPPORT
|
||||
#define REGISTER_AS(className) \
|
||||
__attribute__((constructor)) void RegisterAS##className() { \
|
||||
AbilityLoader::GetInstance().RegisterAbilitySlice(#className, []()->AbilitySlice* { \
|
||||
return new className; \
|
||||
}); \
|
||||
}
|
||||
#endif
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_LOADER_H
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup AbilityKit
|
||||
* @{
|
||||
*
|
||||
* @brief Provides ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* Abilities are classified into Feature Abilities and Particle Abilities. Feature Abilities support the Page template,
|
||||
* and Particle Abilities support the Service template. An ability using the Page template is called a Page ability for
|
||||
* short and that using the Service template is called a Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ability_manager.h
|
||||
*
|
||||
* @brief Declares ability-related functions, including functions for starting, stopping, connecting to,
|
||||
* and disconnecting from an ability, registering a callback, and unregistering a callback.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OHOS_ABILITY_MANAGER_H
|
||||
#define OHOS_ABILITY_MANAGER_H
|
||||
|
||||
#include "ability_connection.h"
|
||||
#include "want.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Starts an ability based on the specified {@link Want} information.
|
||||
*
|
||||
* @param want Indicates the pointer to the {@link Want} structure containing information about the ability to start.
|
||||
* @return Returns <b>0</b> if this function is successfully called; returns another value otherwise.
|
||||
*/
|
||||
int StartAbility(const Want *want);
|
||||
|
||||
/**
|
||||
* @brief Stops an ability based on the specified {@link Want} information.
|
||||
*
|
||||
* This function takes effect only on Service abilities.
|
||||
*
|
||||
* @param want Indicates the pointer to the {@link Want} structure containing information about the ability to stop.
|
||||
* @return Returns <b>0</b> if this function is successfully called; returns another value otherwise.
|
||||
*/
|
||||
int StopAbility(const Want *want);
|
||||
|
||||
/**
|
||||
* @brief Connects to a Service ability based on the specified {@link Want} information.
|
||||
*
|
||||
* @param want Indicates the pointer to the {@link Want} structure containing
|
||||
* information about the Service ability to connect.
|
||||
* @param conn Indicates the callback object when the Service ability is connected.
|
||||
* @param data Indicates the pointer to the data to be passed to the callback.
|
||||
* @return Returns <b>0</b> if this function is successfully called; returns another value otherwise.
|
||||
*/
|
||||
int ConnectAbility(const Want *want, const IAbilityConnection *conn, void *data);
|
||||
|
||||
/**
|
||||
* @brief Disconnects from a Service ability.
|
||||
*
|
||||
* @param conn Indicates the callback object when the Service ability is connected.
|
||||
* @return Returns <b>0</b> if this function is successfully called; returns another value otherwise.
|
||||
*/
|
||||
int DisconnectAbility(const IAbilityConnection *conn);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif /* OHOS_ABILITY_MANAGER_H */
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup AbilityKit
|
||||
* @{
|
||||
*
|
||||
* @brief Provides ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* Abilities are classified into Feature Abilities and Particle Abilities. Feature Abilities support the Page template,
|
||||
* and Particle Abilities support the Service template. An ability using the Page template is called a Page ability for
|
||||
* short and that using the Service template is called a Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ability_slice.h
|
||||
*
|
||||
* @brief Declares ability slice-related functions, including ability slice lifecycle callbacks and functions for
|
||||
* connecting to or disconnecting from ability slices.
|
||||
*
|
||||
* <b>AbilitySlice</b> instances, which are specific to Feature Abilities (abilities using the Page template),
|
||||
* are used to present different screens on an application's user interface.
|
||||
* A Feature Ability can have multiple ability slices.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OHOS_ABILITY_SLICE_H
|
||||
#define OHOS_ABILITY_SLICE_H
|
||||
|
||||
#include "ability.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilitySliceManager;
|
||||
|
||||
/**
|
||||
* @brief Provides ability slice-related functions, including ability slice lifecycle callbacks and functions for
|
||||
* connecting to or disconnecting from ability slices.
|
||||
*
|
||||
* <b>AbilitySlice</b> instances, which are specific to Feature Abilities (abilities using the Page template),
|
||||
* are used to present different screens on an application's user interface.
|
||||
* A Feature Ability can have multiple ability slices.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class AbilitySlice : public AbilityContext {
|
||||
public:
|
||||
AbilitySlice() = default;
|
||||
virtual ~AbilitySlice() = default;
|
||||
|
||||
/**
|
||||
* @brief Called when this ability slice is started. You must override this function if you want to perform some
|
||||
* initialization operations during ability slice startup.
|
||||
*
|
||||
* This function can be called only once in the entire lifecycle of an ability slice.
|
||||
* You can override this function to implement your own processing logic.
|
||||
* @param want Indicates the {@link Want} structure containing startup information about the ability slice.
|
||||
*/
|
||||
virtual void OnStart(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called when this ability slice enters the <b>STATE_INACTIVE</b> state.
|
||||
*
|
||||
* <b>STATE_INACTIVE</b> is an instantaneous state. The ability slice in this state may be visible but does not
|
||||
* have focus. You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnInactive();
|
||||
|
||||
/**
|
||||
* @brief Called when this ability slice enters the <b>STATE_ACTIVE</b> state.
|
||||
*
|
||||
* The ability slice in the <b>STATE_ACTIVE</b> state is visible and has focus.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
* @param want Indicates the {@link Want} structure containing activation information about the ability slice.
|
||||
*/
|
||||
virtual void OnActive(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called when this ability slice enters the <b>STATE_BACKGROUND</b> state.
|
||||
*
|
||||
* The ability slice in the <b>STATE_BACKGROUND</b> state is invisible.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnBackground();
|
||||
|
||||
/**
|
||||
* @brief Called when this ability slice enters the <b>STATE_STOP</b> state.
|
||||
*
|
||||
* The ability slice in the <b>STATE_STOP</b> state is being destroyed.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnStop();
|
||||
|
||||
/**
|
||||
* @brief Presents another ability slice, which can be an ability slice that is not started or an existing ability
|
||||
* slice in the host ability.
|
||||
*
|
||||
* @attention This function can be called only when both of the following conditions are met:
|
||||
* <ul><li>The host ability is in the <b>STATE_ACTIVE</b> state.</li>
|
||||
* <li>The target ability slice is not started or destroyed.</li></ul>
|
||||
*
|
||||
* @param abilitySlice Indicates the target ability slice. This parameter cannot be null.
|
||||
* @param want Indicates the {@link Want} structure containing startup information about the target ability slice.
|
||||
*/
|
||||
void Present(AbilitySlice &abilitySlice, const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Destroys this ability slice.
|
||||
*
|
||||
* This ability slice can call this function to destroy itself. If the ability slice to destroy is the only
|
||||
* running one in the host ability, the host ability will also be destroyed. Otherwise, the host ability will
|
||||
* not be affected.
|
||||
*/
|
||||
void Terminate();
|
||||
|
||||
/**
|
||||
* @brief Sets the UI layout for the host ability of this ability slice.
|
||||
*
|
||||
* You can call {@link GetWindowRootView()} to create a layout and add controls.
|
||||
*
|
||||
* @param rootView Indicates the pointer to the custom layout view you have created.
|
||||
*/
|
||||
void SetUIContent(RootView *rootView);
|
||||
private:
|
||||
void Init(AbilitySliceManager &abilitySliceManager);
|
||||
int GetState() const;
|
||||
|
||||
AbilitySliceManager *abilitySliceManager_ { nullptr };
|
||||
RootView *curRootView_ { nullptr };
|
||||
int sliceState_ { 0 };
|
||||
|
||||
friend class AbilitySliceScheduler;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_SLICE_H
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup AbilityKit
|
||||
* @{
|
||||
*
|
||||
* @brief Provides ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* Abilities are classified into Feature Abilities and Particle Abilities. Feature Abilities support the Page template,
|
||||
* and Particle Abilities support the Service template. An ability using the Page template is called a Page ability for
|
||||
* short and that using the Service template is called a Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ability_state.h
|
||||
*
|
||||
* @brief Declares ability-related functions, including ability lifecycle callbacks and functions for connecting to
|
||||
* or disconnecting from Particle Abilities.
|
||||
* As the fundamental unit of OpenHarmony applications, abilities are classified into Feature Abilities and Particle
|
||||
* Abilities. Feature Abilities support the Page template, and Particle Abilities support the Service template.
|
||||
* An ability using the Page template is called a Page ability for short and that using the Service template
|
||||
* is called a Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OHOS_ABILITY_STATE_H
|
||||
#define OHOS_ABILITY_STATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
/**
|
||||
* @brief Enumerates all lifecycle states that an ability will go through over the course of its lifetime.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum {
|
||||
/**
|
||||
* Uninitialized state: An ability is in this state when it has not been initialized after being created.
|
||||
*/
|
||||
STATE_UNINITIALIZED,
|
||||
|
||||
/**
|
||||
* Initial state: An ability is in this state after it is initialized or stopped.
|
||||
*/
|
||||
STATE_INITIAL,
|
||||
|
||||
/**
|
||||
* Inactive state: An ability is in this state when it is switched to the foreground but is not interactive.
|
||||
*/
|
||||
STATE_INACTIVE,
|
||||
|
||||
/**
|
||||
* Active state: An ability is in this state when it is switched to the foreground and is interactive.
|
||||
*/
|
||||
STATE_ACTIVE,
|
||||
|
||||
/**
|
||||
* Background state: An ability is in this state after it returns to the background.
|
||||
*/
|
||||
STATE_BACKGROUND,
|
||||
} State;
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif // OHOS_ABILITY_STATE_H
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_MANAGER_H
|
||||
#define OHOS_ABILITY_MANAGER_H
|
||||
|
||||
#include "want.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Starts an ability based on the specified {@link Want} information.
|
||||
*
|
||||
* @param want Indicates the pointer to the {@link Want} structure containing information about the ability to start.
|
||||
* @return Returns <b>0</b> if this function is successfully called; returns another value otherwise.
|
||||
*/
|
||||
int StartAbility(const Want *want);
|
||||
|
||||
int TerminateAbility(uint64_t token);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif /* OHOS_ABILITY_MANAGER_H */
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_LITE_CONTEXT_H
|
||||
#define OHOS_LITE_CONTEXT_H
|
||||
|
||||
#include "ability_manager.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
class LiteContext {
|
||||
public:
|
||||
LiteContext() = default;
|
||||
~LiteContext() = default;
|
||||
|
||||
/**
|
||||
* @brief Starts an {@link Ability} based on the specified {@link Want} information.
|
||||
*
|
||||
* @param want Indicates the pointer to the {@link Want} structure containing information about the ability to
|
||||
* start.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
|
||||
*/
|
||||
int StartAbility(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Destroys this {@link Ability}.
|
||||
*
|
||||
* This function can be called only by this ability.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
|
||||
*/
|
||||
int TerminateAbility();
|
||||
private:
|
||||
friend class SliteAbility;
|
||||
uint64_t token_ { 0 };
|
||||
};
|
||||
} // OHOS
|
||||
|
||||
#endif // OHOS_LITE_CONTEXT_H
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_SLITE_ABILITY_H
|
||||
#define OHOS_SLITE_ABILITY_H
|
||||
|
||||
#include "lite_context.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
/**
|
||||
* @brief Declares ability-related functions, including ability lifecycle callbacks and functions for connecting to or
|
||||
* disconnecting from Particle Abilities.
|
||||
*
|
||||
* As the fundamental unit of OpenHarmony applications, abilities are classified into Feature Abilities and Particle
|
||||
* Abilities. Feature Abilities support the Page template, and Particle Abilities support the Service template.
|
||||
* An ability using the Page template is called Page ability for short and that using the Service template
|
||||
* is called Service ability.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
class SliteAbility : public LiteContext {
|
||||
public:
|
||||
SliteAbility() = default;
|
||||
virtual ~SliteAbility() = default;
|
||||
|
||||
/**
|
||||
* @brief Called when this ability is started. You must override this function if you want to perform some
|
||||
* initialization operations during ability startup.
|
||||
*
|
||||
* This function can be called only once in the entire lifecycle of an ability.
|
||||
* @param want Indicates the {@link Want} structure containing startup information about the ability.
|
||||
*/
|
||||
virtual void OnStart(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called when this ability enters the <b>STATE_INACTIVE</b> state.
|
||||
*
|
||||
* <b>STATE_INACTIVE</b> is an instantaneous state. The ability in this state may be visible but does not have
|
||||
* focus. You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnInactive();
|
||||
|
||||
/**
|
||||
* @brief Called when this ability enters the <b>STATE_ACTIVE</b> state.
|
||||
*
|
||||
* The ability in the <b>STATE_ACTIVE</b> state is visible and has focus.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
* @param want Indicates the {@link Want} structure containing activation information about the ability.
|
||||
*/
|
||||
virtual void OnActive(const Want &want);
|
||||
|
||||
/**
|
||||
* @brief Called when this ability enters the <b>STATE_BACKGROUND</b> state.
|
||||
*
|
||||
*
|
||||
* The ability in the <b>STATE_BACKGROUND</b> state is invisible.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnBackground();
|
||||
|
||||
/**
|
||||
* @brief Called when this ability enters the <b>STATE_STOP</b> state.
|
||||
*
|
||||
* The ability in the <b>STATE_STOP</b> is being destroyed.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnStop();
|
||||
|
||||
int GetState() const;
|
||||
private:
|
||||
int abilityState_ = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_SLITE_ABILITY_H
|
||||
Executable
+177
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,2 @@
|
||||
## Introduction
|
||||
A data struct named Want utilized to encapsulate some elements in order to simplify the process of starting an application.
|
||||
Executable → Regular
@@ -0,0 +1 @@
|
||||
unittest
|
||||
@@ -0,0 +1,123 @@
|
||||
# Copyright (c) 2020 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("//build/lite/config/component/lite_component.gni")
|
||||
import("//build/lite/config/subsystem/aafwk/config.gni")
|
||||
|
||||
lite_library("abilityms") {
|
||||
target_type = "shared_library"
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Wno-format",
|
||||
"-Wno-format-extra-args",
|
||||
]
|
||||
cflags_cc = cflags
|
||||
|
||||
ldflags = [
|
||||
"-lstdc++",
|
||||
"-lpthread",
|
||||
"-ldl",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/ability_connect_mission.cpp",
|
||||
"src/ability_inner_feature.cpp",
|
||||
"src/ability_mgr_context.cpp",
|
||||
"src/ability_mgr_feature.cpp",
|
||||
"src/ability_mgr_handler.cpp",
|
||||
"src/ability_mgr_service.cpp",
|
||||
"src/ability_mission_record.cpp",
|
||||
"src/ability_mission_stack.cpp",
|
||||
"src/ability_stack_manager.cpp",
|
||||
"src/ability_worker.cpp",
|
||||
"src/app_manager.cpp",
|
||||
"src/app_record.cpp",
|
||||
"src/client/ability_dump_client.cpp",
|
||||
"src/client/ability_thread_client.cpp",
|
||||
"src/client/app_spawn_client.cpp",
|
||||
"src/client/bundlems_client.cpp",
|
||||
"src/client/wms_client.cpp",
|
||||
"src/page_ability_record.cpp",
|
||||
"src/task/ability_activate_task.cpp",
|
||||
"src/task/ability_attach_task.cpp",
|
||||
"src/task/ability_background_task.cpp",
|
||||
"src/task/ability_connect_done_task.cpp",
|
||||
"src/task/ability_connect_task.cpp",
|
||||
"src/task/ability_disconnect_done_task.cpp",
|
||||
"src/task/ability_disconnect_task.cpp",
|
||||
"src/task/ability_dump_task.cpp",
|
||||
"src/task/ability_inactivate_task.cpp",
|
||||
"src/task/ability_start_task.cpp",
|
||||
"src/task/ability_stop_task.cpp",
|
||||
"src/task/ability_terminate_service_task.cpp",
|
||||
"src/task/ability_terminate_task.cpp",
|
||||
"src/task/app_restart_task.cpp",
|
||||
"src/task/app_terminate_task.cpp",
|
||||
"src/util/abilityms_helper.cpp",
|
||||
"src/util/abilityms_status.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"${aafwk_lite_path}/interfaces/kits/ability_lite",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
"${aafwk_lite_path}/frameworks/want_lite/include",
|
||||
"${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
|
||||
"${appexecfwk_lite_path}/utils/bundle_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite",
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite/include",
|
||||
"//foundation/communication/ipc_lite/interfaces/kits",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/registry",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
"//foundation/graphic/wms/interfaces/innerkits",
|
||||
"//base/startup/appspawn_lite/services/include",
|
||||
"//base/security/permission/interfaces/kits/permission_lite",
|
||||
"//base/security/permission/services/permission_lite/pms/include",
|
||||
"//kernel/liteos_a/kernel/include",
|
||||
"//kernel/liteos_a/kernel/common",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//utils/native/lite/include",
|
||||
"include",
|
||||
"include/task",
|
||||
"//third_party/cJSON",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
|
||||
]
|
||||
|
||||
defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ]
|
||||
|
||||
if (enable_ohos_appexecfwk_feature_ability == true) {
|
||||
deps += [ "//foundation/graphic/surface" ]
|
||||
defines += [ "ABILITY_WINDOW_SUPPORT" ]
|
||||
}
|
||||
}
|
||||
|
||||
generate_notice_file("abilityms_notice_file") {
|
||||
module_name = "abilityms"
|
||||
module_source_dir_list = [
|
||||
"//third_party/bounds_checking_function",
|
||||
"//third_party/cJSON",
|
||||
]
|
||||
}
|
||||
|
||||
lite_component("aafwk_services_lite") {
|
||||
features = [
|
||||
":abilityms",
|
||||
"tools:aa",
|
||||
]
|
||||
}
|
||||
Executable
+177
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
Executable
+121
@@ -0,0 +1,121 @@
|
||||
# AMS - Ability manager service of OpenHarmony
|
||||
|
||||
## Introduction
|
||||
|
||||
`Ability manager service` plays an important role in the OpenHarmony. This module focuses on aspect of introducing the feature of AMS aiming at managing ability stack, managing application process and controlling life cycle of ability slices.
|
||||
|
||||
## Features
|
||||
|
||||
- Manage ability stack.
|
||||
- Manage application process.
|
||||
- Controll life cycle of ability slices.
|
||||
- AMS tools.
|
||||
|
||||
## Directions
|
||||
|
||||
```
|
||||
.
|
||||
├── BUILD.gn
|
||||
├── include
|
||||
│ ├── ability_connect_mission.h
|
||||
│ ├── ability_connect_record.h
|
||||
│ ├── ability_connect_trans_param.h
|
||||
│ ├── ability_inner_feature.h
|
||||
│ ├── ability_list.h # ability map to store ability record
|
||||
│ ├── ability_message_id.h # message id of AMS task
|
||||
│ ├── ability_mgr_context.h
|
||||
│ ├── ability_mgr_feature.h # AMS feature in Service Manager
|
||||
│ ├── ability_mgr_handler.h # AMS message handler
|
||||
│ ├── ability_mgr_service.h # register AMS in the Service Manager
|
||||
│ ├── ability_mission_record.h # ability mission record
|
||||
│ ├── ability_mission_stack.h # ability mission record stack
|
||||
│ ├── ability_record.h # ability record including ability info for GT
|
||||
│ ├── ability_service.h # AMS for GT
|
||||
│ ├── ability_stack.h # stack of AMS for GT
|
||||
│ ├── ability_stack_manager.h # ability stack manager
|
||||
│ ├── ability_worker.h # ability task manager
|
||||
│ ├── app_manager.h # application process record manager
|
||||
│ ├── app_record.h # application process record
|
||||
│ ├── client
|
||||
│ │ ├── ability_dump_client.h
|
||||
│ │ ├── ability_thread_client.h
|
||||
│ │ ├── app_spawn_client.h
|
||||
│ │ ├── bundlems_client.h
|
||||
│ │ └── wms_client.h
|
||||
│ ├── js_app_host.h
|
||||
│ ├── page_ability_record.h
|
||||
│ ├── task
|
||||
│ │ ├── ability_activate_task.h
|
||||
│ │ ├── ability_attach_task.h
|
||||
│ │ ├── ability_background_task.h
|
||||
│ │ ├── ability_connect_done_task.h
|
||||
│ │ ├── ability_connect_task.h
|
||||
│ │ ├── ability_disconnect_done_task.h
|
||||
│ │ ├── ability_disconnect_task.h
|
||||
│ │ ├── ability_dump_task.h
|
||||
│ │ ├── ability_inactivate_task.h
|
||||
│ │ ├── ability_start_task.h
|
||||
│ │ ├── ability_stop_task.h
|
||||
│ │ ├── ability_task.h
|
||||
│ │ ├── ability_terminate_service_task.h
|
||||
│ │ ├── ability_terminate_task.h
|
||||
│ │ ├── app_restart_task.h
|
||||
│ │ └── app_terminate_task.h
|
||||
│ └── util
|
||||
│ ├── abilityms_helper.h
|
||||
│ ├── abilityms_log.h
|
||||
│ └── abilityms_status.h
|
||||
├── README.md
|
||||
├── src
|
||||
│ ├── ability_connect_mission.cpp
|
||||
│ ├── ability_inner_feature.cpp
|
||||
│ ├── ability_list.cpp
|
||||
│ ├── ability_mgr_context.cpp
|
||||
│ ├── ability_mgr_feature.cpp
|
||||
│ ├── ability_mgr_handler.cpp
|
||||
│ ├── ability_mgr_service.cpp
|
||||
│ ├── ability_mission_record.cpp
|
||||
│ ├── ability_mission_stack.cpp
|
||||
│ ├── ability_record.cpp
|
||||
│ ├── ability_service.cpp
|
||||
│ ├── ability_stack.cpp
|
||||
│ ├── ability_stack_manager.cpp
|
||||
│ ├── ability_worker.cpp
|
||||
│ ├── app_manager.cpp
|
||||
│ ├── app_record.cpp
|
||||
│ ├── client
|
||||
│ │ ├── ability_dump_client.cpp
|
||||
│ │ ├── ability_thread_client.cpp
|
||||
│ │ ├── app_spawn_client.cpp
|
||||
│ │ ├── bundlems_client.cpp
|
||||
│ │ └── wms_client.cpp
|
||||
│ ├── js_app_host.cpp
|
||||
│ ├── page_ability_record.cpp
|
||||
│ ├── task
|
||||
│ │ ├── ability_activate_task.cpp
|
||||
│ │ ├── ability_attach_task.cpp
|
||||
│ │ ├── ability_background_task.cpp
|
||||
│ │ ├── ability_connect_done_task.cpp
|
||||
│ │ ├── ability_connect_task.cpp
|
||||
│ │ ├── ability_disconnect_done_task.cpp
|
||||
│ │ ├── ability_disconnect_task.cpp
|
||||
│ │ ├── ability_dump_task.cpp
|
||||
│ │ ├── ability_inactivate_task.cpp
|
||||
│ │ ├── ability_start_task.cpp
|
||||
│ │ ├── ability_stop_task.cpp
|
||||
│ │ ├── ability_terminate_service_task.cpp
|
||||
│ │ ├── ability_terminate_task.cpp
|
||||
│ │ ├── app_restart_task.cpp
|
||||
│ │ └── app_terminate_task.cpp
|
||||
│ └── util
|
||||
│ ├── abilityms_helper.cpp
|
||||
│ └── abilityms_status.cpp
|
||||
└── tools
|
||||
├── BUILD.gn
|
||||
├── include
|
||||
│ └── ability_tool.h
|
||||
└── src
|
||||
├── ability_tool.cpp
|
||||
└── main.cpp
|
||||
|
||||
```
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_CONNECT_MISSION_H
|
||||
#define OHOS_ABILITY_CONNECT_MISSION_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "page_ability_record.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityConnectMission {
|
||||
public:
|
||||
AbilityConnectMission() = default;
|
||||
~AbilityConnectMission();
|
||||
|
||||
void PushServiceRecord(PageAbilityRecord &abilityRecord);
|
||||
PageAbilityRecord *FindServiceRecord(uint64_t token) const;
|
||||
PageAbilityRecord *FindServiceRecord(const char *bundleName, const char *abilityName) const;
|
||||
PageAbilityRecord *FindServiceRecord(const SvcIdentity &connectSid, uint64_t abilityToken) const;
|
||||
void RemoveServiceRecord(uint64_t token);
|
||||
void RemoveServiceRecord(const char *bundleName);
|
||||
int32_t CountServiceInApp(const char *bundleName);
|
||||
#ifdef OHOS_DEBUG
|
||||
AbilityMsStatus DumpConnectMission() const;
|
||||
#endif
|
||||
void RemoveConnectRecordByPageToken(uint64_t token, const char *bundleName);
|
||||
|
||||
private:
|
||||
std::list<PageAbilityRecord *> serviceRecords_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_CONNECT_MISSION_H
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_CONNECT_RECORD_H
|
||||
#define OHOS_ABILITY_CONNECT_RECORD_H
|
||||
|
||||
#include "liteipc_adapter.h"
|
||||
#include "samgr_lite.h"
|
||||
|
||||
namespace OHOS {
|
||||
enum ConnectStatus {
|
||||
INIT,
|
||||
WAIT_CONNECT,
|
||||
CONNECTING,
|
||||
CONNECTED,
|
||||
DISCONNECTING,
|
||||
DISCONNECT,
|
||||
STOPPING,
|
||||
STOPPED,
|
||||
};
|
||||
|
||||
class AbilityConnectRecord {
|
||||
public:
|
||||
AbilityConnectRecord(const SvcIdentity &identity, uint64_t abilityToken)
|
||||
: connectSid_(identity), abilityToken_(abilityToken) {};
|
||||
|
||||
~AbilityConnectRecord() = default;
|
||||
|
||||
void SetStatus(ConnectStatus status)
|
||||
{
|
||||
status_ = status;
|
||||
}
|
||||
|
||||
ConnectStatus GetStatus() const
|
||||
{
|
||||
return status_;
|
||||
}
|
||||
|
||||
const SvcIdentity &GetConnectSid() const
|
||||
{
|
||||
return connectSid_;
|
||||
}
|
||||
|
||||
uint64_t GetAbilityToken() const
|
||||
{
|
||||
return abilityToken_;
|
||||
}
|
||||
|
||||
private:
|
||||
const SvcIdentity connectSid_;
|
||||
const uint64_t abilityToken_;
|
||||
ConnectStatus status_ = ConnectStatus::INIT;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_CONNECT_RECORD_H
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_CONNECT_TRANS_PARAM_H
|
||||
#define OHOS_ABILITY_CONNECT_TRANS_PARAM_H
|
||||
|
||||
#include <sched.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "liteipc_adapter.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityConnectTransParam {
|
||||
public:
|
||||
AbilityConnectTransParam(Want *want, const SvcIdentity &identity, uint64_t abilityToken)
|
||||
: want_(want), identity_(identity), abilityToken_(abilityToken) {};
|
||||
|
||||
AbilityConnectTransParam() = delete;
|
||||
~AbilityConnectTransParam()
|
||||
{
|
||||
ClearWant(want_);
|
||||
delete want_;
|
||||
};
|
||||
|
||||
const SvcIdentity &GetSvcIdentity() const
|
||||
{
|
||||
return identity_;
|
||||
}
|
||||
|
||||
const Want *GetWant() const
|
||||
{
|
||||
return want_;
|
||||
}
|
||||
|
||||
uint64_t GetToken() const
|
||||
{
|
||||
return abilityToken_;
|
||||
}
|
||||
|
||||
void SetCallingUid(pid_t callingUid)
|
||||
{
|
||||
callingUid_ = callingUid;
|
||||
}
|
||||
|
||||
pid_t GetCallingUid() const
|
||||
{
|
||||
return callingUid_;
|
||||
}
|
||||
|
||||
private:
|
||||
Want *want_ = { nullptr };
|
||||
SvcIdentity identity_;
|
||||
uint64_t abilityToken_ = 0;
|
||||
pid_t callingUid_ = -1;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_CONNECT_TRANS_PARAM_H
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITYMANAGERSERVICE_INNER_FEATURE_H
|
||||
#define OHOS_ABILITYMANAGERSERVICE_INNER_FEATURE_H
|
||||
|
||||
#include "ability_service_interface.h"
|
||||
#include "ability_mgr_handler.h"
|
||||
#include "feature.h"
|
||||
#include "iunknown.h"
|
||||
#include "iproxy_client.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
typedef int32 (*InvokeFunc)(const void *origin, IpcIo *req);
|
||||
|
||||
class AbilityInnerFeature : public Feature {
|
||||
public:
|
||||
static int32 StartKeepAliveApps();
|
||||
static int32 TerminateApp(const char *bundleName);
|
||||
|
||||
static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply);
|
||||
|
||||
static AbilityInnerFeature *GetInstance()
|
||||
{
|
||||
static AbilityInnerFeature instance;
|
||||
return &instance;
|
||||
}
|
||||
~AbilityInnerFeature() = default;
|
||||
private:
|
||||
AbilityInnerFeature();
|
||||
|
||||
static int32 TerminateAppInvoke(const void *origin, IpcIo *req);
|
||||
static int32 DumpAbilityInvoke(const void *origin, IpcIo *req);
|
||||
|
||||
static const char *GetFeatureName(Feature *feature);
|
||||
static void OnFeatureInitialize(Feature *feature, Service *parent, Identity identity);
|
||||
static void OnFeatureStop(Feature *feature, Identity identity);
|
||||
static BOOL OnFeatureMessage(Feature *feature, Request *request);
|
||||
|
||||
private:
|
||||
Identity identity_;
|
||||
static InvokeFunc invokeFuncList[COMMAND_END - INNER_BEGIN];
|
||||
DISALLOW_COPY_AND_MOVE(AbilityInnerFeature);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
INHERIT_IUNKNOWNENTRY(AmsInnerInterface);
|
||||
AbilityInnerFeature *ams;
|
||||
} AbilityInnerFeatureImpl;
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITYMANAGERSERVICE_INNER_FEATURE_H
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_LIST_H
|
||||
#define OHOS_ABILITY_LIST_H
|
||||
|
||||
#include "ability_record.h"
|
||||
#include "utils_list.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityList {
|
||||
public:
|
||||
AbilityList() = default;
|
||||
~AbilityList() = default;
|
||||
|
||||
void Add(AbilityRecord *abilityRecord);
|
||||
AbilityRecord *Get(uint16_t token) const;
|
||||
AbilityRecord *Get(const char *bundleName) const;
|
||||
void Erase(uint16_t token);
|
||||
|
||||
private:
|
||||
List<AbilityRecord *> abilityList_ {};
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_LIST_H
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_MESSAGE_ID_H
|
||||
#define OHOS_ABILITY_MESSAGE_ID_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
enum AmsMsgType {
|
||||
#ifndef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
AMS_SERVICE_INITED = 0x1000,
|
||||
AMS_START_ABILITY,
|
||||
AMS_TERMINATE_ABILITY,
|
||||
AMS_ONSTART,
|
||||
AMS_ONACTIVE,
|
||||
AMS_ONBACKGROUND,
|
||||
AMS_ONDESTROY,
|
||||
AMS_SENDMESSAGE,
|
||||
AMS_REGISTER,
|
||||
AMS_UNREGISTER,
|
||||
|
||||
AMS_START_CHECK_REQUEST,
|
||||
AMS_START_CHECK_RESPONSE,
|
||||
|
||||
/* msgId used to communicated with Launcher */
|
||||
LAUNCHER_SCHEDULE_ACTIVE,
|
||||
LAUNCHER_SCHEDULE_BACKGROUND,
|
||||
// The above value is for watch gt, don't change the order
|
||||
#else
|
||||
AMS_SERVICE_INITED = 0,
|
||||
AMS_START_ABILITY,
|
||||
AMS_TERMINATE_ABILITY,
|
||||
|
||||
AMS_ATTACH_BUNDLE,
|
||||
AMS_TRANSACTION_DONE,
|
||||
|
||||
AMS_CONNECT_ABILITY,
|
||||
AMS_CONNECT_ABILITY_DONE,
|
||||
AMS_DISCONNECT_ABILITY,
|
||||
AMS_DISCONNECT_ABILITY_DONE,
|
||||
AMS_TERMINATE_SERVICE,
|
||||
AMS_TERMINATE_APP,
|
||||
AMS_RESTART_APP,
|
||||
AMS_DUMP_ABILITY,
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif // OHOS_ABILITY_MESSAGE_ID_H
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_MGR_CONTEXT_H
|
||||
#define OHOS_ABILITY_MGR_CONTEXT_H
|
||||
|
||||
#include "ability_mission_stack.h"
|
||||
#include "ability_connect_mission.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityMgrContext {
|
||||
public:
|
||||
AbilityMgrContext();
|
||||
~AbilityMgrContext();
|
||||
|
||||
const AbilityMissionStack *GetLauncherMissionStacks() const;
|
||||
const AbilityMissionStack *GetDefaultMissionStacks() const;
|
||||
const AbilityMissionStack *GetTopMissionStacks() const;
|
||||
const AbilityMissionStack *GetTargetMissionStack(const char *bundleName) const;
|
||||
const AbilityConnectMission *GetServiceConnects() const;
|
||||
void SetTopMissionStacks(const AbilityMissionStack *stack);
|
||||
private:
|
||||
AbilityMissionStack *launcherMissionStacks_ { nullptr };
|
||||
AbilityMissionStack *defaultMissionStacks_ { nullptr };
|
||||
AbilityConnectMission *serviceConnects_ { nullptr };
|
||||
const AbilityMissionStack *topMissionStacks_ { nullptr };
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_MGR_CONTEXT_H
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITYMANAGERSERVICE_FEATURE_H
|
||||
#define OHOS_ABILITYMANAGERSERVICE_FEATURE_H
|
||||
|
||||
#include "ability_mgr_handler.h"
|
||||
#include "ability_service_interface.h"
|
||||
#include "feature.h"
|
||||
#include "iproxy_client.h"
|
||||
#include "iunknown.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
typedef int32 (*InvokeFunc)(const void *origin, IpcIo *req);
|
||||
|
||||
class AbilityMgrFeature : public Feature {
|
||||
public:
|
||||
static int32 StartAbility(const Want *want);
|
||||
static int32 TerminateAbility(uint64_t token);
|
||||
static int32 ConnectAbility(const Want *want, SvcIdentity *svc, uint64_t token);
|
||||
static int32 DisconnectAbility(SvcIdentity *svc, uint64_t token);
|
||||
static int32 StopAbility(const Want *want);
|
||||
|
||||
static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply);
|
||||
|
||||
static int32 AppDeathNotify(const IpcContext* context, void *ipcMsg, IpcIo *data, void *arg);
|
||||
static AbilityMgrFeature *GetInstance()
|
||||
{
|
||||
static AbilityMgrFeature instance;
|
||||
return &instance;
|
||||
}
|
||||
~AbilityMgrFeature() = default;
|
||||
private:
|
||||
AbilityMgrFeature();
|
||||
static int32 StartAbilityInner(const Want *want, pid_t callingUid);
|
||||
static int32 ConnectAbilityInner(const Want *want, SvcIdentity *svc, uint64_t token, pid_t callingUid);
|
||||
static int32 StopAbilityInner(const Want *want, pid_t callingUid);
|
||||
static int32 StartAbilityInvoke(const void *origin, IpcIo *req);
|
||||
static int32 TerminateAbilityInvoke(const void *origin, IpcIo *req);
|
||||
static int32 ConnectAbilityInvoke(const void *origin, IpcIo *req);
|
||||
static int32 DisconnectAbilityInvoke(const void *origin, IpcIo *req);
|
||||
static int32 StopAbilityInvoke(const void *origin, IpcIo *req);
|
||||
|
||||
static int32 AbilityTransactionDoneInvoke(const void *origin, IpcIo *req);
|
||||
static int32 AttachBundleInvoke(const void *origin, IpcIo *req);
|
||||
static int32 ConnectAbilityDoneInvoke(const void *origin, IpcIo *req);
|
||||
static int32 DisconnectAbilityDoneInvoke(const void *origin, IpcIo *req);
|
||||
static int32 RestartApp(const char *bundleName);
|
||||
|
||||
static const char *GetFeatureName(Feature *feature);
|
||||
static void OnFeatureInitialize(Feature *feature, Service *parent, Identity identity);
|
||||
static void OnFeatureStop(Feature *feature, Identity identity);
|
||||
static BOOL OnFeatureMessage(Feature *feature, Request *request);
|
||||
|
||||
private:
|
||||
Identity identity_;
|
||||
static InvokeFunc invokeFuncList[INNER_BEGIN];
|
||||
DISALLOW_COPY_AND_MOVE(AbilityMgrFeature);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
INHERIT_IUNKNOWNENTRY(AmsInterface);
|
||||
AbilityMgrFeature *ams;
|
||||
} AbilityMgrFeatureImpl;
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITYMANAGERSERVICE_FEATURE_H
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_MANAGER_SERVICE_IMPL_H
|
||||
#define OHOS_ABILITY_MANAGER_SERVICE_IMPL_H
|
||||
|
||||
#include "ability_connect_trans_param.h"
|
||||
#include "ability_worker.h"
|
||||
#include "client/ability_dump_client.h"
|
||||
#include "client/bundlems_client.h"
|
||||
#include "message.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityMgrHandler : public NoCopyable {
|
||||
public:
|
||||
static AbilityMgrHandler &GetInstance()
|
||||
{
|
||||
static AbilityMgrHandler instance;
|
||||
return instance;
|
||||
}
|
||||
~AbilityMgrHandler() = default;
|
||||
void Init();
|
||||
void ServiceMsgProcess(const Request& request);
|
||||
private:
|
||||
AbilityMgrHandler() = default;
|
||||
void OnServiceInited();
|
||||
void StartKeepAliveApps();
|
||||
void StartKeepAliveApp(const BundleInfo &bundleInfo);
|
||||
void StartLauncher();
|
||||
int StartAbility(const Want *want, pid_t callingUid);
|
||||
void AttachBundle(AbilityThreadClient *client);
|
||||
void TerminateAbility(const uint64_t *token);
|
||||
void AbilityTransaction(TransactionState *state);
|
||||
void TerminateApp(const char *bundleName);
|
||||
void RestartApp(const char *bundleName);
|
||||
|
||||
int ConnectAbility(AbilityConnectTransParam *transParam);
|
||||
void DisconnectAbility(AbilityConnectTransParam *transParam);
|
||||
void ConnectAbilityDone(AbilityConnectTransParam *transParam);
|
||||
void DisconnectAbilityDone(const uint64_t *token);
|
||||
void TerminateService(Want *want, pid_t callingUid);
|
||||
void StartAbilityCallback(const Want *want, int code);
|
||||
void DumpAbility(const AbilityDumpClient *client);
|
||||
void ConnectAbilityCallback(AbilityConnectTransParam *transParam, int code);
|
||||
|
||||
AbilityWorker abilityWorker_;
|
||||
BundleMsClient bundleMsClient_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_MANAGER_SERVICE_IMPL_H
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITYMGRSERVICE_SERVICE_H
|
||||
#define OHOS_ABILITYMGRSERVICE_SERVICE_H
|
||||
|
||||
#include "service.h"
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityMgrService : public Service {
|
||||
public:
|
||||
static AbilityMgrService *GetInstance()
|
||||
{
|
||||
static AbilityMgrService instance;
|
||||
return &instance;
|
||||
}
|
||||
~AbilityMgrService() = default;
|
||||
const Identity *GetIdentity();
|
||||
|
||||
private:
|
||||
AbilityMgrService();
|
||||
static const char *GetServiceName(Service *service);
|
||||
static BOOL ServiceInitialize(Service *service, Identity identity);
|
||||
static TaskConfig GetServiceTaskConfig(Service *service);
|
||||
static BOOL ServiceMessageHandle(Service *service, Request *request);
|
||||
|
||||
private:
|
||||
Identity identity_;
|
||||
DISALLOW_COPY_AND_MOVE(AbilityMgrService);
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITYMGRSERVICE_SERVICE_H
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITYMANAGERSERVICE_SLITE_FEATURE_H
|
||||
#define OHOS_ABILITYMANAGERSERVICE_SLITE_FEATURE_H
|
||||
|
||||
#include "ability_service.h"
|
||||
#include "ability_service_interface.h"
|
||||
#include "feature.h"
|
||||
#include "iproxy_client.h"
|
||||
#include "iunknown.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityMgrSliteFeature : public Feature {
|
||||
public:
|
||||
static int32 StartAbility(const Want *want);
|
||||
static int32 TerminateAbility(uint64_t token);
|
||||
static int32 SchedulerLifecycleDone(uint64_t token, int state);
|
||||
|
||||
static AbilityMgrSliteFeature *GetInstance()
|
||||
{
|
||||
static AbilityMgrSliteFeature instance;
|
||||
return &instance;
|
||||
}
|
||||
~AbilityMgrSliteFeature() = default;
|
||||
private:
|
||||
AbilityMgrSliteFeature();
|
||||
static const char *GetFeatureName(Feature *feature);
|
||||
static void OnFeatureInitialize(Feature *feature, Service *parent, Identity identity);
|
||||
static void OnFeatureStop(Feature *feature, Identity identity);
|
||||
static BOOL OnFeatureMessage(Feature *feature, Request *request);
|
||||
|
||||
private:
|
||||
Identity identity_;
|
||||
AbilityService *abilityService_;
|
||||
DISALLOW_COPY_AND_MOVE(AbilityMgrSliteFeature);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
INHERIT_IUNKNOWNENTRY(AmsSliteInterface);
|
||||
AbilityMgrSliteFeature *ams;
|
||||
} AbilityMgrSliteFeatureImpl;
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITYMANAGERSERVICE_SLITE_FEATURE_H
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_MISSION_RECORD_H
|
||||
#define OHOS_ABILITY_MISSION_RECORD_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "ability_connect_mission.h"
|
||||
#include "page_ability_record.h"
|
||||
|
||||
namespace OHOS {
|
||||
class AbilityMissionStack;
|
||||
class AbilityMissionRecord {
|
||||
public:
|
||||
AbilityMissionRecord(AbilityMissionStack *missionStack, const char *bundleName);
|
||||
~AbilityMissionRecord();
|
||||
bool IsEmpty() const;
|
||||
bool IsSameMissionRecord(const char *bundleName) const;
|
||||
void SetMissionStack(AbilityMissionStack *missionStack);
|
||||
const AbilityMissionStack *GetMissionStack() const;
|
||||
const PageAbilityRecord *GetTopPageAbility() const;
|
||||
const PageAbilityRecord *GetBottomPageAbility() const;
|
||||
PageAbilityRecord *FindPageAbility(uint64_t token) const;
|
||||
PageAbilityRecord *FindPageAbility(const Want &want) const;
|
||||
PageAbilityRecord *GetPrevPageAbility(const PageAbilityRecord ¤t) const;
|
||||
void PushPageAbility(PageAbilityRecord &abilityRecord);
|
||||
void RemovePageAbility(const PageAbilityRecord &target);
|
||||
void ClearPageAbility();
|
||||
void ClearPageAbility(AbilityConnectMission *connectMission);
|
||||
void SetPrevMissionRecord(const AbilityMissionRecord *missionRecord);
|
||||
const AbilityMissionRecord *GetPrevMissionRecord() const;
|
||||
#ifdef OHOS_DEBUG
|
||||
AbilityMsStatus DumpMissionRecord() const;
|
||||
#endif
|
||||
private:
|
||||
AbilityMissionStack *abilityMissionStack_ { nullptr };
|
||||
std::list<PageAbilityRecord *> pageAbilityRecords_;
|
||||
const AbilityMissionRecord *prevMissionRecord_ { nullptr };
|
||||
const char *bundleName_ { nullptr };
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_MISSION_RECORD_H
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_MISSION_STACK_H
|
||||
#define OHOS_ABILITY_MISSION_STACK_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "ability_connect_mission.h"
|
||||
#include "ability_mission_record.h"
|
||||
|
||||
namespace OHOS {
|
||||
typedef enum {
|
||||
LAUNCHER,
|
||||
DEFAULT,
|
||||
} StackType;
|
||||
class AbilityMissionStack {
|
||||
public:
|
||||
explicit AbilityMissionStack(StackType type);
|
||||
~AbilityMissionStack();
|
||||
StackType GetStackType() const;
|
||||
// MissionRecord
|
||||
void PushTopMissionRecord(AbilityMissionRecord &missionRecord);
|
||||
void MoveMissionRecordToTop(AbilityMissionRecord &missionRecord);
|
||||
AbilityMissionRecord *GetTargetMissionRecord(const char *bundleName) const;
|
||||
const AbilityMissionRecord *GetTopMissionRecord() const;
|
||||
void RemoveMissionRecord(AbilityMissionRecord &missionRecord);
|
||||
void RemoveMissionRecord(AbilityConnectMission *connectMission, const char *bundleName);
|
||||
bool IsTopMissionRecord(const char *bundleName) const;
|
||||
// PageAbilityRecord
|
||||
PageAbilityRecord *FindPageAbility(uint64_t token) const;
|
||||
PageAbilityRecord *FindPageAbility(const Want &want) const;
|
||||
const PageAbilityRecord *GetTopPageAbility() const;
|
||||
#ifdef OHOS_DEBUG
|
||||
AbilityMsStatus DumpMissionStack() const;
|
||||
#endif
|
||||
private:
|
||||
std::list<AbilityMissionRecord *> missionRecords_;
|
||||
StackType stackType_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_MISSION_STACK_H
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RECORD_H
|
||||
#define OHOS_ABILITY_RECORD_H
|
||||
|
||||
#ifdef APP_PLATFORM_WATCHGT
|
||||
#include "cmsis_os.h"
|
||||
#endif
|
||||
#include "ability_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
class JsAppHost;
|
||||
|
||||
constexpr int FAIL_CALLBACK_ERRORCODE = 200;
|
||||
|
||||
/* States-feedback from launcher to AMS */
|
||||
typedef enum {
|
||||
SCHEDULE_INITED,
|
||||
SCHEDULE_INACTIVE,
|
||||
SCHEDULE_ACTIVE,
|
||||
SCHEDULE_BACKGROUND,
|
||||
SCHEDULE_STOP
|
||||
} AbilityState;
|
||||
|
||||
typedef enum {
|
||||
STATE_JS_RUNNING,
|
||||
STATE_NATIVE_RUNNING,
|
||||
STATE_JS_JUMP_NATIVE,
|
||||
STATE_NATIVE_JUMP_JS,
|
||||
STATE_JS_JUMP_JS,
|
||||
} AppState;
|
||||
|
||||
class AbilityRecord {
|
||||
public:
|
||||
AbilityRecord();
|
||||
~AbilityRecord();
|
||||
|
||||
void SetAppName(const char *appName);
|
||||
const char *GetAppName() const
|
||||
{
|
||||
return appName_;
|
||||
}
|
||||
|
||||
void SetAppPath(const char *appPath);
|
||||
const char *GetAppPath() const
|
||||
{
|
||||
return appPath_;
|
||||
}
|
||||
|
||||
void SetAppData(const void *appData, uint16_t dataLength);
|
||||
const void *GetAppData() const
|
||||
{
|
||||
return appData_;
|
||||
}
|
||||
|
||||
void SetAbilityInfo(const AbilityInfo abilityInfo)
|
||||
{
|
||||
abilityInfo_ = abilityInfo;
|
||||
}
|
||||
|
||||
AbilityInfo GetAbilityInfo() const
|
||||
{
|
||||
return abilityInfo_;
|
||||
}
|
||||
|
||||
uint16_t GetDataLength() const
|
||||
{
|
||||
return dataLength_;
|
||||
}
|
||||
|
||||
void SetState(const AbilityState state)
|
||||
{
|
||||
state_ = state;
|
||||
}
|
||||
|
||||
AbilityState GetState() const
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
|
||||
bool IsAttached() const
|
||||
{
|
||||
return state_ != SCHEDULE_STOP;
|
||||
}
|
||||
|
||||
void SetToken(uint16_t token)
|
||||
{
|
||||
token_ = token;
|
||||
}
|
||||
uint16_t GetToken() const
|
||||
{
|
||||
return token_;
|
||||
}
|
||||
|
||||
void SetTaskId(UINT32 taskId)
|
||||
{
|
||||
taskId_ = taskId;
|
||||
}
|
||||
|
||||
UINT32 GetTaskId() const
|
||||
{
|
||||
return taskId_;
|
||||
}
|
||||
|
||||
void SetTerminated(bool isTerminated)
|
||||
{
|
||||
isTerminated_ = isTerminated;
|
||||
}
|
||||
|
||||
bool IsTerminated() const
|
||||
{
|
||||
return isTerminated_;
|
||||
}
|
||||
|
||||
void SetMessageQueueId(const osMessageQueueId_t jsAppQueueId)
|
||||
{
|
||||
jsAppQueueId_ = jsAppQueueId;
|
||||
}
|
||||
|
||||
const osMessageQueueId_t& GetMessageQueueId() const
|
||||
{
|
||||
return jsAppQueueId_;
|
||||
}
|
||||
|
||||
void SetJsAppHost(const JsAppHost *jsAppHost)
|
||||
{
|
||||
jsAppHost_ = const_cast<JsAppHost *>(jsAppHost);
|
||||
}
|
||||
|
||||
const JsAppHost *GetJsAppHost() const
|
||||
{
|
||||
return jsAppHost_;
|
||||
}
|
||||
|
||||
static void CopyAbilityRecord(AbilityRecord &abilityRecord, AbilityRecord &newAbilityRecord);
|
||||
|
||||
private:
|
||||
char *appName_ { nullptr };
|
||||
char *appPath_ { nullptr };
|
||||
AbilityInfo abilityInfo_;
|
||||
void *appData_ { nullptr };
|
||||
uint16_t dataLength_ { 0 };
|
||||
AbilityState state_ { SCHEDULE_STOP };
|
||||
uint16_t token_ { 0 };
|
||||
UINT32 taskId_ { 0 };
|
||||
osMessageQueueId_t jsAppQueueId_ { nullptr };
|
||||
JsAppHost *jsAppHost_ { nullptr };
|
||||
bool isTerminated_ = false;
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_RECORD_H
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_SERVICE_H
|
||||
#define OHOS_ABILITY_SERVICE_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ability_list.h"
|
||||
#include "ability_record.h"
|
||||
#include "ability_stack.h"
|
||||
#include "adapter.h"
|
||||
#include "js_app_host.h"
|
||||
#include "nocopyable.h"
|
||||
#include "want.h"
|
||||
#include "slite_ability.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct AbilitySvcInfo {
|
||||
char *bundleName;
|
||||
char *path;
|
||||
void *data;
|
||||
uint16_t dataLength;
|
||||
};
|
||||
|
||||
class AbilityService : public NoCopyable {
|
||||
public:
|
||||
static AbilityService& GetInstance()
|
||||
{
|
||||
static AbilityService instance;
|
||||
return instance;
|
||||
}
|
||||
~AbilityService() override;
|
||||
int32_t StartAbility(const Want *want);
|
||||
int32_t TerminateAbility(uint16_t token);
|
||||
int32_t SchedulerLifecycleDone(uint64_t token, int32_t state);
|
||||
void setNativeAbility(const SliteAbility *ability);
|
||||
void StartLauncher();
|
||||
void CleanWant();
|
||||
Want *want_ = nullptr;
|
||||
|
||||
private:
|
||||
static uint16_t GenerateToken();
|
||||
AbilityService();
|
||||
int32_t StartAbility(AbilitySvcInfo *info);
|
||||
int32_t PreCheckStartAbility(const char *bundleName, const char *path, const void *data, uint16_t dataLength);
|
||||
bool CheckResponse(const char *bundleName);
|
||||
int32_t SchedulerLifecycle(uint64_t token, int32_t state);
|
||||
int32_t SchedulerLifecycleInner(const AbilityRecord *record, int32_t state);
|
||||
void SchedulerAbilityLifecycle(SliteAbility *ability, const Want &want, int32_t state);
|
||||
int32_t CreateAppTask(AbilityRecord *record);
|
||||
void OnActiveDone(uint16_t token);
|
||||
void OnBackgroundDone(uint16_t token);
|
||||
void OnDestroyDone(uint16_t token);
|
||||
void DeleteRecordInfo(uint16_t token);
|
||||
bool SendMsgToJsAbility(int32_t msgId, const AbilityRecord *record);
|
||||
void SetAbilityState(uint64_t token, int32_t state);
|
||||
void UpdataRecord(AbilitySvcInfo *info);
|
||||
|
||||
uint16_t pendingToken_ { 0 };
|
||||
AbilityList abilityList_ {};
|
||||
AbilityStack abilityStack_ {};
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_SERVICE_H
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user