mirror of
https://github.com/openharmony/appexecfwk_appexecfwk_lite.git
synced 2026-06-30 21:07:55 -04:00
update openharmony 1.0.1
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
### 该问题是怎么引起的?
|
||||
|
||||
|
||||
|
||||
### 重现步骤
|
||||
|
||||
|
||||
|
||||
### 报错信息
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
### 相关的Issue
|
||||
|
||||
|
||||
### 原因(目的、解决的问题等)
|
||||
|
||||
|
||||
### 描述(做了什么,变更了什么)
|
||||
|
||||
|
||||
### 测试用例(新增、改动、可能影响的功能)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# Bundle Management Framework<a name="EN-US_TOPIC_0000001061838370"></a>
|
||||
|
||||
- [Introduction](#section11660541593)
|
||||
- [Directory Structure](#section1464106163817)
|
||||
- [Repositories Involved](#section93061357133720)
|
||||
|
||||
## Introduction<a name="section11660541593"></a>
|
||||
|
||||
The bundle management framework is provided by OpenHarmony for you to manage application bundles \(installation packages\). The following figure shows the architecture of the bundle management framework.
|
||||
|
||||
**Figure 1** Bundle management framework architecture<a name="fig1047932418305"></a>
|
||||

|
||||
|
||||
- **BundleKit** includes external APIs provided by the Bundle Manager Service, including the APIs for application installation and uninstallation, bundle information query, and bundle state change listeners.
|
||||
- The **bundle scanning sub-module** parses pre-installed or installed bundles on the local device and extracts information from them for the bundle management sub-module to manage and make the information persistent for storage.
|
||||
|
||||
- The **bundle installation sub-module** installs, uninstalls, and updates a bundle.
|
||||
- The **bundle installation service** is an independent process used to create or delete installation directories and has high permissions.
|
||||
|
||||
- The **bundle management sub-module** manages information related to application bundles and stores persistent bundle information.
|
||||
|
||||
- The **bundle security management sub-module** verifies signatures, and grants and manages permissions.
|
||||
|
||||
## Directory Structure<a name="section1464106163817"></a>
|
||||
|
||||
```
|
||||
/foundation/appexecfwk/appexecfwk_lite
|
||||
├── frameworks
|
||||
│ └── bundle_lite # Client code used for communication between the BundleKit and Bundle Manager Service
|
||||
├── interfaces
|
||||
│ ├── kits
|
||||
│ │ └── bundle_lite # BundleKit APIs exposed externally
|
||||
│ └── innerkits
|
||||
│ └── bundlemgr_lite # Core implementation code of BundleKit and internal APIs provided by the Bundle Manager Service for other subsystems
|
||||
├── services
|
||||
│ └── bundlemgr_lite # Implementation code of the Bundle Manager Service
|
||||
└── utils
|
||||
└── bundle_lite # Utility code used during the implementation of the Bundle Manager Service
|
||||
```
|
||||
|
||||
- The Bundle Manager Service is running in the foundation process.
|
||||
- The Bundle 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 Bundle Manager Service, see [SA Framework](en-us_topic_0000001051589563.md).
|
||||
- The Bundle Manager Service starts upon OS startup.
|
||||
- You can use the bm tool to install the specified HAP. \(Taking **hispark\_taurus** as an example, you can obtain the bm tool from the **out/hispark\_taurus/ipcamera\_hispark\_taurus/dev\_tools/bin directory** after the version building.\)
|
||||
|
||||
```
|
||||
./bin/bm install -p /nfs/xxxx.hap
|
||||
```
|
||||
|
||||
## Repositories Involved<a name="section93061357133720"></a>
|
||||
|
||||
Application framework
|
||||
|
||||
aafwk\_lite
|
||||
|
||||
**appexecfwk\_lite**
|
||||
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
# 包管理组件<a name="ZH-CN_TOPIC_0000001061838370"></a>
|
||||
|
||||
- [简介](#section11660541593)
|
||||
- [目录](#section1464106163817)
|
||||
- [相关仓](#section93061357133720)
|
||||
|
||||
## 简介<a name="section11660541593"></a>
|
||||
|
||||
**包管理组件**,是OpenHarmony为开发者提供的安装包管理框架。包管理组件的由如下模块组成:
|
||||
|
||||
**图 1** 包管理组件框架图<a name="fig1047932418305"></a>
|
||||

|
||||
|
||||
- **BundleKit:**是包管理服务对外提供的接口,有安装/卸载接口、包信息查询接口、包状态变化监听接口。
|
||||
- **包扫描子模块**:用来解析本地预制或者安装的安装包,提取里面的各种信息,供管理子模块进行管理,持久化。
|
||||
|
||||
- **包安装子模块**:负责安装,卸载,升级一个包。
|
||||
- **包安装服务**:一个单独进程的用于创建删除安装目录,具有较高的权限。
|
||||
|
||||
- **包管理子模块**:管理安装包相关的信息,存储持久化包信息。
|
||||
|
||||
- **包安全管理子模块**:签名检查、权限授予、权限管理。
|
||||
|
||||
## 目录<a name="section1464106163817"></a>
|
||||
|
||||
```
|
||||
/foundation/appexecfwk/appexecfwk_lite
|
||||
├── frameworks
|
||||
│ └── bundle_lite # 管理BundleKit与包管理服务通信的客户端代码
|
||||
├── interfaces
|
||||
│ ├── kits
|
||||
│ │ └── bundle_lite # BundleKit为开发者提供的接口
|
||||
│ └── innerkits
|
||||
│ └── bundlemgr_lite # BundleKit实现的核心代码,及包管理服务为其它子系统提供的接口
|
||||
├── services
|
||||
│ └── bundlemgr_lite # 包管理服务的实现代码
|
||||
└── utils
|
||||
└── bundle_lite # 包管理服务实现中用到的工具性的代码
|
||||
```
|
||||
|
||||
- 包管理服务为BundleMs,服务运行于foudation进程中;
|
||||
- BundleMs注册到sa\_manager中,sa\_manager运行于foundation进程中,sa\_manager为BundleMs创建线程运行环境。具体创建BundleMs服务的方式以及使用该服务的方式,可参考[系统服务框架子系统](zh-cn_topic_0000001051589563.md);
|
||||
- 系统启动后,BundleMs会随系统启动而启动;
|
||||
- 使用bm工具可以安装指定的hap包(以hispark\_taurus为例,bm工具在系统构建后放置在out/hispark\_taurus/ipcamera\_hispark\_taurus/dev\_tools/bin下):
|
||||
|
||||
```
|
||||
./bin/bm install -p /nfs/xxxx.hap
|
||||
```
|
||||
|
||||
## 相关仓<a name="section93061357133720"></a>
|
||||
|
||||
用户程序框架子系统
|
||||
|
||||
aafwk\_lite
|
||||
|
||||
**appexecfwk\_lite**
|
||||
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 143 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
@@ -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.
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
import("//build/lite/ndk/ndk.gni")
|
||||
|
||||
generate_notice_file("bundle_notice_file") {
|
||||
module_name = "bundle"
|
||||
module_source_dir_list = [
|
||||
"//third_party/bounds_checking_function",
|
||||
"//third_party/cJSON",
|
||||
]
|
||||
}
|
||||
|
||||
lite_component("appexecfwk_kits_lite") {
|
||||
features = [ ":bundle" ]
|
||||
}
|
||||
|
||||
lite_library("bundle") {
|
||||
target_type = "shared_library"
|
||||
sources = [
|
||||
"src/ability_info.cpp",
|
||||
"src/ability_info_utils.cpp",
|
||||
"src/bundle_callback.cpp",
|
||||
"src/bundle_callback_utils.cpp",
|
||||
"src/bundle_info.cpp",
|
||||
"src/bundle_info_utils.cpp",
|
||||
"src/bundle_manager.cpp",
|
||||
"src/bundle_self_callback.cpp",
|
||||
"src/convert_utils.cpp",
|
||||
"src/element_name.cpp",
|
||||
"src/module_info.cpp",
|
||||
"src/module_info_utils.cpp",
|
||||
"src/token_generate.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${aafwk_lite_path}/frameworks/want_lite:want",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//base/security/permission/services/permission_lite/pms_client:pms_client",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-fPIC",
|
||||
"-Wall",
|
||||
"-Wno-format",
|
||||
]
|
||||
cflags_cc = cflags
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//base/security/permission/interfaces/kits/permission_lite",
|
||||
"//base/security/permission/services/permission_lite/pms/include",
|
||||
"${aafwk_lite_path}/frameworks/want_lite/include",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
"${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
|
||||
"${appexecfwk_lite_path}/utils/bundle_lite",
|
||||
"//foundation/communication/ipc_lite/interfaces/kits",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/kits/registry",
|
||||
"//kernel/liteos_a/kernel/include",
|
||||
"//kernel/liteos_a/kernel/common",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//utils/native/lite/include",
|
||||
"//third_party/cJSON",
|
||||
]
|
||||
|
||||
defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ]
|
||||
}
|
||||
|
||||
ndk_lib("bundle_notes") {
|
||||
lib_extension = ".so"
|
||||
deps = [ ":bundle" ]
|
||||
head_files = [ "${appexecfwk_lite_path}/interfaces/kits/bundle_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
|
||||
@@ -0,0 +1,35 @@
|
||||
## Introduction
|
||||
|
||||
The implementation files of the corresponding `.h` files are provided at here and a tool `bm` can be utilized by developers to install, uninstall application or query some information of the specified application.
|
||||
|
||||
## Directions
|
||||
|
||||
```
|
||||
.
|
||||
├── BUILD.gn
|
||||
├── include
|
||||
│ ├── ability_info_utils.h # to provide some function to set the elements of AbilityInfo.
|
||||
│ ├── bundle_callback.h # to provide monitor mechanism of install states for other module in the system.
|
||||
│ ├── bundle_callback_utils.h # to define some data structs to obtain the specified information return from the BMS `Bunndle Manager Servcice`.
|
||||
│ ├── bundle_info_utils.h # to provide some functions to set the elements of BundleInfo.
|
||||
│ ├── bundle_self_callback.h # to provide the callback mechanism of install function and uninstall function.
|
||||
│ ├── convert_utils.h # to provide some functions to transform AbilityInfo and BundleInfo to string, and then to transport by ipc.
|
||||
│ └── module_info_utils.h # to provide some function to set the elements of ModuleInfo.
|
||||
├── README.md
|
||||
└── src
|
||||
├── ability_info.cpp
|
||||
├── ability_info_utils.cpp
|
||||
├── bundle_callback.cpp
|
||||
├── bundle_callback_utils.cpp
|
||||
├── bundle_info.cpp
|
||||
├── bundle_info_utils.cpp
|
||||
├── bundle_manager.cpp
|
||||
├── bundle_self_callback.cpp
|
||||
├── convert_utils.cpp
|
||||
├── element_name.cpp
|
||||
├── event_handler.cpp
|
||||
├── module_info.cpp
|
||||
├── module_info_utils.cpp
|
||||
└── token_generate.cpp
|
||||
|
||||
```
|
||||
@@ -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_ABILITYINFO_UTILS_H
|
||||
#define OHOS_ABILITYINFO_UTILS_H
|
||||
|
||||
#include "ability_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct AbilityInfoUtils {
|
||||
static void CopyAbilityInfo(AbilityInfo *des, AbilityInfo src);
|
||||
static bool SetAbilityInfoBundleName(AbilityInfo *abilityInfo, const char *bundleName);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
static bool SetAbilityInfoModuleName(AbilityInfo *abilityInfo, const char *moduleName);
|
||||
static bool SetAbilityInfoName(AbilityInfo *abilityInfo, const char *name);
|
||||
static bool SetAbilityInfoDescription(AbilityInfo *abilityInfo, const char *description);
|
||||
static bool SetAbilityInfoIconPath(AbilityInfo *abilityInfo, const char *iconPath);
|
||||
static bool SetAbilityInfoDeviceId(AbilityInfo *abilityInfo, const char *deviceId);
|
||||
static bool SetAbilityInfoLabel(AbilityInfo *abilityInfo, const char *label);
|
||||
#else
|
||||
static bool SetAbilityInfoSrcPath(AbilityInfo *abilityInfo, const char *srcPath);
|
||||
#endif
|
||||
private:
|
||||
AbilityInfoUtils() = default;
|
||||
~AbilityInfoUtils() = default;
|
||||
}; // AbilityInfoUtils
|
||||
} // OHOS
|
||||
#endif // OHOS_ABILITYINFO_UTILS_H
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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_BUNDLE_CALLBACK_H
|
||||
#define OHOS_BUNDLE_CALLBACK_H
|
||||
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "bundle_callback_utils.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
class BundleCallback {
|
||||
public:
|
||||
~BundleCallback();
|
||||
static BundleCallback& GetInstance()
|
||||
{
|
||||
static BundleCallback instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
int32_t RegisterBundleStateCallback(const BundleStateCallback &callback, const char *bundleName, void *data);
|
||||
int32_t UnregisterBundleStateCallback();
|
||||
int32_t GenerateLocalServiceId();
|
||||
int32_t TransmitServiceId(const SvcIdentity &svc, bool flag);
|
||||
BundleCallbackInfo GetCallbackInfoByName(const char *bundleName);
|
||||
private:
|
||||
BundleCallback() = default;
|
||||
|
||||
BundleStateCallback bundleStateCallback_ { nullptr }; // register callback for all apps
|
||||
SvcIdentity *svcIdentity_ { nullptr };
|
||||
void *innerData_ { nullptr };
|
||||
std::unordered_map<std::string, BundleCallbackInfo> callbackMap_ {};
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(BundleCallback);
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLE_CALLBACK_H
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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_BUNDLE_CALLBACK_UTILS_H
|
||||
#define OHOS_BUNDLE_CALLBACK_UTILS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "bundle_info.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "bundle_status_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
const char INSTALL_SUCCESS[] = "install success !";
|
||||
const char UNINSTALL_SUCCESS[] = "uninstall success !";
|
||||
|
||||
enum {
|
||||
INSTALL_CALLBACK,
|
||||
UNINSTALL_CALLBACK
|
||||
};
|
||||
|
||||
std::string ObtainErrorMessage(uint8_t errorCode);
|
||||
} // namespace
|
||||
|
||||
struct ResultOfQueryAbilityInfo {
|
||||
uint8_t resultCode;
|
||||
AbilityInfo *abilityInfo;
|
||||
};
|
||||
|
||||
struct ResultOfGetBundleInfo {
|
||||
uint8_t resultCode;
|
||||
BundleInfo *bundleInfo;
|
||||
};
|
||||
|
||||
struct ResultOfGetBundleInfos {
|
||||
uint8_t resultCode;
|
||||
int32_t length;
|
||||
BundleInfo *bundleInfo;
|
||||
};
|
||||
|
||||
struct ResultOfGetBundleNameForUid {
|
||||
uint8_t resultCode;
|
||||
char *bundleName;
|
||||
int32_t length;
|
||||
};
|
||||
|
||||
struct ResultOfGetSysCap {
|
||||
uint8_t resultCode;
|
||||
SystemCapability systemCap;
|
||||
};
|
||||
|
||||
struct BundleCallbackInfo {
|
||||
BundleStateCallback bundleStateCallback;
|
||||
void *data;
|
||||
};
|
||||
#endif // OHOS_BUNDLE_CALLBACK_UTILS_H
|
||||
+49
@@ -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_BUNDLEINFO_UTILS_H
|
||||
#define OHOS_BUNDLEINFO_UTILS_H
|
||||
|
||||
#include "bundle_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct BundleInfoUtils {
|
||||
static void CopyBundleInfo(int32_t flags, BundleInfo *des, BundleInfo src);
|
||||
static bool SetBundleInfoBundleName(BundleInfo *bundleInfo, const char *bundleName);
|
||||
static bool SetBundleInfoVendor(BundleInfo *bundleInfo, const char *vendor);
|
||||
static bool SetBundleInfoLabel(BundleInfo *bundleInfo, const char *label);
|
||||
static bool SetBundleInfoVersionName(BundleInfo *bundleInfo, const char *versionName);
|
||||
static bool SetBundleInfoBigIconPath(BundleInfo *bundleInfo, const char *bigIconPath);
|
||||
static bool SetBundleInfoCodePath(BundleInfo *bundleInfo, const char *codePath);
|
||||
static bool SetBundleInfoDataPath(BundleInfo *bundleInfo, const char *dataPath);
|
||||
static bool SetBundleInfoModuleInfos(BundleInfo *bundleInfo, const ModuleInfo *moduleInfos, uint32_t numOfModule);
|
||||
static void ClearModuleInfos(ModuleInfo *moduleInfos, uint32_t numOfModule);
|
||||
static void FreeBundleInfos(BundleInfo *bundleInfos, uint32_t len);
|
||||
static void FreeBundleInfo(BundleInfo *bundleInfo);
|
||||
static bool SetBundleInfoAppId(BundleInfo *bundleInfo, const char *appId);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
static bool SetBundleInfoAbilityInfos(BundleInfo *bundleInfo, const AbilityInfo *abilityInfos,
|
||||
uint32_t numOfAbility);
|
||||
static void ClearAbilityInfos(AbilityInfo *abilityInfos, uint32_t numOfAbility);
|
||||
#else
|
||||
static bool SetBundleInfoSmallIconPath(BundleInfo *bundleInfo, const char *smallIconPath);
|
||||
static bool SetBundleInfoAbilityInfo(BundleInfo *bundleInfo, AbilityInfo abilityInfo);
|
||||
#endif
|
||||
private:
|
||||
BundleInfoUtils() = default;
|
||||
~BundleInfoUtils() = default;
|
||||
}; // BundleInfoUtils
|
||||
} // OHOS
|
||||
#endif // OHOS_BUNDLEINFO_UTILS_H
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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_BUNDLE_SELF_CALLBACK_H
|
||||
#define OHOS_BUNDLE_SELF_CALLBACK_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
class BundleSelfCallback {
|
||||
public:
|
||||
static BundleSelfCallback &GetInstance()
|
||||
{
|
||||
static BundleSelfCallback instance;
|
||||
return instance;
|
||||
}
|
||||
~BundleSelfCallback();
|
||||
const SvcIdentity *RegisterBundleSelfCallback(InstallerCallback &installerCallback);
|
||||
const InstallerCallback GetCallback();
|
||||
private:
|
||||
BundleSelfCallback() = default;
|
||||
static int32_t Callback(const IpcContext* context, void *ipcMsg, IpcIo *io, void *arg);
|
||||
int32_t GenerateLocalServiceId();
|
||||
InstallerCallback installerCallback_ { nullptr };
|
||||
SvcIdentity *svcIdentity_ { nullptr };
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(BundleSelfCallback);
|
||||
};
|
||||
} // namespace
|
||||
#endif // OHOS_BUNDLE_SELF_CALLBACK_H
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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_BUNDLEMS_SLITE_CLIENT_H
|
||||
#define OHOS_BUNDLEMS_SLITE_CLIENT_H
|
||||
|
||||
#include "iproxy_client.h"
|
||||
#include "nocopyable.h"
|
||||
#include "want.h"
|
||||
#include "bundle_service_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
class BundleMsClient {
|
||||
public:
|
||||
static BundleMsClient &GetInstance()
|
||||
{
|
||||
static BundleMsClient instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
~BundleMsClient() = default;
|
||||
|
||||
bool Initialize() const;
|
||||
|
||||
bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback) const;
|
||||
|
||||
bool Uninstall(const char *bundleName, const InstallParam *installParam, InstallerCallback installerCallback) const;
|
||||
|
||||
uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo) const;
|
||||
|
||||
uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo) const;
|
||||
|
||||
uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const;
|
||||
|
||||
int8_t GetInstallState(const char *bundleName) const;
|
||||
|
||||
private:
|
||||
BundleMsClient() = default;
|
||||
|
||||
BmsSliteInterface *bmsProxy_ { nullptr };
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(BundleMsClient);
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_BUNDLEMS_SLITE_CLIENT_H
|
||||
+54
@@ -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_CONVERT_UTILS_H
|
||||
#define OHOS_CONVERT_UTILS_H
|
||||
|
||||
#include "bundle_info.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct ConvertUtils {
|
||||
static char *ConvertAbilityInfoToString(const AbilityInfo *abilityInfo);
|
||||
static char *ConvertBundleInfoToString(const BundleInfo *bundleInfo);
|
||||
static char *ConvertBundleInfosToString(BundleInfo **bundleInfo, uint32_t numOfBundleInfo);
|
||||
static AbilityInfo *ConvertStringToAbilityInfo(const char *str, size_t buffSize);
|
||||
static BundleInfo *ConvertStringToBundleInfo(const char *str, size_t buffSize);
|
||||
static bool ConvertStringToBundleInfos(const char *strs, BundleInfo **bundleInfo, uint32_t numOfBundleInfo,
|
||||
size_t buffSize);
|
||||
static cJSON *GetJsonBundleInfo(const BundleInfo *bundleInfo);
|
||||
static cJSON *GetJsonBundleInfos(BundleInfo **bundleInfo, uint32_t numOfBundleInfo);
|
||||
static cJSON *GetJsonModuleInfos(const ModuleInfo *moduleInfos, uint32_t numOfModule);
|
||||
static cJSON *GetJsonModuleInfoMetaData(const ModuleInfo *moduleInfos, uint32_t index);
|
||||
static cJSON *GetJsonModuleInfoDeviceType(const ModuleInfo *moduleInfos, uint32_t index);
|
||||
static cJSON *GetJsonAbilityInfos(const AbilityInfo *abilityInfos, uint32_t numOfAbility);
|
||||
static cJSON *GetJsonAbilityInfo(const AbilityInfo *abilityInfo);
|
||||
static bool ConvertJsonToBundleInfo(const cJSON *root, BundleInfo *bundleInfo);
|
||||
static bool ConvertJsonToMetaData(const cJSON *metaDataArray, MetaData **metaData);
|
||||
static bool ConvertJsonToDeviceType(const cJSON *deviceTypeArray, char **deviceType);
|
||||
static bool ConvertJsonToModuleInfos(const cJSON *moduleArray, ModuleInfo **moduleInfos, uint32_t numOfModule);
|
||||
static bool ConvertJsonToAbilityInfo(const cJSON *root, AbilityInfo *abilityInfo);
|
||||
static bool ConvertJsonToAbilityInfos(const cJSON *abilityArray, AbilityInfo **abilityInfos, uint32_t numOfAbility);
|
||||
private:
|
||||
ConvertUtils() = default;
|
||||
~ConvertUtils() = default;
|
||||
static bool ConvertBundleInfoPartToJson(const BundleInfo *bundleInfo, cJSON *root);
|
||||
static bool ConvertModuleInfosToJson(const BundleInfo *bundleInfo, cJSON *root);
|
||||
static bool ConvertAbilityInfosToJson(const BundleInfo *bundleInfo, cJSON *root);
|
||||
static bool ConvertModuleInfoMetaDataToJson(const ModuleInfo *moduleInfos, uint32_t index, cJSON *item);
|
||||
static bool ConvertModuleInfoDeviceTypeToJson(const ModuleInfo *moduleInfos, uint32_t index, cJSON *item);
|
||||
}; // ConvertUtils
|
||||
} // OHOS
|
||||
#endif // OHOS_CONVERT_UTILS_H
|
||||
+41
@@ -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_ELEMENT_NAME_UTILS_H
|
||||
#define OHOS_ELEMENT_NAME_UTILS_H
|
||||
|
||||
#include <serializer.h>
|
||||
#include "element_name.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
|
||||
bool SerializeElement(IpcIo *io, const ElementName *element);
|
||||
bool DeserializeElement(ElementName *element, IpcIo *io);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // OHOS_ELEMENT_NAME_UTILS_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_MODULEINFO_UTILS_H
|
||||
#define OHOS_MODULEINFO_UTILS_H
|
||||
|
||||
#include "module_info.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct ModuleInfoUtils {
|
||||
static void CopyModuleInfo(ModuleInfo *des, ModuleInfo src);
|
||||
static void ClearModuleInfoMetaData(MetaData **metaData, uint32_t numOfMetaData);
|
||||
static void ClearModuleInfo(ModuleInfo *moduleInfo);
|
||||
static bool SetModuleInfoModuleName(ModuleInfo *moduleInfo, const char *moduleName);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
static bool SetModuleInfoName(ModuleInfo *moduleInfo, const char *name);
|
||||
static bool SetModuleInfoDescription(ModuleInfo *moduleInfo, const char *description);
|
||||
static bool SetModuleInfoModuleType(ModuleInfo *moduleInfo, const char *moduleType);
|
||||
static bool SetModuleInfoDeviceType(ModuleInfo *moduleInfo, char **deviceType, uint32_t numOfDeviceType);
|
||||
static void ClearModuleInfoDeviceType(char **deviceType, uint32_t numOfdeviceType);
|
||||
#endif
|
||||
static bool SetModuleInfoMetaData(ModuleInfo *moduleInfo, MetaData **metaData, uint32_t numOfMetaData);
|
||||
private:
|
||||
ModuleInfoUtils() = default;
|
||||
~ModuleInfoUtils() = default;
|
||||
}; // ModuleInfoUtils
|
||||
} // OHOS
|
||||
#endif // OHOS_MODULEINFO_UTILS_H
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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_info.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
void ClearAbilityInfo(AbilityInfo *abilityInfo)
|
||||
{
|
||||
if (abilityInfo == nullptr) {
|
||||
return;
|
||||
}
|
||||
AdapterFree(abilityInfo->bundleName);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
AdapterFree(abilityInfo->moduleName);
|
||||
AdapterFree(abilityInfo->name);
|
||||
AdapterFree(abilityInfo->description);
|
||||
AdapterFree(abilityInfo->iconPath);
|
||||
AdapterFree(abilityInfo->deviceId);
|
||||
AdapterFree(abilityInfo->label);
|
||||
#else
|
||||
AdapterFree(abilityInfo->srcPath);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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_info_utils.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
void AbilityInfoUtils::CopyAbilityInfo(AbilityInfo *des, AbilityInfo src)
|
||||
{
|
||||
if (des == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetAbilityInfoBundleName(des, src.bundleName);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
des->isVisible = src.isVisible;
|
||||
des->abilityType = src.abilityType;
|
||||
des->launchMode = src.launchMode;
|
||||
SetAbilityInfoModuleName(des, src.moduleName);
|
||||
SetAbilityInfoName(des, src.name);
|
||||
SetAbilityInfoDescription(des, src.description);
|
||||
SetAbilityInfoIconPath(des, src.iconPath);
|
||||
SetAbilityInfoDeviceId(des, src.deviceId);
|
||||
SetAbilityInfoLabel(des, src.label);
|
||||
#else
|
||||
SetAbilityInfoSrcPath(des, src.srcPath);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool AbilityInfoUtils::SetAbilityInfoBundleName(AbilityInfo *abilityInfo, const char *bundleName)
|
||||
{
|
||||
if (abilityInfo == nullptr || bundleName == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(abilityInfo->bundleName);
|
||||
abilityInfo->bundleName = Utils::Strdup(bundleName);
|
||||
return abilityInfo->bundleName != nullptr;
|
||||
}
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
bool AbilityInfoUtils::SetAbilityInfoModuleName(AbilityInfo *abilityInfo, const char *moduleName)
|
||||
{
|
||||
if (abilityInfo == nullptr || moduleName == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(abilityInfo->moduleName);
|
||||
abilityInfo->moduleName = Utils::Strdup(moduleName);
|
||||
return abilityInfo->moduleName != nullptr;
|
||||
}
|
||||
|
||||
bool AbilityInfoUtils::SetAbilityInfoName(AbilityInfo *abilityInfo, const char *name)
|
||||
{
|
||||
if (abilityInfo == nullptr || name == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(abilityInfo->name);
|
||||
abilityInfo->name = Utils::Strdup(name);
|
||||
return abilityInfo->name != nullptr;
|
||||
}
|
||||
|
||||
bool AbilityInfoUtils::SetAbilityInfoDescription(AbilityInfo *abilityInfo, const char *description)
|
||||
{
|
||||
if (abilityInfo == nullptr || description == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(abilityInfo->description);
|
||||
abilityInfo->description = Utils::Strdup(description);
|
||||
return abilityInfo->description != nullptr;
|
||||
}
|
||||
|
||||
bool AbilityInfoUtils::SetAbilityInfoIconPath(AbilityInfo *abilityInfo, const char *iconPath)
|
||||
{
|
||||
if (abilityInfo == nullptr || iconPath == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(abilityInfo->iconPath);
|
||||
abilityInfo->iconPath = Utils::Strdup(iconPath);
|
||||
return abilityInfo->iconPath != nullptr;
|
||||
}
|
||||
|
||||
bool AbilityInfoUtils::SetAbilityInfoDeviceId(AbilityInfo *abilityInfo, const char *deviceId)
|
||||
{
|
||||
if (abilityInfo == nullptr || deviceId == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(abilityInfo->deviceId);
|
||||
abilityInfo->deviceId = Utils::Strdup(deviceId);
|
||||
return abilityInfo->deviceId != nullptr;
|
||||
}
|
||||
|
||||
bool AbilityInfoUtils::SetAbilityInfoLabel(AbilityInfo *abilityInfo, const char *label)
|
||||
{
|
||||
if (abilityInfo == nullptr || label == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(abilityInfo->label);
|
||||
abilityInfo->label = Utils::Strdup(label);
|
||||
return abilityInfo->label != nullptr;
|
||||
}
|
||||
#else
|
||||
bool AbilityInfoUtils::SetAbilityInfoSrcPath(AbilityInfo *abilityInfo, const char *srcPath)
|
||||
{
|
||||
if (abilityInfo == nullptr || srcPath == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(abilityInfo->srcPath);
|
||||
abilityInfo->srcPath = Utils::Strdup(srcPath);
|
||||
return abilityInfo->srcPath != nullptr;
|
||||
}
|
||||
#endif
|
||||
} // OHOS
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* 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 "bundle_callback.h"
|
||||
|
||||
#include "adapter.h"
|
||||
#include "bundle_callback_utils.h"
|
||||
#include "bundle_inner_interface.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "iproxy_client.h"
|
||||
#include "log.h"
|
||||
#include "ohos_types.h"
|
||||
#include "samgr_lite.h"
|
||||
|
||||
namespace OHOS {
|
||||
BundleCallback::~BundleCallback()
|
||||
{
|
||||
if (svcIdentity_ != nullptr) {
|
||||
UnregisterIpcCallback(*svcIdentity_);
|
||||
TransmitServiceId(*svcIdentity_, false);
|
||||
AdapterFree(svcIdentity_);
|
||||
}
|
||||
callbackMap_.clear();
|
||||
}
|
||||
|
||||
static int Notify(IOwner owner, int code, IpcIo *reply)
|
||||
{
|
||||
if ((reply == nullptr) || (owner == nullptr)) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
if (IpcIoPopUint8(reply) != CHANGE_CALLBACK_SERVICE_IDENTITY) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
uint8_t *result = reinterpret_cast<uint8_t *>(owner);
|
||||
*result = IpcIoPopUint8(reply);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t InnerCallback(uint32_t installType, uint8_t resultCode, const char *bundleName)
|
||||
{
|
||||
if (bundleName == nullptr) {
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
BundleCallbackInfo callbackInfo = BundleCallback::GetInstance().GetCallbackInfoByName(bundleName);
|
||||
BundleStateCallback callback = callbackInfo.bundleStateCallback;
|
||||
if (callback == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "InnerCallback is nullptr");
|
||||
return ERR_APPEXECFWK_CALLBACK_NULL_CORRESPONDING_CALLBACK;
|
||||
}
|
||||
|
||||
if (resultCode != ERR_OK) {
|
||||
callback(installType, resultCode, ObtainErrorMessage(resultCode).c_str(), bundleName, callbackInfo.data);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
if (installType == INSTALL_CALLBACK) {
|
||||
callback(installType, resultCode, INSTALL_SUCCESS, bundleName, callbackInfo.data);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
if (installType == UNINSTALL_CALLBACK) {
|
||||
callback(installType, resultCode, UNINSTALL_SUCCESS, bundleName, callbackInfo.data);
|
||||
return ERR_OK;
|
||||
}
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "param installType is invalid!");
|
||||
return ERR_APPEXECFWK_CALLBACK_GET_ERROR_INSTALLTYPE;
|
||||
}
|
||||
|
||||
static int32_t Callback(const IpcContext* context, void *ipcMsg, IpcIo *io, void *arg)
|
||||
{
|
||||
// at here, arg is always been nullptr
|
||||
if (ipcMsg == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleCallback ipcMsg is nullptr");
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
|
||||
if (io == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleCallback io is nullptr");
|
||||
FreeBuffer(NULL, ipcMsg);
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
|
||||
uint32_t installType = 0;
|
||||
int32_t ret = GetCode(ipcMsg, &installType);
|
||||
if (ret != LITEIPC_OK) {
|
||||
FreeBuffer(NULL, ipcMsg);
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleCallback Get install type failed");
|
||||
return ERR_APPEXECFWK_CALLBACK_GET_INSTALLTYPE_FAILED;
|
||||
}
|
||||
if ((installType == INSTALL_CALLBACK) || (installType == UNINSTALL_CALLBACK)) {
|
||||
uint8_t resultCode = static_cast<uint8_t>(IpcIoPopInt32(io));
|
||||
size_t size = 0;
|
||||
char *bundleName = reinterpret_cast<char *>(IpcIoPopString(io, &size));
|
||||
ret = InnerCallback(installType, resultCode, bundleName);
|
||||
FreeBuffer(NULL, ipcMsg);
|
||||
return ret;
|
||||
}
|
||||
FreeBuffer(NULL, ipcMsg);
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleSelfCallback get error install type");
|
||||
return ERR_APPEXECFWK_CALLBACK_GET_ERROR_INSTALLTYPE;
|
||||
}
|
||||
|
||||
int32_t BundleCallback::TransmitServiceId(const SvcIdentity &svc, bool flag)
|
||||
{
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BMS_SERVICE, BMS_FEATURE);
|
||||
if (iUnknown == nullptr) {
|
||||
return ERR_APPEXECFWK_CALLBACK_SERVICEID_TRANSMITTED_FAILED;
|
||||
}
|
||||
IClientProxy *bmsClient = nullptr;
|
||||
int32_t result = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, reinterpret_cast<void **>(&bmsClient));
|
||||
if ((result != 0) || (bmsClient == nullptr)) {
|
||||
return ERR_APPEXECFWK_CALLBACK_SERVICEID_TRANSMITTED_FAILED;
|
||||
}
|
||||
IpcIo ipcIo;
|
||||
uint32_t data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 1);
|
||||
IpcIoPushBool(&ipcIo, flag);
|
||||
IpcIoPushSvc(&ipcIo, &svc);
|
||||
if (!IpcIoAvailable(&ipcIo)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleCallback TransmitServiceId ipc failed");
|
||||
return ERR_APPEXECFWK_IPCIO_UNAVAILABLED;
|
||||
}
|
||||
uint8_t errorCode = 0;
|
||||
int32_t ret = bmsClient->Invoke(bmsClient, CHANGE_CALLBACK_SERVICE_IDENTITY, &ipcIo, &errorCode, Notify);
|
||||
if (ret != OHOS_SUCCESS) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "TransmitServiceId calling Invoke function failed: %{public}d", ret);
|
||||
return ERR_APPEXECFWK_INVOKE_ERROR;
|
||||
}
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
int32_t BundleCallback::GenerateLocalServiceId()
|
||||
{
|
||||
if (svcIdentity_ != nullptr) {
|
||||
return ERR_OK;
|
||||
}
|
||||
svcIdentity_ = reinterpret_cast<SvcIdentity *>(AdapterMalloc(sizeof(SvcIdentity)));
|
||||
if (svcIdentity_ == nullptr) {
|
||||
return ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED;
|
||||
}
|
||||
int32_t ret = RegisterIpcCallback(Callback, 0, IPC_WAIT_FOREVER, svcIdentity_, NULL);
|
||||
if ((ret != LITEIPC_OK)) {
|
||||
AdapterFree(svcIdentity_);
|
||||
return ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED;
|
||||
}
|
||||
ret = TransmitServiceId(*svcIdentity_, true);
|
||||
if (ret != ERR_OK) {
|
||||
UnregisterIpcCallback(*svcIdentity_);
|
||||
AdapterFree(svcIdentity_);
|
||||
return ERR_APPEXECFWK_CALLBACK_SERVICEID_TRANSMITTED_FAILED;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
// register callback by bundle name
|
||||
int32_t BundleCallback::RegisterBundleStateCallback(const BundleStateCallback &callback,
|
||||
const char *bundleName, void *data)
|
||||
{
|
||||
int32_t ret = GenerateLocalServiceId();
|
||||
if (ret != ERR_OK) {
|
||||
return ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED;
|
||||
}
|
||||
|
||||
if ((bundleName == nullptr) || (strlen(bundleName) == 0)) {
|
||||
// monitor all applications by the callback function bundleStateCallback_
|
||||
bundleStateCallback_ = callback;
|
||||
innerData_ = data;
|
||||
callbackMap_.clear();
|
||||
return ERR_OK;
|
||||
}
|
||||
// already monitor all applications
|
||||
if (bundleStateCallback_ != nullptr) {
|
||||
return ERR_OK;
|
||||
}
|
||||
std::string innerBundleName = bundleName;
|
||||
auto it = callbackMap_.find(innerBundleName);
|
||||
if (it != callbackMap_.end()) {
|
||||
// already monitor the application
|
||||
it->second.bundleStateCallback = callback;
|
||||
it->second.data = data;
|
||||
return ERR_OK;
|
||||
}
|
||||
BundleCallbackInfo bundleCallbackInfo;
|
||||
bundleCallbackInfo.bundleStateCallback = callback;
|
||||
bundleCallbackInfo.data = data;
|
||||
callbackMap_.emplace(bundleName, bundleCallbackInfo);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
// unregister callback of all application
|
||||
int32_t BundleCallback::UnregisterBundleStateCallback()
|
||||
{
|
||||
if (svcIdentity_ == nullptr) {
|
||||
return ERR_APPEXECFWK_CALLBACK_UNREGISTER_FAILED;
|
||||
}
|
||||
|
||||
bundleStateCallback_ = nullptr;
|
||||
innerData_ = nullptr;
|
||||
callbackMap_.clear();
|
||||
(void) TransmitServiceId(*svcIdentity_, false);
|
||||
(void) UnregisterIpcCallback(*svcIdentity_);
|
||||
AdapterFree(svcIdentity_);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
BundleCallbackInfo BundleCallback::GetCallbackInfoByName(const char *bundleName)
|
||||
{
|
||||
BundleCallbackInfo innerCallbackInfo = { nullptr, nullptr };
|
||||
if ((bundleName == nullptr) || (strlen(bundleName) == 0)) {
|
||||
return innerCallbackInfo;
|
||||
}
|
||||
|
||||
if (bundleStateCallback_ != nullptr) {
|
||||
innerCallbackInfo.bundleStateCallback = bundleStateCallback_;
|
||||
innerCallbackInfo.data = innerData_;
|
||||
return innerCallbackInfo;
|
||||
}
|
||||
std::string innerBundleName = bundleName;
|
||||
auto it = callbackMap_.find(innerBundleName);
|
||||
if (it == callbackMap_.end()) {
|
||||
return innerCallbackInfo;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* 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 "bundle_callback_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
std::string ObtainErrorMessage(uint8_t errorCode)
|
||||
{
|
||||
switch (errorCode) {
|
||||
case ERR_APPEXECFWK_OBJECT_NULL:
|
||||
return "ERR_APPEXECFWK_OBJECT_NULL";
|
||||
// install errcode
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARAM_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARAM_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_FILE_PATH_INVALID:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_FILE_PATH_INVALID";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_FILE_NOT_EXISTS:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_FILE_NOT_EXISTS";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_INVALID_FILE_NAME:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_INVALID_FILE_NAME";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_BAD_FILE:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_BAD_FILE";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_CREATE_FILE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_CREATE_FILE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_CREATE_PERMISSIONS_DIR_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_CREATE_PERMISSIONS_DIR_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_RENAME_DIR_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_RENAME_DIR_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_RENAME_FILE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_RENAME_FILE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_CREATE_DATA_DIR_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_CREATE_DATA_DIR_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_RECORD_INFO_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_RECORD_INFO_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_UID_AND_GID_BACKUP_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_UID_AND_GID_BACKUP_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_VERSION_DOWNGRADE:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_VERSION_DOWNGRADE";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_STORE_PERMISSIONS_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_STORE_PERMISSIONS_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_INCOMPATIBLE_SIGNATURE:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_INCOMPATIBLE_SIGNATURE";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_INVALID_PROVISIONINFO:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_INVALID_PROVISIONINFO";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_OPERATE_SIGNED_FILE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_OPERATE_SIGNED_FILE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_APP_SIGNATURE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_APP_SIGNATURE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_SIGNATURE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_SIGNATURE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_SIGNATURE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_SIGNATURE_ERROR";
|
||||
// parse profile
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_BUNDLENAME_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_BUNDLENAME_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_INVALID_BUNDLENAME:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_INVALID_BUNDLENAME";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_VENDOR_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_VENDOR_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_VERSIONCODE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_VERSIONCODE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_VERSIONNAME_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_VERSIONNAME_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PERMISSIONS_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PERMISSIONS_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DEVICE_CONFIG_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DEVICE_CONFIG_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_KEEPALIVE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_KEEPALIVE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_MODULENAME_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_MODULENAME_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_INVALID_MODULENAME:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_INVALID_MODULENAME";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_MODULE_DESCRIPTION_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_MODULE_DESCRIPTION_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DEVICETYPE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DEVICETYPE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_MODULENAME_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_MODULENAME_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_MODULETYPE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_MODULETYPE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_DELIVERY_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_DELIVERY_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_METADATA_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_METADATA_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITIES_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITIES_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_NAME_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_NAME_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_TYPE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_TYPE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_ICONPATH_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_ICONPATH_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_LABEL_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_LABEL_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_DESCRIPTION_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_DESCRIPTION_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_LAUNCHTYPE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_LAUNCHTYPE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_VISIBLE_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_VISIBLE_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_INVALID_BUNDLENAME_LENGTH:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_INVALID_BUNDLENAME_LENGTH";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_LABEL_LENGTH_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_LABEL_LENGTH_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_VERSIONNAME_LENGTH_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_VERSIONNAME_LENGTH_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_METADATA_NAME_LENGTH_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_METADATA_NAME_LENGTH_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_METADATA_VALUE_LENGTH_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_METADATA_VALUE_LENGTH_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_VENDOR_LENGTH_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_VENDOR_LENGTH_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_MODULENAME_LENGTH_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_MODULENAME_LENGTH_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_ABILITYNAME_LENGTH_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_ABILITYNAME_LENGTH_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_ABILITY_DESCRIPTION_LENGTH_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_ABILITY_DESCRIPTION_LENGTH_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_ABILITY_LABEL_LENGTH_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_ABILITY_LABEL_LENGTH_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_EXTRACTOR_NOT_INIT:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_EXTRACTOR_NOT_INIT";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_EXTRACT_HAP_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_EXTRACT_HAP_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_RESOURCE_INDEX_NOT_EXISTS:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_RESOURCE_INDEX_NOT_EXISTS";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_LABEL_RES_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_LABEL_RES_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ICON_RES_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ICON_RES_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DESCRIPTION_RES_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DESCRIPTION_RES_ERROR";
|
||||
case ERR_APPEXECFWK_INSTALL_FAILED_PARSE_API_VERSION_ERROR:
|
||||
return "ERR_APPEXECFWK_INSTALL_FAILED_PARSE_API_VERSION_ERROR";
|
||||
// unistall result data
|
||||
case ERR_APPEXECFWK_UNINSTALL_FAILED_INTERNAL_ERROR:
|
||||
return "ERR_APPEXECFWK_UNINSTALL_FAILED_INTERNAL_ERROR";
|
||||
case ERR_APPEXECFWK_UNINSTALL_FAILED_BUNDLE_NOT_EXISTS:
|
||||
return "ERR_APPEXECFWK_UNINSTALL_FAILED_BUNDLE_NOT_EXISTS";
|
||||
case ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_DIRS_ERROR:
|
||||
return "ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_DIRS_ERROR";
|
||||
case ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_RECORD_INFO_ERROR:
|
||||
return "ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_RECORD_INFO_ERROR";
|
||||
case ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_PERMISSIONS_ERROR:
|
||||
return "ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_PERMISSIONS_ERROR";
|
||||
case ERR_APPEXECFWK_UNINSTALL_FAILED_BUNDLE_NOT_UNINSTALLABLE:
|
||||
return "ERR_APPEXECFWK_UNINSTALL_FAILED_BUNDLE_NOT_UNINSTALLABLE";
|
||||
case ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_UID_INFO_ERROR:
|
||||
return "ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_UID_INFO_ERROR";
|
||||
case ERR_APPEXECFWK_UNINSTALL_FAILED_SEND_REQUEST_ERROR:
|
||||
return "ERR_APPEXECFWK_UNINSTALL_FAILED_SEND_REQUEST_ERROR";
|
||||
// register and serialization errorcode
|
||||
case ERR_APPEXECFWK_CALLBACK_REGISTER_FAILED:
|
||||
return "ERR_APPEXECFWK_CALLBACK_REGISTER_FAILED";
|
||||
case ERR_APPEXECFWK_CALLBACK_UNREGISTER_FAILED:
|
||||
return "ERR_APPEXECFWK_CALLBACK_UNREGISTER_FAILED";
|
||||
case ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED:
|
||||
return "ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED";
|
||||
case ERR_APPEXECFWK_CALLBACK_SERVICEID_TRANSMITTED_FAILED:
|
||||
return "ERR_APPEXECFWK_CALLBACK_SERVICEID_TRANSMITTED_FAILED";
|
||||
case ERR_APPEXECFWK_CALLBACK_NEVER_REGISTERED:
|
||||
return "ERR_APPEXECFWK_CALLBACK_NEVER_REGISTERED";
|
||||
case ERR_APPEXECFWK_CALLBACK_OBTAIN_ALL_BUNDLE_FAILED:
|
||||
return "ERR_APPEXECFWK_CALLBACK_OBTAIN_ALL_BUNDLE_FAILED";
|
||||
case ERR_APPEXECFWK_CALLBACK_NULL_CORRESPONDING_CALLBACK:
|
||||
return "ERR_APPEXECFWK_CALLBACK_NULL_CORRESPONDING_CALLBACK";
|
||||
case ERR_APPEXECFWK_CALLBACK_GET_INSTALLTYPE_FAILED:
|
||||
return "ERR_APPEXECFWK_CALLBACK_GET_INSTALLTYPE_FAILED";
|
||||
case ERR_APPEXECFWK_CALLBACK_GET_ERROR_INSTALLTYPE:
|
||||
return "ERR_APPEXECFWK_CALLBACK_GET_ERROR_INSTALLTYPE";
|
||||
case ERR_APPEXECFWK_SERIALIZATION_FAILED:
|
||||
return "ERR_APPEXECFWK_SERIALIZATION_FAILED";
|
||||
case ERR_APPEXECFWK_DESERIALIZATION_FAILED:
|
||||
return "ERR_APPEXECFWK_DESERIALIZATION_FAILED";
|
||||
case ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR:
|
||||
return "ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR";
|
||||
default: {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
Executable
+45
@@ -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 "bundle_info.h"
|
||||
|
||||
#include "bundle_info_utils.h"
|
||||
#include "securec.h"
|
||||
#include "utils.h"
|
||||
|
||||
void ClearBundleInfo(BundleInfo *bundleInfo)
|
||||
{
|
||||
if (bundleInfo == nullptr) {
|
||||
return;
|
||||
}
|
||||
AdapterFree(bundleInfo->bundleName);
|
||||
AdapterFree(bundleInfo->versionName);
|
||||
AdapterFree(bundleInfo->label);
|
||||
AdapterFree(bundleInfo->bigIconPath);
|
||||
AdapterFree(bundleInfo->codePath);
|
||||
AdapterFree(bundleInfo->dataPath);
|
||||
AdapterFree(bundleInfo->vendor);
|
||||
OHOS::BundleInfoUtils::ClearModuleInfos(bundleInfo->moduleInfos, bundleInfo->numOfModule);
|
||||
AdapterFree(bundleInfo->moduleInfos);
|
||||
AdapterFree(bundleInfo->appId);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
OHOS::BundleInfoUtils::ClearAbilityInfos(bundleInfo->abilityInfos, bundleInfo->numOfAbility);
|
||||
AdapterFree(bundleInfo->abilityInfos);
|
||||
#else
|
||||
AdapterFree(bundleInfo->smallIconPath);
|
||||
ClearAbilityInfo(bundleInfo->abilityInfo);
|
||||
AdapterFree(bundleInfo->abilityInfo);
|
||||
#endif
|
||||
}
|
||||
+287
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* 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 "bundle_info_utils.h"
|
||||
|
||||
#include "ability_info_utils.h"
|
||||
#include "module_info_utils.h"
|
||||
#include "securec.h"
|
||||
|
||||
namespace OHOS {
|
||||
const uint8_t GET_BUNDLE_WITH_ABILITIES = 1;
|
||||
|
||||
void BundleInfoUtils::FreeBundleInfos(BundleInfo *bundleInfos, uint32_t len)
|
||||
{
|
||||
if (bundleInfos == nullptr) {
|
||||
return;
|
||||
}
|
||||
for (uint32_t i = 0; i < len; ++i) {
|
||||
ClearBundleInfo(bundleInfos + i);
|
||||
}
|
||||
AdapterFree(bundleInfos);
|
||||
}
|
||||
|
||||
void BundleInfoUtils::FreeBundleInfo(BundleInfo *bundleInfo)
|
||||
{
|
||||
if (bundleInfo == nullptr) {
|
||||
return;
|
||||
}
|
||||
ClearBundleInfo(bundleInfo);
|
||||
AdapterFree(bundleInfo);
|
||||
}
|
||||
|
||||
void BundleInfoUtils::CopyBundleInfo(int32_t flags, BundleInfo *des, BundleInfo src)
|
||||
{
|
||||
if (des == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetBundleInfoBundleName(des, src.bundleName);
|
||||
SetBundleInfoLabel(des, src.label);
|
||||
SetBundleInfoVersionName(des, src.versionName);
|
||||
SetBundleInfoBigIconPath(des, src.bigIconPath);
|
||||
SetBundleInfoCodePath(des, src.codePath);
|
||||
SetBundleInfoDataPath(des, src.dataPath);
|
||||
SetBundleInfoVendor(des, src.vendor);
|
||||
SetBundleInfoModuleInfos(des, src.moduleInfos, src.numOfModule);
|
||||
des->isSystemApp = src.isSystemApp;
|
||||
des->versionCode = src.versionCode;
|
||||
des->compatibleApi = src.compatibleApi;
|
||||
des->targetApi = src.targetApi;
|
||||
SetBundleInfoAppId(des, src.appId);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
des->isKeepAlive = src.isKeepAlive;
|
||||
des->isNativeApp = src.isNativeApp;
|
||||
des->uid = src.uid;
|
||||
des->gid = src.gid;
|
||||
if (flags == GET_BUNDLE_WITH_ABILITIES) {
|
||||
SetBundleInfoAbilityInfos(des, src.abilityInfos, src.numOfAbility);
|
||||
} else {
|
||||
des->abilityInfos = nullptr;
|
||||
des->numOfAbility = 0;
|
||||
}
|
||||
#else
|
||||
SetBundleInfoSmallIconPath(des, src.smallIconPath);
|
||||
if (flags == GET_BUNDLE_WITH_ABILITIES) {
|
||||
if (src.abilityInfo != nullptr) {
|
||||
SetBundleInfoAbilityInfo(des, *(src.abilityInfo));
|
||||
}
|
||||
} else {
|
||||
des->abilityInfo = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool BundleInfoUtils::SetBundleInfoBundleName(BundleInfo *bundleInfo, const char *bundleName)
|
||||
{
|
||||
if (bundleInfo == nullptr || bundleName == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(bundleInfo->bundleName);
|
||||
bundleInfo->bundleName = Utils::Strdup(bundleName);
|
||||
return bundleInfo->bundleName != nullptr;
|
||||
}
|
||||
|
||||
bool BundleInfoUtils::SetBundleInfoVendor(BundleInfo *bundleInfo, const char *vendor)
|
||||
{
|
||||
if (bundleInfo == nullptr || vendor == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(bundleInfo->vendor);
|
||||
bundleInfo->vendor = Utils::Strdup(vendor);
|
||||
return bundleInfo->vendor != nullptr;
|
||||
}
|
||||
|
||||
bool BundleInfoUtils::SetBundleInfoLabel(BundleInfo *bundleInfo, const char *label)
|
||||
{
|
||||
if (bundleInfo == nullptr || label == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(bundleInfo->label);
|
||||
bundleInfo->label = Utils::Strdup(label);
|
||||
return bundleInfo->label != nullptr;
|
||||
}
|
||||
|
||||
bool BundleInfoUtils::SetBundleInfoVersionName(BundleInfo *bundleInfo, const char *versionName)
|
||||
{
|
||||
if (bundleInfo == nullptr || versionName == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(bundleInfo->versionName);
|
||||
bundleInfo->versionName = Utils::Strdup(versionName);
|
||||
return bundleInfo->versionName != nullptr;
|
||||
}
|
||||
|
||||
bool BundleInfoUtils::SetBundleInfoBigIconPath(BundleInfo *bundleInfo, const char *bigIconPath)
|
||||
{
|
||||
if (bundleInfo == nullptr || bigIconPath == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(bundleInfo->bigIconPath);
|
||||
bundleInfo->bigIconPath = Utils::Strdup(bigIconPath);
|
||||
return bundleInfo->bigIconPath != nullptr;
|
||||
}
|
||||
|
||||
bool BundleInfoUtils::SetBundleInfoCodePath(BundleInfo *bundleInfo, const char *codePath)
|
||||
{
|
||||
if (bundleInfo == nullptr || codePath == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(bundleInfo->codePath);
|
||||
bundleInfo->codePath = Utils::Strdup(codePath);
|
||||
return bundleInfo->codePath != nullptr;
|
||||
}
|
||||
|
||||
bool BundleInfoUtils::SetBundleInfoDataPath(BundleInfo *bundleInfo, const char *dataPath)
|
||||
{
|
||||
if (bundleInfo == nullptr || dataPath == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(bundleInfo->dataPath);
|
||||
bundleInfo->dataPath = Utils::Strdup(dataPath);
|
||||
return bundleInfo->dataPath != nullptr;
|
||||
}
|
||||
|
||||
bool BundleInfoUtils::SetBundleInfoModuleInfos(BundleInfo *bundleInfo, const ModuleInfo *moduleInfos,
|
||||
uint32_t numOfModule)
|
||||
{
|
||||
if (numOfModule == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (moduleInfos == nullptr || bundleInfo == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bundleInfo->numOfModule = numOfModule;
|
||||
bundleInfo->moduleInfos = reinterpret_cast<ModuleInfo *>(AdapterMalloc(sizeof(ModuleInfo) * numOfModule));
|
||||
if (bundleInfo->moduleInfos == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t ret = memset_s(bundleInfo->moduleInfos, sizeof(ModuleInfo) * numOfModule, 0,
|
||||
sizeof(ModuleInfo) * numOfModule);
|
||||
if (ret != EOK) {
|
||||
AdapterFree(bundleInfo->moduleInfos);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < numOfModule; i++) {
|
||||
ModuleInfoUtils::CopyModuleInfo(bundleInfo->moduleInfos + i, moduleInfos[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void BundleInfoUtils::ClearModuleInfos(ModuleInfo *moduleInfos, uint32_t numOfModule)
|
||||
{
|
||||
if (moduleInfos == nullptr || numOfModule == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < numOfModule; i++) {
|
||||
ClearModuleInfo(moduleInfos + i);
|
||||
}
|
||||
}
|
||||
|
||||
bool BundleInfoUtils::SetBundleInfoAppId(BundleInfo *bundleInfo, const char *appId)
|
||||
{
|
||||
if (bundleInfo == nullptr || appId == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(bundleInfo->appId);
|
||||
bundleInfo->appId = Utils::Strdup(appId);
|
||||
return bundleInfo->appId != nullptr;
|
||||
}
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
bool BundleInfoUtils::SetBundleInfoAbilityInfos(BundleInfo *bundleInfo, const AbilityInfo *abilityInfos,
|
||||
uint32_t numOfAbility)
|
||||
{
|
||||
if (numOfAbility == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (abilityInfos == nullptr || bundleInfo == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bundleInfo->numOfAbility = numOfAbility;
|
||||
bundleInfo->abilityInfos = reinterpret_cast<AbilityInfo *>(AdapterMalloc(sizeof(AbilityInfo) * numOfAbility));
|
||||
if (bundleInfo->abilityInfos == nullptr) {
|
||||
return false;
|
||||
}
|
||||
int32_t ret = memset_s(bundleInfo->abilityInfos, sizeof(AbilityInfo) * numOfAbility, 0,
|
||||
sizeof(AbilityInfo) * numOfAbility);
|
||||
if (ret != EOK) {
|
||||
AdapterFree(bundleInfo->abilityInfos);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < numOfAbility; i++) {
|
||||
AbilityInfoUtils::CopyAbilityInfo(bundleInfo->abilityInfos + i, abilityInfos[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void BundleInfoUtils::ClearAbilityInfos(AbilityInfo *abilityInfos, uint32_t numOfAbility)
|
||||
{
|
||||
if (abilityInfos == nullptr || numOfAbility == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < numOfAbility; i++) {
|
||||
ClearAbilityInfo(abilityInfos + i);
|
||||
}
|
||||
}
|
||||
#else
|
||||
bool BundleInfoUtils::SetBundleInfoSmallIconPath(BundleInfo *bundleInfo, const char *smallIconPath)
|
||||
{
|
||||
if (bundleInfo == nullptr || smallIconPath == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(bundleInfo->smallIconPath);
|
||||
bundleInfo->smallIconPath = Utils::Strdup(smallIconPath);
|
||||
return bundleInfo->smallIconPath != nullptr;
|
||||
}
|
||||
|
||||
bool BundleInfoUtils::SetBundleInfoAbilityInfo(BundleInfo *bundleInfo, AbilityInfo abilityInfo)
|
||||
{
|
||||
if (bundleInfo == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ClearAbilityInfo(bundleInfo->abilityInfo);
|
||||
AdapterFree(bundleInfo->abilityInfo);
|
||||
bundleInfo->abilityInfo = reinterpret_cast<AbilityInfo *>(AdapterMalloc(sizeof(AbilityInfo)));
|
||||
if (bundleInfo->abilityInfo == nullptr ||
|
||||
memset_s(bundleInfo->abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo)) != EOK) {
|
||||
AdapterFree(bundleInfo->abilityInfo);
|
||||
return false;
|
||||
}
|
||||
|
||||
AbilityInfoUtils::CopyAbilityInfo(bundleInfo->abilityInfo, abilityInfo);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
} // OHOS
|
||||
+786
@@ -0,0 +1,786 @@
|
||||
/*
|
||||
* 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 "bundle_manager.h"
|
||||
|
||||
#include "ability_info_utils.h"
|
||||
#include "adapter.h"
|
||||
#include "bundle_callback.h"
|
||||
#include "bundle_callback_utils.h"
|
||||
#include "bundle_info_utils.h"
|
||||
#include "bundle_inner_interface.h"
|
||||
#include "bundle_self_callback.h"
|
||||
#include "convert_utils.h"
|
||||
#include "iproxy_client.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "log.h"
|
||||
#include "ohos_types.h"
|
||||
#include "pms_interface.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "securec.h"
|
||||
#include "want_utils.h"
|
||||
|
||||
extern "C" {
|
||||
constexpr static char PERMISSION_INSTALL_BUNDLE[] = "ohos.permission.INSTALL_BUNDLE";
|
||||
constexpr static char PERMISSION_GET_BUNDLE_INFO[] = "ohos.permission.GET_BUNDLE_INFO";
|
||||
constexpr static char PERMISSION_LISTEN_BUNDLE_CHANGE[] = "ohos.permission.LISTEN_BUNDLE_CHANGE";
|
||||
constexpr static uint8_t MAX_BUNDLE_NAME = 128;
|
||||
constexpr static uint8_t OBJECT_NUMBER_IN_WANT = 2;
|
||||
#ifdef __LINUX__
|
||||
constexpr static uint8_t OBJECT_NUMBER_IN_INSTALLATION = 1;
|
||||
#else
|
||||
constexpr static uint8_t OBJECT_NUMBER_IN_INSTALLATION = 2;
|
||||
#endif
|
||||
|
||||
int32 RegisterCallback(BundleStatusCallback *bundleStatusCallback)
|
||||
{
|
||||
if ((bundleStatusCallback == nullptr) || (bundleStatusCallback->callBack == nullptr)) {
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
if (CheckSelfPermission(static_cast<const char *>(PERMISSION_LISTEN_BUNDLE_CHANGE)) != GRANTED) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager register callback failed due to permission denied");
|
||||
return ERR_APPEXECFWK_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
return OHOS::BundleCallback::GetInstance().RegisterBundleStateCallback(bundleStatusCallback->callBack,
|
||||
bundleStatusCallback->bundleName, bundleStatusCallback->data);
|
||||
}
|
||||
|
||||
int32 UnregisterCallback()
|
||||
{
|
||||
return OHOS::BundleCallback::GetInstance().UnregisterBundleStateCallback();
|
||||
}
|
||||
|
||||
static uint8_t DeserializeInnerAbilityInfo(IOwner owner, IpcIo *reply)
|
||||
{
|
||||
if ((reply == nullptr) || (owner == nullptr)) {
|
||||
return OHOS_FAILURE;
|
||||
}
|
||||
uint8_t resultCode = IpcIoPopUint8(reply);
|
||||
ResultOfQueryAbilityInfo *info = reinterpret_cast<ResultOfQueryAbilityInfo *>(owner);
|
||||
if (resultCode != ERR_OK) {
|
||||
info->resultCode = resultCode;
|
||||
return resultCode;
|
||||
}
|
||||
#ifdef __LINUX__
|
||||
size_t len = 0;
|
||||
char *jsonStr = reinterpret_cast<char *>(IpcIoPopString(reply, &len));
|
||||
if (jsonStr == nullptr) {
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "AbilityInfo DeserializeAbilityInfo buff is empty!");
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
info->abilityInfo = OHOS::ConvertUtils::ConvertStringToAbilityInfo(jsonStr, len);
|
||||
#else
|
||||
BuffPtr *buff = IpcIoPopDataBuff(reply);
|
||||
if (buff == nullptr) {
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "AbilityInfo DeserializeAbilityInfo buff is empty!");
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
char* jsonStr = reinterpret_cast<char *>(buff->buff);
|
||||
info->abilityInfo = OHOS::ConvertUtils::ConvertStringToAbilityInfo(jsonStr, buff->buffSz);
|
||||
FreeBuffer(NULL, buff->buff);
|
||||
#endif
|
||||
if (info->abilityInfo == nullptr) {
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
info->resultCode = resultCode;
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
static uint8_t DeserializeInnerBundleInfo(IOwner owner, IpcIo *reply)
|
||||
{
|
||||
if ((reply == nullptr) || (owner == nullptr)) {
|
||||
return OHOS_FAILURE;
|
||||
}
|
||||
uint8_t resultCode = IpcIoPopUint8(reply);
|
||||
ResultOfGetBundleInfo *info = reinterpret_cast<ResultOfGetBundleInfo *>(owner);
|
||||
if (resultCode != ERR_OK) {
|
||||
info->resultCode = resultCode;
|
||||
return resultCode;
|
||||
}
|
||||
#ifdef __LINUX__
|
||||
size_t len = 0;
|
||||
char *jsonStr = reinterpret_cast<char *>(IpcIoPopString(reply, &len));
|
||||
if (jsonStr == nullptr) {
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleInfo DeserializeBundleInfo buff is empty!");
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
info->bundleInfo = OHOS::ConvertUtils::ConvertStringToBundleInfo(jsonStr, len);
|
||||
#else
|
||||
BuffPtr *buff = IpcIoPopDataBuff(reply);
|
||||
if (buff == nullptr) {
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleInfo DeserializeBundleInfo buff is empty!");
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
char* jsonStr = reinterpret_cast<char *>(buff->buff);
|
||||
info->bundleInfo = OHOS::ConvertUtils::ConvertStringToBundleInfo(jsonStr, buff->buffSz);
|
||||
FreeBuffer(NULL, buff->buff);
|
||||
#endif
|
||||
if (info->bundleInfo == nullptr) {
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
info->resultCode = resultCode;
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
static uint8_t DeserializeInnerBundleInfos(IOwner owner, IpcIo *reply)
|
||||
{
|
||||
if ((reply == nullptr) || (owner == nullptr)) {
|
||||
return OHOS_FAILURE;
|
||||
}
|
||||
uint8_t resultCode = IpcIoPopUint8(reply);
|
||||
ResultOfGetBundleInfos *info = reinterpret_cast<ResultOfGetBundleInfos *>(owner);
|
||||
if (resultCode != ERR_OK) {
|
||||
info->resultCode = resultCode;
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
info->length = IpcIoPopInt32(reply);
|
||||
#ifdef __LINUX__
|
||||
size_t len = 0;
|
||||
char *jsonStr = reinterpret_cast<char*>(IpcIoPopString(reply, &len));
|
||||
if (jsonStr == nullptr) {
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleInfo DeserializeBundleInfos buff is empty!");
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
if (!OHOS::ConvertUtils::ConvertStringToBundleInfos(jsonStr, &(info->bundleInfo), info->length, len)) {
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
#else
|
||||
BuffPtr *buff = IpcIoPopDataBuff(reply);
|
||||
if (buff == nullptr) {
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleInfo DeserializeBundleInfos buff is empty!");
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
char *jsonStr = reinterpret_cast<char *>(buff->buff);
|
||||
if (!OHOS::ConvertUtils::ConvertStringToBundleInfos(jsonStr, &(info->bundleInfo), info->length,
|
||||
buff->buffSz)) {
|
||||
FreeBuffer(NULL, buff->buff);
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
FreeBuffer(NULL, buff->buff);
|
||||
#endif
|
||||
info->resultCode = resultCode;
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
static uint8_t DeserializeInnerBundleName(IOwner owner, IpcIo *reply)
|
||||
{
|
||||
if ((reply == nullptr) || (owner == nullptr)) {
|
||||
return OHOS_FAILURE;
|
||||
}
|
||||
uint8_t resultCode = IpcIoPopUint8(reply);
|
||||
ResultOfGetBundleNameForUid *info = reinterpret_cast<ResultOfGetBundleNameForUid *>(owner);
|
||||
if (resultCode != ERR_OK) {
|
||||
info->resultCode = resultCode;
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
size_t length = 0;
|
||||
char *bundleName = reinterpret_cast<char *>(IpcIoPopString(reply, &length));
|
||||
if (bundleName == nullptr) {
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
if (length < 0 || length > MAX_BUNDLE_NAME) {
|
||||
info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
return ERR_APPEXECFWK_DESERIALIZATION_FAILED;
|
||||
}
|
||||
info->bundleName = reinterpret_cast<char *>(AdapterMalloc(length + 1));
|
||||
if (info->bundleName == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager DeserializeInnerBundleName failed");
|
||||
info->resultCode = ERR_APPEXECFWK_OBJECT_NULL;
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
errno_t err = strncpy_s(info->bundleName, length + 1, bundleName, length);
|
||||
if (err != EOK) {
|
||||
AdapterFree(info->bundleName);
|
||||
info->resultCode = ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR;
|
||||
return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR;
|
||||
}
|
||||
info->length = length;
|
||||
info->resultCode = resultCode;
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
static uint8_t DeserializeSystemCapabilities(IOwner owner, IpcIo *reply)
|
||||
{
|
||||
if ((reply == nullptr) || (owner == nullptr)) {
|
||||
return OHOS_FAILURE;
|
||||
}
|
||||
uint8_t resultCode = IpcIoPopUint8(reply);
|
||||
ResultOfGetSysCap *info = reinterpret_cast<ResultOfGetSysCap *>(owner);
|
||||
if (resultCode != ERR_OK) {
|
||||
info->resultCode = resultCode;
|
||||
return resultCode;
|
||||
}
|
||||
int32_t sysCapCount = IpcIoPopInt32(reply);
|
||||
info->systemCap.systemCapName = reinterpret_cast<SystemCapName *>(AdapterMalloc(sizeof(SystemCapName) *
|
||||
sysCapCount));
|
||||
if (info->systemCap.systemCapName == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager DeserializeSystemCapabilities failed");
|
||||
info->resultCode = ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR;
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
if (memset_s(info->systemCap.systemCapName, sizeof(SystemCapName) * sysCapCount,
|
||||
0, sizeof(SystemCapName) * sysCapCount)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager DeserializeSystemCapabilities failed");
|
||||
AdapterFree(info->systemCap.systemCapName);
|
||||
info->resultCode = ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR;
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
for (int32_t index = 0; index < sysCapCount; index++) {
|
||||
size_t sysCapNameLen;
|
||||
char *sysCapName = reinterpret_cast<char *>(IpcIoPopString(reply, &sysCapNameLen));
|
||||
errno_t err = strncpy_s(info->systemCap.systemCapName[index].name, MAX_SYSCAP_NAME_LEN,
|
||||
sysCapName, sysCapNameLen);
|
||||
if (err != EOK) {
|
||||
AdapterFree(info->systemCap.systemCapName);
|
||||
info->resultCode = ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR;
|
||||
return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
info->systemCap.systemCapNum = sysCapCount;
|
||||
info->resultCode = resultCode;
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
static int Notify(IOwner owner, int code, IpcIo *reply)
|
||||
{
|
||||
if ((reply == nullptr) || (owner == nullptr)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Notify ipc is nullptr");
|
||||
return OHOS_FAILURE;
|
||||
}
|
||||
switch (IpcIoPopUint8(reply)) {
|
||||
case INSTALL:
|
||||
case UNINSTALL: {
|
||||
uint8_t *ret = reinterpret_cast<uint8_t *>(owner);
|
||||
*ret = IpcIoPopUint8(reply);
|
||||
HILOG_INFO(HILOG_MODULE_APP, "BundleManager install or uninstall invoke return: %{public}d", *ret);
|
||||
break;
|
||||
}
|
||||
case QUERY_ABILITY_INFO: {
|
||||
return DeserializeInnerAbilityInfo(owner, reply);
|
||||
}
|
||||
case GET_BUNDLE_INFO: {
|
||||
return DeserializeInnerBundleInfo(owner, reply);
|
||||
}
|
||||
case GET_BUNDLE_INFOS:
|
||||
case QUERY_KEEPALIVE_BUNDLE_INFOS:
|
||||
case GET_BUNDLE_INFOS_BY_METADATA: {
|
||||
return DeserializeInnerBundleInfos(owner, reply);
|
||||
}
|
||||
case GET_BUNDLENAME_FOR_UID: {
|
||||
return DeserializeInnerBundleName(owner, reply);
|
||||
}
|
||||
case CHECK_SYS_CAP: {
|
||||
uint8_t *ret = reinterpret_cast<uint8_t *>(owner);
|
||||
*ret = IpcIoPopUint8(reply);
|
||||
HILOG_INFO(HILOG_MODULE_APP, "BundleManager HasSystemCapability invoke return: %{public}d", *ret);
|
||||
break;
|
||||
}
|
||||
case GET_SYS_CAP: {
|
||||
return DeserializeSystemCapabilities(owner, reply);
|
||||
}
|
||||
#ifdef OHOS_DEBUG
|
||||
case SET_EXTERNAL_INSTALL_MODE:
|
||||
case SET_SIGN_DEBUG_MODE:
|
||||
case SET_SIGN_MODE: {
|
||||
uint8_t *ret = reinterpret_cast<uint8_t *>(owner);
|
||||
*ret = IpcIoPopUint8(reply);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static IClientProxy *GetBmsClient()
|
||||
{
|
||||
IClientProxy *bmsClient = nullptr;
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BMS_SERVICE, BMS_FEATURE);
|
||||
if (iUnknown == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
int result = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, reinterpret_cast<void **>(&bmsClient));
|
||||
if (result != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return bmsClient;
|
||||
}
|
||||
|
||||
static IClientProxy *GetBmsInnerClient()
|
||||
{
|
||||
IClientProxy *bmsClient = nullptr;
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BMS_SERVICE, BMS_INNER_FEATURE);
|
||||
if (iUnknown == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
int result = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, reinterpret_cast<void **>(&bmsClient));
|
||||
if (result != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return bmsClient;
|
||||
}
|
||||
|
||||
bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback)
|
||||
{
|
||||
if ((hapPath == nullptr) || (installerCallback == nullptr) || (installParam == nullptr)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager install failed due to nullptr parameters");
|
||||
return false;
|
||||
}
|
||||
if (CheckSelfPermission(static_cast<const char *>(PERMISSION_INSTALL_BUNDLE)) != GRANTED) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager install failed due to permission denied");
|
||||
return false;
|
||||
}
|
||||
auto bmsInnerClient = GetBmsInnerClient();
|
||||
if (bmsInnerClient == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager install failed due to nullptr bms client");
|
||||
return false;
|
||||
}
|
||||
|
||||
IpcIo ipcIo;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, OBJECT_NUMBER_IN_INSTALLATION);
|
||||
#ifdef __LINUX__
|
||||
IpcIoPushString(&ipcIo, hapPath);
|
||||
#else
|
||||
BuffPtr dataBuff = {
|
||||
.buffSz = strlen(hapPath) + 1, // include \0
|
||||
.buff = const_cast<char *>(hapPath)
|
||||
};
|
||||
IpcIoPushDataBuff(&ipcIo, &dataBuff);
|
||||
#endif
|
||||
const SvcIdentity *svc = OHOS::BundleSelfCallback::GetInstance().RegisterBundleSelfCallback(installerCallback);
|
||||
if (svc == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Install svc is nullptr");
|
||||
return false;
|
||||
}
|
||||
IpcIoPushSvc(&ipcIo, svc);
|
||||
IpcIoPushInt32(&ipcIo, installParam->installLocation);
|
||||
if (!IpcIoAvailable(&ipcIo)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Install ipc failed");
|
||||
return false;
|
||||
}
|
||||
HILOG_DEBUG(HILOG_MODULE_APP, "BMS client invoke install");
|
||||
uint8_t result = 0;
|
||||
int32_t ret = bmsInnerClient->Invoke(bmsInnerClient, INSTALL, &ipcIo, &result, Notify);
|
||||
if (ret != OHOS_SUCCESS) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Install invoke failed: %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
return result == OHOS_SUCCESS;
|
||||
}
|
||||
|
||||
bool Uninstall(const char *bundleName, const InstallParam *installParam, InstallerCallback installerCallback)
|
||||
{
|
||||
// installParam is nullptr at present.
|
||||
if ((bundleName == nullptr) || (installerCallback == nullptr) || (strlen(bundleName) >= MAX_BUNDLE_NAME) ||
|
||||
(installParam == nullptr)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager uninstall failed due to nullptr or invalid parameters");
|
||||
return false;
|
||||
}
|
||||
if (CheckSelfPermission(static_cast<const char *>(PERMISSION_INSTALL_BUNDLE)) != GRANTED) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager uninstall failed due to permission denied");
|
||||
return false;
|
||||
}
|
||||
auto bmsInnerClient = GetBmsInnerClient();
|
||||
if (bmsInnerClient == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager uninstall failed due to nullptr bms client");
|
||||
return false;
|
||||
}
|
||||
|
||||
const SvcIdentity *svc = OHOS::BundleSelfCallback::GetInstance().RegisterBundleSelfCallback(installerCallback);
|
||||
if (svc == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Uninstall svc is nullptr");
|
||||
return false;
|
||||
}
|
||||
IpcIo ipcIo;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 1);
|
||||
IpcIoPushString(&ipcIo, bundleName);
|
||||
IpcIoPushSvc(&ipcIo, svc);
|
||||
IpcIoPushBool(&ipcIo, installParam->keepData);
|
||||
if (!IpcIoAvailable(&ipcIo)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Uninstall ipc failed");
|
||||
return false;
|
||||
}
|
||||
HILOG_DEBUG(HILOG_MODULE_APP, "BMS client invoke uninstall");
|
||||
uint8_t result = 0;
|
||||
int32_t ret = bmsInnerClient->Invoke(bmsInnerClient, UNINSTALL, &ipcIo, &result, Notify);
|
||||
if (ret != OHOS_SUCCESS) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Uninstall invoke failed: %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
return result == OHOS_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo)
|
||||
{
|
||||
if ((want == nullptr) || (abilityInfo == nullptr)) {
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
if (CheckSelfPermission(static_cast<const char *>(PERMISSION_GET_BUNDLE_INFO)) != GRANTED) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager query AbilityInfo failed due to permission denied");
|
||||
return ERR_APPEXECFWK_PERMISSION_DENIED;
|
||||
}
|
||||
auto bmsClient = GetBmsClient();
|
||||
if (bmsClient == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager query AbilityInfo failed due to nullptr bms client");
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
|
||||
IpcIo ipcIo;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, OBJECT_NUMBER_IN_WANT);
|
||||
if (!SerializeWant(&ipcIo, want)) {
|
||||
return ERR_APPEXECFWK_SERIALIZATION_FAILED;
|
||||
}
|
||||
if (!IpcIoAvailable(&ipcIo)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager QueryAbilityInfo ipc failed");
|
||||
return ERR_APPEXECFWK_SERIALIZATION_FAILED;
|
||||
}
|
||||
ResultOfQueryAbilityInfo resultOfQueryAbilityInfo = { 0, nullptr };
|
||||
|
||||
int32_t ret = bmsClient->Invoke(bmsClient, QUERY_ABILITY_INFO, &ipcIo, &resultOfQueryAbilityInfo, Notify);
|
||||
if (ret != OHOS_SUCCESS) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager QueryAbilityInfo invoke failed: %{public}d", ret);
|
||||
return ERR_APPEXECFWK_INVOKE_ERROR;
|
||||
}
|
||||
|
||||
if (resultOfQueryAbilityInfo.abilityInfo == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager QueryAbilityInfo failed: %{public}d",
|
||||
resultOfQueryAbilityInfo.resultCode);
|
||||
return resultOfQueryAbilityInfo.resultCode;
|
||||
}
|
||||
if (resultOfQueryAbilityInfo.resultCode == ERR_OK) {
|
||||
OHOS::AbilityInfoUtils::CopyAbilityInfo(abilityInfo, *(resultOfQueryAbilityInfo.abilityInfo));
|
||||
ClearAbilityInfo(resultOfQueryAbilityInfo.abilityInfo);
|
||||
AdapterFree(resultOfQueryAbilityInfo.abilityInfo);
|
||||
}
|
||||
|
||||
return resultOfQueryAbilityInfo.resultCode;
|
||||
}
|
||||
|
||||
uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo)
|
||||
{
|
||||
if ((bundleName == nullptr) || (bundleInfo == nullptr)) {
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
if (flags < 0 || flags > 1 || (strlen(bundleName) >= MAX_BUNDLE_NAME)) {
|
||||
return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR;
|
||||
}
|
||||
if (CheckSelfPermission(static_cast<const char *>(PERMISSION_GET_BUNDLE_INFO)) != GRANTED) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager get BundleInfo failed due to permission denied");
|
||||
return ERR_APPEXECFWK_PERMISSION_DENIED;
|
||||
}
|
||||
auto bmsClient = GetBmsClient();
|
||||
if (bmsClient == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager get BundleInfo failed due to nullptr bms client");
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
|
||||
IpcIo ipcIo;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0);
|
||||
IpcIoPushString(&ipcIo, bundleName);
|
||||
IpcIoPushInt32(&ipcIo, flags);
|
||||
if (!IpcIoAvailable(&ipcIo)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleInfo ipc failed");
|
||||
return ERR_APPEXECFWK_SERIALIZATION_FAILED;
|
||||
}
|
||||
ResultOfGetBundleInfo resultOfGetBundleInfo;
|
||||
resultOfGetBundleInfo.bundleInfo = nullptr;
|
||||
int32_t ret = bmsClient->Invoke(bmsClient, GET_BUNDLE_INFO, &ipcIo, &resultOfGetBundleInfo, Notify);
|
||||
if (ret != OHOS_SUCCESS) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleInfo invoke failed: %{public}d", ret);
|
||||
return ERR_APPEXECFWK_INVOKE_ERROR;
|
||||
}
|
||||
if (resultOfGetBundleInfo.bundleInfo == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleInfo failed: %{public}d",
|
||||
resultOfGetBundleInfo.resultCode);
|
||||
return resultOfGetBundleInfo.resultCode;
|
||||
}
|
||||
if (resultOfGetBundleInfo.resultCode == ERR_OK) {
|
||||
OHOS::BundleInfoUtils::CopyBundleInfo(flags, bundleInfo, *(resultOfGetBundleInfo.bundleInfo));
|
||||
ClearBundleInfo(resultOfGetBundleInfo.bundleInfo);
|
||||
AdapterFree(resultOfGetBundleInfo.bundleInfo);
|
||||
}
|
||||
return resultOfGetBundleInfo.resultCode;
|
||||
}
|
||||
|
||||
static uint8_t ObtainInnerBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len,
|
||||
uint8_t code, IpcIo *ipcIo)
|
||||
{
|
||||
if ((bundleInfos == nullptr) || (len == nullptr) || (ipcIo == nullptr)) {
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
if (CheckSelfPermission(static_cast<const char *>(PERMISSION_GET_BUNDLE_INFO)) != GRANTED) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager get BundleInfos failed due to permission denied");
|
||||
return ERR_APPEXECFWK_PERMISSION_DENIED;
|
||||
}
|
||||
auto bmsClient = GetBmsClient();
|
||||
if (bmsClient == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager get BundleInfos failed due to nullptr bms client");
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
|
||||
if (!IpcIoAvailable(ipcIo)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleInfos ipc failed");
|
||||
return ERR_APPEXECFWK_SERIALIZATION_FAILED;
|
||||
}
|
||||
ResultOfGetBundleInfos resultOfGetBundleInfos;
|
||||
resultOfGetBundleInfos.length = 0;
|
||||
resultOfGetBundleInfos.bundleInfo = nullptr;
|
||||
int32_t ret = bmsClient->Invoke(bmsClient, code, ipcIo, &resultOfGetBundleInfos, Notify);
|
||||
if (ret != OHOS_SUCCESS) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager ObtainInnerBundleInfo invoke failed: %{public}d\n", ret);
|
||||
return ERR_APPEXECFWK_INVOKE_ERROR;
|
||||
}
|
||||
|
||||
if (resultOfGetBundleInfos.length == 0 || resultOfGetBundleInfos.resultCode != ERR_OK) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager ObtainInnerBundleInfo fail");
|
||||
*bundleInfos = nullptr;
|
||||
return resultOfGetBundleInfos.resultCode;
|
||||
}
|
||||
|
||||
*bundleInfos = reinterpret_cast<BundleInfo *>(AdapterMalloc(sizeof(BundleInfo) * resultOfGetBundleInfos.length));
|
||||
if (*bundleInfos == nullptr) {
|
||||
OHOS::BundleInfoUtils::FreeBundleInfos(resultOfGetBundleInfos.bundleInfo, resultOfGetBundleInfos.length);
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
if (memset_s(*bundleInfos, sizeof(BundleInfo) * (resultOfGetBundleInfos.length), 0, sizeof(BundleInfo) *
|
||||
(resultOfGetBundleInfos.length)) != EOK) {
|
||||
AdapterFree(*bundleInfos);
|
||||
OHOS::BundleInfoUtils::FreeBundleInfos(resultOfGetBundleInfos.bundleInfo, resultOfGetBundleInfos.length);
|
||||
return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR;
|
||||
}
|
||||
for (int32_t i = 0; i < resultOfGetBundleInfos.length; ++i) {
|
||||
OHOS::BundleInfoUtils::CopyBundleInfo(flags, *bundleInfos + i, (resultOfGetBundleInfos.bundleInfo)[i]);
|
||||
}
|
||||
*len = resultOfGetBundleInfos.length;
|
||||
OHOS::BundleInfoUtils::FreeBundleInfos(resultOfGetBundleInfos.bundleInfo, resultOfGetBundleInfos.length);
|
||||
return resultOfGetBundleInfos.resultCode;
|
||||
}
|
||||
|
||||
uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len)
|
||||
{
|
||||
if ((bundleInfos == nullptr) || (len == nullptr)) {
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
|
||||
if (flags < 0 || flags > 1) {
|
||||
return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR;
|
||||
}
|
||||
IpcIo ipcIo;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0);
|
||||
IpcIoPushInt32(&ipcIo, flags);
|
||||
return ObtainInnerBundleInfos(flags, bundleInfos, len, GET_BUNDLE_INFOS, &ipcIo);
|
||||
}
|
||||
|
||||
uint8_t QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len)
|
||||
{
|
||||
if ((bundleInfos == nullptr) || (len == nullptr)) {
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
IpcIo ipcIo;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0);
|
||||
return ObtainInnerBundleInfos(0, bundleInfos, len, QUERY_KEEPALIVE_BUNDLE_INFOS, &ipcIo);
|
||||
}
|
||||
|
||||
uint8_t GetBundleInfosByMetaData(const char *metaDataKey, BundleInfo **bundleInfos, int32_t *len)
|
||||
{
|
||||
if ((metaDataKey == nullptr) || (bundleInfos == nullptr) || (len == nullptr)) {
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
IpcIo ipcIo;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0);
|
||||
IpcIoPushString(&ipcIo, metaDataKey);
|
||||
return ObtainInnerBundleInfos(0, bundleInfos, len, GET_BUNDLE_INFOS_BY_METADATA, &ipcIo);
|
||||
}
|
||||
|
||||
uint8_t GetBundleNameForUid(int32_t uid, char **bundleName)
|
||||
{
|
||||
if (bundleName == nullptr) {
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
if (CheckSelfPermission(static_cast<const char *>(PERMISSION_GET_BUNDLE_INFO)) != GRANTED) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager get BundleName for uid failed due to permission denied");
|
||||
return ERR_APPEXECFWK_PERMISSION_DENIED;
|
||||
}
|
||||
auto bmsClient = GetBmsClient();
|
||||
if (bmsClient == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager get BundleName for uid failed due to nullptr bms client");
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
|
||||
IpcIo ipcIo;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0);
|
||||
IpcIoPushInt32(&ipcIo, uid);
|
||||
|
||||
ResultOfGetBundleNameForUid resultOfGetBundleNameForUid;
|
||||
resultOfGetBundleNameForUid.length = 0;
|
||||
resultOfGetBundleNameForUid.bundleName = nullptr;
|
||||
int32_t ret = bmsClient->Invoke(bmsClient, GET_BUNDLENAME_FOR_UID, &ipcIo, &resultOfGetBundleNameForUid, Notify);
|
||||
if (ret != OHOS_SUCCESS) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleNameForUid invoke failed: %{public}d\n", ret);
|
||||
return ERR_APPEXECFWK_INVOKE_ERROR;
|
||||
}
|
||||
if (resultOfGetBundleNameForUid.bundleName == nullptr || resultOfGetBundleNameForUid.length == 0) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleNameForUid failed: %{public}d\n",
|
||||
resultOfGetBundleNameForUid.resultCode);
|
||||
return resultOfGetBundleNameForUid.resultCode;
|
||||
}
|
||||
|
||||
*bundleName = reinterpret_cast<char *>(AdapterMalloc(resultOfGetBundleNameForUid.length + 1));
|
||||
if (*bundleName == nullptr) {
|
||||
AdapterFree(resultOfGetBundleNameForUid.bundleName);
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
errno_t err = strncpy_s(*bundleName, resultOfGetBundleNameForUid.length + 1,
|
||||
resultOfGetBundleNameForUid.bundleName, resultOfGetBundleNameForUid.length);
|
||||
AdapterFree(resultOfGetBundleNameForUid.bundleName);
|
||||
if (err != EOK) {
|
||||
return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR;
|
||||
}
|
||||
return resultOfGetBundleNameForUid.resultCode;
|
||||
}
|
||||
|
||||
bool HasSystemCapability(const char *sysCapName)
|
||||
{
|
||||
if (sysCapName == nullptr || strlen(sysCapName) > MAX_SYSCAP_NAME_LEN) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager HasSystemCapability failed due to parameters is invalid");
|
||||
return false;
|
||||
}
|
||||
auto bmsClient = GetBmsClient();
|
||||
if (bmsClient == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager HasSystemCapability failed due to nullptr bms client");
|
||||
return false;
|
||||
}
|
||||
IpcIo ipcIo;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0);
|
||||
IpcIoPushString(&ipcIo, sysCapName);
|
||||
if (!IpcIoAvailable(&ipcIo)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager HasSystemCapability ipc failed");
|
||||
return false;
|
||||
}
|
||||
uint8_t result = 0;
|
||||
int32_t ret = bmsClient->Invoke(bmsClient, CHECK_SYS_CAP, &ipcIo, &result, Notify);
|
||||
if (ret != OHOS_SUCCESS) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager HasSystemCapability invoke failed: %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
return result == OHOS_SUCCESS;
|
||||
}
|
||||
|
||||
SystemCapability *GetSystemAvailableCapabilities()
|
||||
{
|
||||
auto bmsClient = GetBmsClient();
|
||||
if (bmsClient == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetSystemAvailableCapabilities failed due to nullptr bms client");
|
||||
return nullptr;
|
||||
}
|
||||
IpcIo ipcIo;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0);
|
||||
if (!IpcIoAvailable(&ipcIo)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetSystemAvailableCapabilities ipc failed");
|
||||
return nullptr;
|
||||
}
|
||||
ResultOfGetSysCap resultOfGetSysCap;
|
||||
resultOfGetSysCap.systemCap.systemCapNum = 0;
|
||||
resultOfGetSysCap.systemCap.systemCapName = nullptr;
|
||||
int32_t ret = bmsClient->Invoke(bmsClient, GET_SYS_CAP, &ipcIo, &resultOfGetSysCap, Notify);
|
||||
if (ret != OHOS_SUCCESS) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetSystemAvailableCapabilities invoke failed: %{public}d\n", ret);
|
||||
return nullptr;
|
||||
}
|
||||
if (resultOfGetSysCap.systemCap.systemCapNum == 0 || resultOfGetSysCap.resultCode != ERR_OK
|
||||
|| resultOfGetSysCap.systemCap.systemCapName == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetSystemAvailableCapabilities fail");
|
||||
return nullptr;
|
||||
}
|
||||
int32_t sysCapNum = resultOfGetSysCap.systemCap.systemCapNum;
|
||||
SystemCapability *retSystemCap = reinterpret_cast<SystemCapability *>(AdapterMalloc(sizeof(SystemCapability)));
|
||||
if (retSystemCap == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetSystemAvailableCapabilities retSystemCap is null");
|
||||
AdapterFree(resultOfGetSysCap.systemCap.systemCapName);
|
||||
return nullptr;
|
||||
}
|
||||
if (memset_s(retSystemCap, sizeof(SystemCapability), 0, sizeof(SystemCapability)) != EOK) {
|
||||
AdapterFree(resultOfGetSysCap.systemCap.systemCapName);
|
||||
AdapterFree(retSystemCap);
|
||||
return nullptr;
|
||||
}
|
||||
int32_t sysCapNameMem = sizeof(SystemCapName) * sysCapNum;
|
||||
retSystemCap->systemCapName = reinterpret_cast<SystemCapName *>(AdapterMalloc(sysCapNameMem));
|
||||
if (retSystemCap->systemCapName == nullptr) {
|
||||
AdapterFree(resultOfGetSysCap.systemCap.systemCapName);
|
||||
AdapterFree(retSystemCap);
|
||||
return nullptr;
|
||||
}
|
||||
if (memset_s(retSystemCap->systemCapName, sysCapNameMem, 0, sysCapNameMem) != EOK) {
|
||||
AdapterFree(resultOfGetSysCap.systemCap.systemCapName);
|
||||
AdapterFree(retSystemCap->systemCapName);
|
||||
AdapterFree(retSystemCap);
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetSystemAvailableCapabilities memset error");
|
||||
return nullptr;
|
||||
}
|
||||
for (int32_t index = 0; index < sysCapNum; index++) {
|
||||
int32_t copyLen = strlen(resultOfGetSysCap.systemCap.systemCapName[index].name);
|
||||
errno_t err = strncpy_s(retSystemCap->systemCapName[index].name, MAX_SYSCAP_NAME_LEN,
|
||||
resultOfGetSysCap.systemCap.systemCapName[index].name, copyLen);
|
||||
if (err != EOK) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetSystemAvailableCapabilities strcpy error %{public}d", err);
|
||||
AdapterFree(resultOfGetSysCap.systemCap.systemCapName);
|
||||
AdapterFree(retSystemCap->systemCapName);
|
||||
AdapterFree(retSystemCap);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
retSystemCap->systemCapNum = sysCapNum;
|
||||
return retSystemCap;
|
||||
}
|
||||
|
||||
void FreeSystemAvailableCapabilitiesInfo(SystemCapability *sysCap)
|
||||
{
|
||||
if (sysCap == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (sysCap->systemCapName != nullptr) {
|
||||
AdapterFree(sysCap->systemCapName);
|
||||
}
|
||||
AdapterFree(sysCap);
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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 "bundle_self_callback.h"
|
||||
|
||||
#include "adapter.h"
|
||||
#include "bundle_callback_utils.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "iproxy_client.h"
|
||||
#include "log.h"
|
||||
#include "samgr_lite.h"
|
||||
|
||||
namespace OHOS {
|
||||
BundleSelfCallback::~BundleSelfCallback()
|
||||
{
|
||||
if (svcIdentity_ != nullptr) {
|
||||
(void) UnregisterIpcCallback(*svcIdentity_);
|
||||
AdapterFree(svcIdentity_);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t InnerCallback(const char *resultMessage, uint8_t resultCode, const InstallerCallback& installerCallback)
|
||||
{
|
||||
if ((resultMessage == nullptr) || (installerCallback == nullptr)) {
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
if (resultCode == ERR_OK) {
|
||||
installerCallback(resultCode, resultMessage);
|
||||
} else {
|
||||
installerCallback(resultCode, ObtainErrorMessage(resultCode).c_str());
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t BundleSelfCallback::Callback(const IpcContext* context, void *ipcMsg, IpcIo *io, void *arg)
|
||||
{
|
||||
if (ipcMsg == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleSelfCallback ipcMsg is nullptr");
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
|
||||
if (io == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleSelfCallback io is nullptr");
|
||||
FreeBuffer(NULL, ipcMsg);
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
InstallerCallback installerCallback = GetInstance().GetCallback();
|
||||
if (installerCallback == nullptr) {
|
||||
FreeBuffer(NULL, ipcMsg);
|
||||
return ERR_APPEXECFWK_OBJECT_NULL;
|
||||
}
|
||||
uint32_t installType = 0;
|
||||
int32_t ret = GetCode(ipcMsg, &installType);
|
||||
if (ret != LITEIPC_OK) {
|
||||
FreeBuffer(NULL, ipcMsg);
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleSelfCallback Get install type failed");
|
||||
return ERR_APPEXECFWK_CALLBACK_GET_INSTALLTYPE_FAILED;
|
||||
}
|
||||
auto resultCode = static_cast<uint8_t>(IpcIoPopInt32(io));
|
||||
FreeBuffer(NULL, ipcMsg);
|
||||
if (installType == INSTALL_CALLBACK) {
|
||||
return InnerCallback(INSTALL_SUCCESS, resultCode, installerCallback);
|
||||
}
|
||||
if (installType == UNINSTALL_CALLBACK) {
|
||||
return InnerCallback(UNINSTALL_SUCCESS, resultCode, installerCallback);
|
||||
}
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleSelfCallback get error install type");
|
||||
return ERR_APPEXECFWK_CALLBACK_GET_ERROR_INSTALLTYPE;
|
||||
}
|
||||
|
||||
int32 BundleSelfCallback::GenerateLocalServiceId()
|
||||
{
|
||||
svcIdentity_ = reinterpret_cast<SvcIdentity *>(AdapterMalloc(sizeof(SvcIdentity)));
|
||||
if (svcIdentity_ == nullptr) {
|
||||
return ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED;
|
||||
}
|
||||
|
||||
int32_t ret = RegisterIpcCallback(Callback, 0, IPC_WAIT_FOREVER, svcIdentity_, NULL);
|
||||
if ((ret != LITEIPC_OK)) {
|
||||
AdapterFree(svcIdentity_);
|
||||
svcIdentity_ = nullptr;
|
||||
return ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
const SvcIdentity *BundleSelfCallback::RegisterBundleSelfCallback(InstallerCallback &installerCallback)
|
||||
{
|
||||
if (installerCallback == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (svcIdentity_ == nullptr) {
|
||||
int32 ret = GenerateLocalServiceId();
|
||||
if (ret != ERR_OK) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
installerCallback_ = installerCallback;
|
||||
return svcIdentity_;
|
||||
}
|
||||
|
||||
const InstallerCallback BundleSelfCallback::GetCallback()
|
||||
{
|
||||
return installerCallback_;
|
||||
}
|
||||
} // namespace
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 "bundel_status_callback.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
void ClearBundleStatusCallback(BundleStatusCallback *bundleStatusCallback)
|
||||
{
|
||||
if (bundleStatusCallback == nullptr) {
|
||||
return;
|
||||
}
|
||||
AdapterFree(bundleStatusCallback->bundleName);
|
||||
AdapterFree(bundleStatusCallback->data);
|
||||
}
|
||||
Executable
+849
@@ -0,0 +1,849 @@
|
||||
/*
|
||||
* 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 "convert_utils.h"
|
||||
|
||||
#include "ability_info_utils.h"
|
||||
#include "bundle_info_utils.h"
|
||||
#include "log.h"
|
||||
#include "module_info_utils.h"
|
||||
#include "securec.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
// bundleInfo json key
|
||||
const char BUNDLEINFO_JSON_KEY_SYSTEMAPP[] = "isSystemApp";
|
||||
const char BUNDLEINFO_JSON_KEY_NATIVEAPP[] = "isNativeApp";
|
||||
const char BUNDLEINFO_JSON_KEY_KEEPALIVE[] = "isKeepAlive";
|
||||
const char BUNDLEINFO_JSON_KEY_VERSIONCODE[] = "versionCode";
|
||||
const char BUNDLEINFO_JSON_KEY_UID[] = "uid";
|
||||
const char BUNDLEINFO_JSON_KEY_GID[] = "gid";
|
||||
const char BUNDLEINFO_JSON_KEY_VERSIONNAME[] = "versionName";
|
||||
const char BUNDLEINFO_JSON_KEY_BUNDLENAME[] = "bundleName";
|
||||
const char BUNDLEINFO_JSON_KEY_LABLE[] = "label";
|
||||
const char BUNDLEINFO_JSON_KEY_ICONPATH[] = "iconPath";
|
||||
const char BUNDLEINFO_JSON_KEY_CODEPATH[] = "codePath";
|
||||
const char BUNDLEINFO_JSON_KEY_DATAPATH[] = "dataPath";
|
||||
const char BUNDLEINFO_JSON_KEY_COMPATIBLEAPI[] = "compatibleApi";
|
||||
const char BUNDLEINFO_JSON_KEY_TARGETAPI[] = "targetApi";
|
||||
const char BUNDLEINFO_JSON_KEY_VENDOR[] = "vendor";
|
||||
const char BUNDLEINFO_JSON_KEY_APPID[] = "appId";
|
||||
const char BUNDLEINFO_JSON_KEY_NUMOFMODULE[] = "numOfModule";
|
||||
const char BUNDLEINFO_JSON_KEY_MODULEINFOS[] = "moduleInfos";
|
||||
const char BUNDLEINFO_JSON_KEY_NUMOFABILITY[] = "numOfAbility";
|
||||
const char BUNDLEINFO_JSON_KEY_ABILITYINFOS[] = "abilityInfos";
|
||||
// abilityInfo json key
|
||||
const char ABILITYINFO_JSON_KEY_BUNDLENAME[] = "bundleName";
|
||||
const char ABILITYINFO_JSON_KEY_NAME[] = "name";
|
||||
const char ABILITYINFO_JSON_KEY_ABILITYTYPE[] = "abilityType";
|
||||
const char ABILITYINFO_JSON_KEY_LAUNCHMODE[] = "launchMode";
|
||||
const char ABILITYINFO_JSON_KEY_VISIBLE[] = "isVisible";
|
||||
const char ABILITYINFO_JSON_KEY_MODULENAME[] = "moduleName";
|
||||
const char ABILITYINFO_JSON_KEY_DESCRIPTION[] = "description";
|
||||
const char ABILITYINFO_JSON_KEY_ICONPATH[] = "iconPath";
|
||||
const char ABILITYINFO_JSON_KEY_DEVICEID[] = "deviceId";
|
||||
const char ABILITYINFO_JSON_KEY_LABEL[] = "label";
|
||||
// moduleInfo json key
|
||||
const char MODULEINFO_JSON_KEY_NAME[] = "name";
|
||||
const char MODULEINFO_JSON_KEY_DESCRIPTION[] = "description";
|
||||
const char MODULEINFO_JSON_KEY_MODULENAME[] = "moduleName";
|
||||
const char MODULEINFO_JSON_KEY_MODULETYPE[] = "moduleType";
|
||||
const char MODULEINFO_JSON_KEY_DELIVERYINSTALL[] = "isDeliveryInstall";
|
||||
const char MODULEINFO_JSON_KEY_DEVICETYPE[] = "deviceType";
|
||||
const char MODULEINFO_JSON_KEY_METADATA[] = "metaData";
|
||||
const char MODULEINFO_JSON_KEY_METADATA_NAME[] = "name";
|
||||
const char MODULEINFO_JSON_KEY_METADATA_VALUE[] = "value";
|
||||
const char MODULEINFO_JSON_KEY_METADATA_EXTRA[] = "extra";
|
||||
|
||||
char *ConvertUtils::ConvertAbilityInfoToString(const AbilityInfo *abilityInfo)
|
||||
{
|
||||
if (abilityInfo == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
cJSON *root = GetJsonAbilityInfo(abilityInfo);
|
||||
if (root == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
char *str = cJSON_PrintUnformatted(root);
|
||||
cJSON_Delete(root);
|
||||
return str;
|
||||
}
|
||||
|
||||
char *ConvertUtils::ConvertBundleInfoToString(const BundleInfo *bundleInfo)
|
||||
{
|
||||
if (bundleInfo == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
cJSON *root = GetJsonBundleInfo(bundleInfo);
|
||||
if (root == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
char *str = cJSON_PrintUnformatted(root);
|
||||
cJSON_Delete(root);
|
||||
return str;
|
||||
}
|
||||
|
||||
char *ConvertUtils::ConvertBundleInfosToString(BundleInfo **bundleInfo, uint32_t numOfBundleInfo)
|
||||
{
|
||||
if (bundleInfo == nullptr || numOfBundleInfo == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
cJSON *roots = GetJsonBundleInfos(bundleInfo, numOfBundleInfo);
|
||||
if (roots == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
char *strs = cJSON_PrintUnformatted(roots);
|
||||
cJSON_Delete(roots);
|
||||
return strs;
|
||||
}
|
||||
|
||||
AbilityInfo *ConvertUtils::ConvertStringToAbilityInfo(const char *str, size_t buffSize)
|
||||
{
|
||||
if (str == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
AbilityInfo *abilityInfo = reinterpret_cast<AbilityInfo *>(AdapterMalloc(sizeof(AbilityInfo)));
|
||||
if (abilityInfo == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (memset_s(abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo)) != EOK) {
|
||||
AdapterFree(abilityInfo);
|
||||
return nullptr;
|
||||
}
|
||||
cJSON *root = cJSON_ParseWithLength(str, buffSize);
|
||||
if (root == nullptr) {
|
||||
AdapterFree(abilityInfo);
|
||||
return nullptr;
|
||||
}
|
||||
if (!ConvertJsonToAbilityInfo(root, abilityInfo)) {
|
||||
ClearAbilityInfo(abilityInfo);
|
||||
AdapterFree(abilityInfo);
|
||||
cJSON_Delete(root);
|
||||
return nullptr;
|
||||
}
|
||||
cJSON_Delete(root);
|
||||
return abilityInfo;
|
||||
}
|
||||
|
||||
BundleInfo *ConvertUtils::ConvertStringToBundleInfo(const char *str, size_t buffSize)
|
||||
{
|
||||
if (str == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
BundleInfo *bundleInfo = reinterpret_cast<BundleInfo *>(AdapterMalloc(sizeof(BundleInfo)));
|
||||
if (bundleInfo == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (memset_s(bundleInfo, sizeof(BundleInfo), 0, sizeof(BundleInfo)) != EOK) {
|
||||
AdapterFree(bundleInfo);
|
||||
return nullptr;
|
||||
}
|
||||
cJSON *root = cJSON_ParseWithLength(str, buffSize);
|
||||
if (root == nullptr) {
|
||||
AdapterFree(bundleInfo);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ConvertJsonToBundleInfo(root, bundleInfo)) {
|
||||
BundleInfoUtils::FreeBundleInfo(bundleInfo);
|
||||
cJSON_Delete(root);
|
||||
return nullptr;
|
||||
}
|
||||
cJSON_Delete(root);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertStringToBundleInfos(const char *strs, BundleInfo **bundleInfo, uint32_t numOfBundleInfo,
|
||||
size_t buffSize)
|
||||
{
|
||||
if (strs == nullptr || bundleInfo == nullptr || numOfBundleInfo == 0) {
|
||||
return false;
|
||||
}
|
||||
cJSON *roots = cJSON_ParseWithLength(strs, buffSize);
|
||||
if (roots == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!cJSON_IsArray(roots) || static_cast<uint32_t>(cJSON_GetArraySize(roots)) != numOfBundleInfo) {
|
||||
cJSON_Delete(roots);
|
||||
return false;
|
||||
}
|
||||
|
||||
*bundleInfo = reinterpret_cast<BundleInfo *>(AdapterMalloc(sizeof(BundleInfo) * numOfBundleInfo));
|
||||
if (*bundleInfo == nullptr) {
|
||||
cJSON_Delete(roots);
|
||||
return false;
|
||||
}
|
||||
int32_t ret =
|
||||
memset_s(*bundleInfo, sizeof(BundleInfo) * numOfBundleInfo, 0, sizeof(BundleInfo) * numOfBundleInfo);
|
||||
if (ret != EOK) {
|
||||
AdapterFree(*bundleInfo);
|
||||
cJSON_Delete(roots);
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON *item = nullptr;
|
||||
uint32_t i = 0;
|
||||
cJSON_ArrayForEach(item, roots) {
|
||||
if (!ConvertJsonToBundleInfo(item, *bundleInfo + i)) {
|
||||
BundleInfoUtils::FreeBundleInfos(*bundleInfo, numOfBundleInfo);
|
||||
cJSON_Delete(roots);
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
cJSON_Delete(roots);
|
||||
return true;
|
||||
}
|
||||
|
||||
cJSON *ConvertUtils::GetJsonBundleInfo(const BundleInfo *bundleInfo)
|
||||
{
|
||||
if (bundleInfo == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
if (root == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!ConvertBundleInfoPartToJson(bundleInfo, root)) {
|
||||
cJSON_Delete(root);
|
||||
return nullptr;
|
||||
}
|
||||
// set moduleInfos in json
|
||||
if (!ConvertModuleInfosToJson(bundleInfo, root)) {
|
||||
cJSON_Delete(root);
|
||||
return nullptr;
|
||||
}
|
||||
// set abilityInfos in json when is exists
|
||||
if (!ConvertAbilityInfosToJson(bundleInfo, root)) {
|
||||
cJSON_Delete(root);
|
||||
return nullptr;
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertBundleInfoPartToJson(const BundleInfo *bundleInfo, cJSON *root)
|
||||
{
|
||||
if (bundleInfo == nullptr || root == nullptr) {
|
||||
return false;
|
||||
}
|
||||
// set mandatory fileds in json
|
||||
if (cJSON_AddBoolToObject(root, BUNDLEINFO_JSON_KEY_SYSTEMAPP, bundleInfo->isSystemApp) == nullptr ||
|
||||
cJSON_AddBoolToObject(root, BUNDLEINFO_JSON_KEY_NATIVEAPP, bundleInfo->isNativeApp) == nullptr ||
|
||||
cJSON_AddBoolToObject(root, BUNDLEINFO_JSON_KEY_KEEPALIVE, bundleInfo->isKeepAlive) == nullptr ||
|
||||
cJSON_AddNumberToObject(root, BUNDLEINFO_JSON_KEY_VERSIONCODE, bundleInfo->versionCode) == nullptr ||
|
||||
cJSON_AddNumberToObject(root, BUNDLEINFO_JSON_KEY_UID, bundleInfo->uid) == nullptr ||
|
||||
cJSON_AddNumberToObject(root, BUNDLEINFO_JSON_KEY_GID, bundleInfo->gid) == nullptr ||
|
||||
cJSON_AddStringToObject(root, BUNDLEINFO_JSON_KEY_VERSIONNAME, bundleInfo->versionName) == nullptr ||
|
||||
cJSON_AddStringToObject(root, BUNDLEINFO_JSON_KEY_BUNDLENAME, bundleInfo->bundleName) == nullptr ||
|
||||
cJSON_AddStringToObject(root, BUNDLEINFO_JSON_KEY_CODEPATH, bundleInfo->codePath) == nullptr ||
|
||||
cJSON_AddStringToObject(root, BUNDLEINFO_JSON_KEY_DATAPATH, bundleInfo->dataPath) == nullptr ||
|
||||
cJSON_AddNumberToObject(root, BUNDLEINFO_JSON_KEY_COMPATIBLEAPI, bundleInfo->compatibleApi) == nullptr ||
|
||||
cJSON_AddNumberToObject(root, BUNDLEINFO_JSON_KEY_TARGETAPI, bundleInfo->targetApi) == nullptr ||
|
||||
cJSON_AddStringToObject(root, BUNDLEINFO_JSON_KEY_APPID, bundleInfo->appId) == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "set mandatory fileds fail in bundleInfo json!");
|
||||
return false;
|
||||
}
|
||||
// set optional field which is not nullptr in json
|
||||
if ((bundleInfo->label != nullptr &&
|
||||
cJSON_AddStringToObject(root, BUNDLEINFO_JSON_KEY_LABLE, bundleInfo->label) == nullptr) ||
|
||||
(bundleInfo->bigIconPath != nullptr &&
|
||||
cJSON_AddStringToObject(root, BUNDLEINFO_JSON_KEY_ICONPATH, bundleInfo->bigIconPath) == nullptr) ||
|
||||
(bundleInfo->vendor != nullptr &&
|
||||
cJSON_AddStringToObject(root, BUNDLEINFO_JSON_KEY_VENDOR, bundleInfo->vendor) == nullptr)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "set optional filed fail which not nullptr in bundleInfo json!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertModuleInfosToJson(const BundleInfo *bundleInfo, cJSON *root)
|
||||
{
|
||||
if (bundleInfo == nullptr || root == nullptr || bundleInfo->numOfModule <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON *moduleInfosJson = GetJsonModuleInfos(bundleInfo->moduleInfos, bundleInfo->numOfModule);
|
||||
if (moduleInfosJson == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "get modulseInfos fail when convert moduleInfo to json!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cJSON_AddNumberToObject(root, BUNDLEINFO_JSON_KEY_NUMOFMODULE, bundleInfo->numOfModule) == nullptr) {
|
||||
cJSON_Delete(moduleInfosJson);
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "cJSON_AddNumberToObject fail when convert moduleInfo to json!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!cJSON_AddItemToObject(root, BUNDLEINFO_JSON_KEY_MODULEINFOS, moduleInfosJson)) {
|
||||
cJSON_Delete(moduleInfosJson);
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "cJSON_AddItemToObject fail when convert moduleInfo to json!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertAbilityInfosToJson(const BundleInfo *bundleInfo, cJSON *root)
|
||||
{
|
||||
if (bundleInfo == nullptr || root == nullptr || bundleInfo->numOfAbility < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bundleInfo->numOfAbility == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
cJSON *abilitysJson = GetJsonAbilityInfos(bundleInfo->abilityInfos, bundleInfo->numOfAbility);
|
||||
if (abilitysJson == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "get abilityInfos fail when convert abilityInfo to json!");
|
||||
return false;
|
||||
}
|
||||
if (cJSON_AddNumberToObject(root, BUNDLEINFO_JSON_KEY_NUMOFABILITY, bundleInfo->numOfAbility) == nullptr) {
|
||||
cJSON_Delete(abilitysJson);
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "cJSON_AddNumberToObject fail when convert abilityInfo to json!");
|
||||
return false;
|
||||
}
|
||||
if (!cJSON_AddItemToObject(root, BUNDLEINFO_JSON_KEY_ABILITYINFOS, abilitysJson)) {
|
||||
cJSON_Delete(abilitysJson);
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "cJSON_AddItemToObject fail when convert abilityInfo to json!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
cJSON *ConvertUtils::GetJsonBundleInfos(BundleInfo **bundleInfo, uint32_t numOfBundleInfo)
|
||||
{
|
||||
if (bundleInfo == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
cJSON *roots = cJSON_CreateArray();
|
||||
if (roots == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < numOfBundleInfo; i++) {
|
||||
cJSON *item = GetJsonBundleInfo(*bundleInfo + i);
|
||||
if (item == nullptr) {
|
||||
cJSON_Delete(roots);
|
||||
return nullptr;
|
||||
}
|
||||
if (!cJSON_AddItemToArray(roots, item)) {
|
||||
cJSON_Delete(item);
|
||||
cJSON_Delete(roots);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return roots;
|
||||
}
|
||||
|
||||
cJSON *ConvertUtils::GetJsonModuleInfos(const ModuleInfo *moduleInfos, uint32_t numOfModule)
|
||||
{
|
||||
if (moduleInfos == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
cJSON *jsonModuleInfos = cJSON_CreateArray();
|
||||
if (jsonModuleInfos == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
for (uint32_t index = 0; index < numOfModule; ++index) {
|
||||
cJSON *moduleInfosItem = cJSON_CreateObject();
|
||||
if (moduleInfosItem == nullptr) {
|
||||
cJSON_Delete(jsonModuleInfos);
|
||||
return nullptr;
|
||||
}
|
||||
// set mandatory fileds in json
|
||||
if (cJSON_AddStringToObject(moduleInfosItem, MODULEINFO_JSON_KEY_MODULENAME,
|
||||
moduleInfos[index].moduleName) == nullptr ||
|
||||
cJSON_AddStringToObject(moduleInfosItem, MODULEINFO_JSON_KEY_MODULETYPE,
|
||||
moduleInfos[index].moduleType) == nullptr ||
|
||||
cJSON_AddBoolToObject(moduleInfosItem, MODULEINFO_JSON_KEY_DELIVERYINSTALL,
|
||||
moduleInfos[index].isDeliveryInstall) == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "set mandatory fileds fail in moduleInfo json!");
|
||||
cJSON_Delete(moduleInfosItem);
|
||||
cJSON_Delete(jsonModuleInfos);
|
||||
return nullptr;
|
||||
}
|
||||
// set optional field which is not nullptr in json
|
||||
if ((moduleInfos[index].name != nullptr && cJSON_AddStringToObject(moduleInfosItem,
|
||||
MODULEINFO_JSON_KEY_NAME, moduleInfos[index].name) == nullptr) ||
|
||||
(moduleInfos[index].description != nullptr && cJSON_AddStringToObject(moduleInfosItem,
|
||||
ABILITYINFO_JSON_KEY_DESCRIPTION, moduleInfos[index].description) == nullptr)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "set optional fileds fail in moduleInfo json!");
|
||||
cJSON_Delete(moduleInfosItem);
|
||||
cJSON_Delete(jsonModuleInfos);
|
||||
return nullptr;
|
||||
}
|
||||
if (!ConvertModuleInfoMetaDataToJson(moduleInfos, index, moduleInfosItem)) {
|
||||
cJSON_Delete(moduleInfosItem);
|
||||
cJSON_Delete(jsonModuleInfos);
|
||||
return nullptr;
|
||||
}
|
||||
if (!ConvertModuleInfoDeviceTypeToJson(moduleInfos, index, moduleInfosItem)) {
|
||||
cJSON_Delete(moduleInfosItem);
|
||||
cJSON_Delete(jsonModuleInfos);
|
||||
return nullptr;
|
||||
}
|
||||
if (!cJSON_AddItemToArray(jsonModuleInfos, moduleInfosItem)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "add moduleInfosItem in jsonModuleInfos fail!");
|
||||
cJSON_Delete(moduleInfosItem);
|
||||
cJSON_Delete(jsonModuleInfos);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return jsonModuleInfos;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertModuleInfoMetaDataToJson(const ModuleInfo *moduleInfos, uint32_t index, cJSON *item)
|
||||
{
|
||||
if (moduleInfos == nullptr || item == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (moduleInfos[index].metaData[0] == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
cJSON *metaDataJson = GetJsonModuleInfoMetaData(moduleInfos, index);
|
||||
if (metaDataJson == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "get metaDataJson fail in moduleInfo json when metaData is not null!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!cJSON_AddItemToObject(item, MODULEINFO_JSON_KEY_METADATA, metaDataJson)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "set metaDataJson fail in moduleInfo json when metaData is not null!");
|
||||
cJSON_Delete(metaDataJson);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertModuleInfoDeviceTypeToJson(const ModuleInfo *moduleInfos, uint32_t index, cJSON *item)
|
||||
{
|
||||
if (moduleInfos == nullptr || item == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (moduleInfos[index].deviceType[0] == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "deviceType is null!");
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON *deviceTypeJson = GetJsonModuleInfoDeviceType(moduleInfos, index);
|
||||
if (deviceTypeJson == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "get deviceType fail in moduleInfo json when deviceType is not null!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!cJSON_AddItemToObject(item, MODULEINFO_JSON_KEY_DEVICETYPE, deviceTypeJson)) {
|
||||
cJSON_Delete(deviceTypeJson);
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "set deviceType fail in moduleInfo json when deviceType is not null!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
cJSON *ConvertUtils::GetJsonModuleInfoMetaData(const ModuleInfo *moduleInfos, uint32_t index)
|
||||
{
|
||||
if (moduleInfos == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
cJSON *jsonMetaData = cJSON_CreateArray();
|
||||
if (jsonMetaData == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
for (uint32_t metaDataIndex = 0; metaDataIndex < METADATA_SIZE; ++metaDataIndex) {
|
||||
if (moduleInfos[index].metaData[metaDataIndex] == nullptr) {
|
||||
break;
|
||||
}
|
||||
cJSON *metaDataItem = cJSON_CreateObject();
|
||||
if (metaDataItem == nullptr) {
|
||||
cJSON_Delete(jsonMetaData);
|
||||
return nullptr;
|
||||
}
|
||||
if ((moduleInfos[index].metaData[metaDataIndex]->name != nullptr && cJSON_AddStringToObject(metaDataItem,
|
||||
MODULEINFO_JSON_KEY_METADATA_NAME, moduleInfos[index].metaData[metaDataIndex]->name) == nullptr) ||
|
||||
(moduleInfos[index].metaData[metaDataIndex]->value != nullptr && cJSON_AddStringToObject(metaDataItem,
|
||||
MODULEINFO_JSON_KEY_METADATA_VALUE, moduleInfos[index].metaData[metaDataIndex]->value) == nullptr) ||
|
||||
(moduleInfos[index].metaData[metaDataIndex]->extra != nullptr && cJSON_AddStringToObject(metaDataItem,
|
||||
MODULEINFO_JSON_KEY_METADATA_EXTRA, moduleInfos[index].metaData[metaDataIndex]->extra) == nullptr) ||
|
||||
!cJSON_AddItemToArray(jsonMetaData, metaDataItem)) {
|
||||
cJSON_Delete(metaDataItem);
|
||||
cJSON_Delete(jsonMetaData);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return jsonMetaData;
|
||||
}
|
||||
|
||||
cJSON *ConvertUtils::GetJsonModuleInfoDeviceType(const ModuleInfo *moduleInfos, uint32_t index)
|
||||
{
|
||||
if (moduleInfos == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
cJSON *jsonDeviceType = cJSON_CreateArray();
|
||||
if (jsonDeviceType == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
for (int32_t deviceTypeIndex = 0; deviceTypeIndex < DEVICE_TYPE_SIZE; ++deviceTypeIndex) {
|
||||
if (moduleInfos[index].deviceType[deviceTypeIndex] == nullptr) {
|
||||
break;
|
||||
}
|
||||
cJSON *object = cJSON_CreateString(moduleInfos[index].deviceType[deviceTypeIndex]);
|
||||
if (object == nullptr) {
|
||||
cJSON_Delete(jsonDeviceType);
|
||||
return nullptr;
|
||||
}
|
||||
if (!cJSON_AddItemToArray(jsonDeviceType, object)) {
|
||||
cJSON_Delete(object);
|
||||
cJSON_Delete(jsonDeviceType);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return jsonDeviceType;
|
||||
}
|
||||
|
||||
cJSON *ConvertUtils::GetJsonAbilityInfos(const AbilityInfo *abilityInfos, uint32_t numOfAbility)
|
||||
{
|
||||
cJSON *jsonAbilityInfos = cJSON_CreateArray();
|
||||
if (jsonAbilityInfos == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
for (uint32_t index = 0; index < numOfAbility; ++index) {
|
||||
cJSON *item = GetJsonAbilityInfo(abilityInfos + index);
|
||||
if (item == nullptr) {
|
||||
cJSON_Delete(jsonAbilityInfos);
|
||||
return nullptr;
|
||||
}
|
||||
if (!cJSON_AddItemToArray(jsonAbilityInfos, item)) {
|
||||
cJSON_Delete(item);
|
||||
cJSON_Delete(jsonAbilityInfos);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return jsonAbilityInfos;
|
||||
}
|
||||
|
||||
cJSON *ConvertUtils::GetJsonAbilityInfo(const AbilityInfo *abilityInfo)
|
||||
{
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
if (root == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
// set mandatory fileds in json
|
||||
if (cJSON_AddBoolToObject(root, ABILITYINFO_JSON_KEY_VISIBLE, abilityInfo->isVisible) == nullptr ||
|
||||
cJSON_AddNumberToObject(root, ABILITYINFO_JSON_KEY_ABILITYTYPE, abilityInfo->abilityType) == nullptr ||
|
||||
cJSON_AddNumberToObject(root, ABILITYINFO_JSON_KEY_LAUNCHMODE, abilityInfo->launchMode) == nullptr ||
|
||||
cJSON_AddStringToObject(root, ABILITYINFO_JSON_KEY_BUNDLENAME, abilityInfo->bundleName) == nullptr ||
|
||||
cJSON_AddStringToObject(root, ABILITYINFO_JSON_KEY_MODULENAME, abilityInfo->moduleName) == nullptr ||
|
||||
cJSON_AddStringToObject(root, ABILITYINFO_JSON_KEY_NAME, abilityInfo->name) == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "set mandatory fileds fail in abilityInfo json!");
|
||||
cJSON_Delete(root);
|
||||
return nullptr;
|
||||
}
|
||||
// set optional fields in json
|
||||
if ((abilityInfo->description != nullptr &&
|
||||
cJSON_AddStringToObject(root, ABILITYINFO_JSON_KEY_DESCRIPTION, abilityInfo->description) == nullptr) ||
|
||||
(abilityInfo->iconPath != nullptr &&
|
||||
cJSON_AddStringToObject(root, ABILITYINFO_JSON_KEY_ICONPATH, abilityInfo->iconPath) == nullptr) ||
|
||||
(abilityInfo->label != nullptr &&
|
||||
cJSON_AddStringToObject(root, ABILITYINFO_JSON_KEY_LABEL, abilityInfo->label) == nullptr) ||
|
||||
(abilityInfo->deviceId != nullptr &&
|
||||
cJSON_AddStringToObject(root, ABILITYINFO_JSON_KEY_DEVICEID, abilityInfo->deviceId) == nullptr)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "set optional fileds fail in abilityInfo json!");
|
||||
cJSON_Delete(root);
|
||||
return nullptr;
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertJsonToBundleInfo(const cJSON *root, BundleInfo *bundleInfo)
|
||||
{
|
||||
if (root == nullptr || bundleInfo == nullptr) {
|
||||
return false;
|
||||
}
|
||||
cJSON *item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_SYSTEMAPP);
|
||||
if (cJSON_IsBool(item)) {
|
||||
bundleInfo->isSystemApp = cJSON_IsTrue(item);
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_NATIVEAPP);
|
||||
if (cJSON_IsBool(item)) {
|
||||
bundleInfo->isNativeApp = cJSON_IsTrue(item);
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_KEEPALIVE);
|
||||
if (cJSON_IsBool(item)) {
|
||||
bundleInfo->isKeepAlive = cJSON_IsTrue(item);
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_VERSIONCODE);
|
||||
if (cJSON_IsNumber(item)) {
|
||||
bundleInfo->versionCode = item->valueint;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_UID);
|
||||
if (cJSON_IsNumber(item)) {
|
||||
bundleInfo->uid = item->valueint;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_GID);
|
||||
if (cJSON_IsNumber(item)) {
|
||||
bundleInfo->gid = item->valueint;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_COMPATIBLEAPI);
|
||||
if (cJSON_IsNumber(item)) {
|
||||
bundleInfo->compatibleApi = item->valueint;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_TARGETAPI);
|
||||
if (cJSON_IsNumber(item)) {
|
||||
bundleInfo->targetApi = item->valueint;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_VERSIONNAME);
|
||||
if (!cJSON_IsString(item) || !BundleInfoUtils::SetBundleInfoVersionName(bundleInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_BUNDLENAME);
|
||||
if (!cJSON_IsString(item) || !BundleInfoUtils::SetBundleInfoBundleName(bundleInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_LABLE);
|
||||
if (cJSON_IsString(item) && !BundleInfoUtils::SetBundleInfoLabel(bundleInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_ICONPATH);
|
||||
if (cJSON_IsString(item) && !BundleInfoUtils::SetBundleInfoBigIconPath(bundleInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_CODEPATH);
|
||||
if (!cJSON_IsString(item) || !BundleInfoUtils::SetBundleInfoCodePath(bundleInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_DATAPATH);
|
||||
if (!cJSON_IsString(item) || !BundleInfoUtils::SetBundleInfoDataPath(bundleInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_VENDOR);
|
||||
if (cJSON_IsString(item) && !BundleInfoUtils::SetBundleInfoVendor(bundleInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_APPID);
|
||||
if (!cJSON_IsString(item) || !BundleInfoUtils::SetBundleInfoAppId(bundleInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_NUMOFMODULE);
|
||||
if (cJSON_IsNumber(item) && item->valueint > 0) {
|
||||
bundleInfo->numOfModule = item->valueint;
|
||||
if (!ConvertJsonToModuleInfos(cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_MODULEINFOS),
|
||||
&(bundleInfo->moduleInfos), bundleInfo->numOfModule)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_NUMOFABILITY);
|
||||
if (cJSON_IsNumber(item) && item->valueint > 0) {
|
||||
bundleInfo->numOfAbility = item->valueint;
|
||||
if (!ConvertJsonToAbilityInfos(cJSON_GetObjectItem(root, BUNDLEINFO_JSON_KEY_ABILITYINFOS),
|
||||
&(bundleInfo->abilityInfos), bundleInfo->numOfAbility)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertJsonToMetaData(const cJSON *metaDataArray, MetaData **metaData)
|
||||
{
|
||||
if (metaData == nullptr || !cJSON_IsArray(metaDataArray) || cJSON_GetArraySize(metaDataArray) > METADATA_SIZE) {
|
||||
return false;
|
||||
}
|
||||
ModuleInfoUtils::ClearModuleInfoMetaData(metaData, METADATA_SIZE);
|
||||
cJSON *metaDataItem = nullptr;
|
||||
uint32_t index = 0;
|
||||
cJSON_ArrayForEach(metaDataItem, metaDataArray) {
|
||||
metaData[index] = reinterpret_cast<MetaData *>(AdapterMalloc(sizeof(MetaData)));
|
||||
if (metaData[index] == nullptr) {
|
||||
return false;
|
||||
}
|
||||
int32_t ret = memset_s(metaData[index], sizeof(MetaData), 0, sizeof(MetaData));
|
||||
if (ret != EOK) {
|
||||
AdapterFree(metaData[index]);
|
||||
return false;
|
||||
}
|
||||
cJSON *item = cJSON_GetObjectItem(metaDataItem, MODULEINFO_JSON_KEY_METADATA_NAME);
|
||||
if (cJSON_IsString(item) && (metaData[index]->name = Utils::Strdup(item->valuestring)) == nullptr) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(metaDataItem, MODULEINFO_JSON_KEY_METADATA_VALUE);
|
||||
if (cJSON_IsString(item) && (metaData[index]->value = Utils::Strdup(item->valuestring)) == nullptr) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(metaDataItem, MODULEINFO_JSON_KEY_METADATA_EXTRA);
|
||||
if (cJSON_IsString(item) && (metaData[index]->extra = Utils::Strdup(item->valuestring)) == nullptr) {
|
||||
return false;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertJsonToDeviceType(const cJSON *deviceTypeArray, char **deviceType)
|
||||
{
|
||||
if (deviceType == nullptr || !cJSON_IsArray(deviceTypeArray) ||
|
||||
cJSON_GetArraySize(deviceTypeArray) > DEVICE_TYPE_SIZE) {
|
||||
return false;
|
||||
}
|
||||
ModuleInfoUtils::ClearModuleInfoDeviceType(deviceType, DEVICE_TYPE_SIZE);
|
||||
cJSON *deviceTypeItem = nullptr;
|
||||
uint32_t index = 0;
|
||||
cJSON_ArrayForEach(deviceTypeItem, deviceTypeArray) {
|
||||
if (!cJSON_IsString(deviceTypeItem)) {
|
||||
return false;
|
||||
}
|
||||
deviceType[index] = Utils::Strdup(deviceTypeItem->valuestring);
|
||||
if (deviceType[index] == nullptr) {
|
||||
return false;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertJsonToModuleInfos(const cJSON *moduleArray, ModuleInfo **moduleInfos, uint32_t numOfModule)
|
||||
{
|
||||
if (moduleInfos == nullptr || !cJSON_IsArray(moduleArray) || numOfModule == 0 ||
|
||||
static_cast<uint32_t>(cJSON_GetArraySize(moduleArray)) != numOfModule) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*moduleInfos = reinterpret_cast<ModuleInfo*>(AdapterMalloc(sizeof(ModuleInfo) * numOfModule));
|
||||
if (*moduleInfos == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t ret = memset_s(*moduleInfos, sizeof(ModuleInfo) * numOfModule, 0, sizeof(ModuleInfo) * numOfModule);
|
||||
if (ret != EOK) {
|
||||
AdapterFree(*moduleInfos);
|
||||
return false;
|
||||
}
|
||||
cJSON *moduleItem = nullptr;
|
||||
uint32_t index = 0;
|
||||
cJSON_ArrayForEach(moduleItem, moduleArray) {
|
||||
cJSON *item = cJSON_GetObjectItem(moduleItem, MODULEINFO_JSON_KEY_NAME);
|
||||
if (cJSON_IsString(item) && !ModuleInfoUtils::SetModuleInfoName(*moduleInfos + index, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(moduleItem, MODULEINFO_JSON_KEY_DESCRIPTION);
|
||||
if (cJSON_IsString(item) &&
|
||||
!ModuleInfoUtils::SetModuleInfoDescription(*moduleInfos + index, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(moduleItem, MODULEINFO_JSON_KEY_MODULENAME);
|
||||
if (!cJSON_IsString(item) ||
|
||||
!ModuleInfoUtils::SetModuleInfoModuleName(*moduleInfos + index, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(moduleItem, MODULEINFO_JSON_KEY_MODULETYPE);
|
||||
if (!cJSON_IsString(item) ||
|
||||
!ModuleInfoUtils::SetModuleInfoModuleType(*moduleInfos + index, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(moduleItem, MODULEINFO_JSON_KEY_DELIVERYINSTALL);
|
||||
if (cJSON_IsBool(item)) {
|
||||
(*moduleInfos + index)->isDeliveryInstall = cJSON_IsTrue(item);
|
||||
}
|
||||
item = cJSON_GetObjectItem(moduleItem, MODULEINFO_JSON_KEY_METADATA);
|
||||
if (cJSON_IsArray(item) && !ConvertJsonToMetaData(item, (*moduleInfos + index)->metaData)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(moduleItem, MODULEINFO_JSON_KEY_DEVICETYPE);
|
||||
if (!cJSON_IsArray(item) || !ConvertJsonToDeviceType(item, (*moduleInfos + index)->deviceType)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertJsonToAbilityInfo(const cJSON *root, AbilityInfo *abilityInfo)
|
||||
{
|
||||
if (root == nullptr || abilityInfo == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON *item = cJSON_GetObjectItem(root, ABILITYINFO_JSON_KEY_BUNDLENAME);
|
||||
if (!cJSON_IsString(item) || !AbilityInfoUtils::SetAbilityInfoBundleName(abilityInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, ABILITYINFO_JSON_KEY_NAME);
|
||||
if (!cJSON_IsString(item) || !AbilityInfoUtils::SetAbilityInfoName(abilityInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, ABILITYINFO_JSON_KEY_ABILITYTYPE);
|
||||
if (cJSON_IsNumber(item)) {
|
||||
abilityInfo->abilityType = AbilityType(item->valueint);
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, ABILITYINFO_JSON_KEY_LAUNCHMODE);
|
||||
if (cJSON_IsNumber(item)) {
|
||||
abilityInfo->launchMode = LaunchMode(item->valueint);
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, ABILITYINFO_JSON_KEY_VISIBLE);
|
||||
abilityInfo->isVisible = cJSON_IsTrue(item);
|
||||
item = cJSON_GetObjectItem(root, ABILITYINFO_JSON_KEY_MODULENAME);
|
||||
if (!cJSON_IsString(item) || !AbilityInfoUtils::SetAbilityInfoModuleName(abilityInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, ABILITYINFO_JSON_KEY_DESCRIPTION);
|
||||
if (cJSON_IsString(item) && !AbilityInfoUtils::SetAbilityInfoDescription(abilityInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, ABILITYINFO_JSON_KEY_ICONPATH);
|
||||
if (cJSON_IsString(item) && !AbilityInfoUtils::SetAbilityInfoIconPath(abilityInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, ABILITYINFO_JSON_KEY_DEVICEID);
|
||||
if (cJSON_IsString(item) && !AbilityInfoUtils::SetAbilityInfoDeviceId(abilityInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
item = cJSON_GetObjectItem(root, ABILITYINFO_JSON_KEY_LABEL);
|
||||
if (cJSON_IsString(item) && !AbilityInfoUtils::SetAbilityInfoLabel(abilityInfo, item->valuestring)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertUtils::ConvertJsonToAbilityInfos(const cJSON *abilityArray, AbilityInfo **abilityInfos,
|
||||
uint32_t numOfAbility)
|
||||
{
|
||||
if (abilityInfos == nullptr || !cJSON_IsArray(abilityArray) || numOfAbility == 0 ||
|
||||
static_cast<uint32_t>(cJSON_GetArraySize(abilityArray)) != numOfAbility) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*abilityInfos = reinterpret_cast<AbilityInfo*>(AdapterMalloc(sizeof(AbilityInfo) * numOfAbility));
|
||||
if (*abilityInfos == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t ret = memset_s(*abilityInfos, sizeof(AbilityInfo) * numOfAbility, 0,
|
||||
sizeof(AbilityInfo) * numOfAbility);
|
||||
if (ret != EOK) {
|
||||
AdapterFree(*abilityInfos);
|
||||
*abilityInfos = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
cJSON *arrayItem = nullptr;
|
||||
uint32_t index = 0;
|
||||
cJSON_ArrayForEach(arrayItem, abilityArray) {
|
||||
if (!ConvertJsonToAbilityInfo(arrayItem, *abilityInfos + index)) {
|
||||
return false;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // OHOS
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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 "element_name_utils.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
namespace {
|
||||
constexpr int VALUE_NULL = 0;
|
||||
constexpr int VALUE_OBJECT = 1;
|
||||
constexpr int MAX_BUNDLE_NAME = 127;
|
||||
constexpr int MAX_ABILITY_NAME = 127;
|
||||
constexpr int MAX_DEVICE_ID = 1024;
|
||||
}
|
||||
#endif
|
||||
|
||||
void ClearElement(ElementName *element)
|
||||
{
|
||||
if (element == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
AdapterFree(element->deviceId);
|
||||
AdapterFree(element->bundleName);
|
||||
AdapterFree(element->abilityName);
|
||||
}
|
||||
|
||||
bool SetElementDeviceID(ElementName *element, const char *deviceId)
|
||||
{
|
||||
if (element == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(element->deviceId);
|
||||
element->deviceId = OHOS::Utils::Strdup(deviceId);
|
||||
return element->deviceId != nullptr;
|
||||
}
|
||||
|
||||
bool SetElementBundleName(ElementName *element, const char *bundleName)
|
||||
{
|
||||
if (element == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(element->bundleName);
|
||||
element->bundleName = OHOS::Utils::Strdup(bundleName);
|
||||
return element->bundleName != nullptr;
|
||||
}
|
||||
|
||||
bool SetElementAbilityName(ElementName *element, const char *abilityName)
|
||||
{
|
||||
if (element == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(element->abilityName);
|
||||
element->abilityName = OHOS::Utils::Strdup(abilityName);
|
||||
return element->abilityName != nullptr;
|
||||
}
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
bool SerializeElement(IpcIo *io, const ElementName *element)
|
||||
{
|
||||
if ((io == nullptr) || (element == nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (element->deviceId == nullptr || strlen(element->deviceId) == 0) {
|
||||
IpcIoPushInt32(io, VALUE_NULL);
|
||||
} else if (strlen(element->deviceId) > MAX_DEVICE_ID) {
|
||||
return false;
|
||||
} else {
|
||||
IpcIoPushInt32(io, VALUE_OBJECT);
|
||||
IpcIoPushString(io, element->deviceId);
|
||||
}
|
||||
if (element->bundleName == nullptr || strlen(element->bundleName) == 0) {
|
||||
IpcIoPushInt32(io, VALUE_NULL);
|
||||
} else if (strlen(element->bundleName) > MAX_BUNDLE_NAME) {
|
||||
return false;
|
||||
} else {
|
||||
IpcIoPushInt32(io, VALUE_OBJECT);
|
||||
IpcIoPushString(io, element->bundleName);
|
||||
}
|
||||
if (element->abilityName == nullptr || strlen(element->abilityName) == 0) {
|
||||
IpcIoPushInt32(io, VALUE_NULL);
|
||||
} else if (strlen(element->abilityName) > MAX_ABILITY_NAME) {
|
||||
return false;
|
||||
} else {
|
||||
IpcIoPushInt32(io, VALUE_OBJECT);
|
||||
IpcIoPushString(io, element->abilityName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeserializeElement(ElementName *element, IpcIo *io)
|
||||
{
|
||||
if ((io == nullptr) || (element == nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IpcIoPopInt32(io) == VALUE_OBJECT &&
|
||||
!SetElementDeviceID(element, reinterpret_cast<char *>(IpcIoPopString(io, nullptr)))) {
|
||||
return false;
|
||||
}
|
||||
if (IpcIoPopInt32(io) == VALUE_OBJECT &&
|
||||
!SetElementBundleName(element, reinterpret_cast<char *>(IpcIoPopString(io, nullptr)))) {
|
||||
ClearElement(element);
|
||||
return false;
|
||||
}
|
||||
if (IpcIoPopInt32(io) == VALUE_OBJECT &&
|
||||
!SetElementAbilityName(element, reinterpret_cast<char *>(IpcIoPopString(io, nullptr)))) {
|
||||
ClearElement(element);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 "module_info.h"
|
||||
|
||||
#include "module_info_utils.h"
|
||||
#include "utils.h"
|
||||
|
||||
void ClearModuleInfo(ModuleInfo *moduleInfo)
|
||||
{
|
||||
if (moduleInfo == nullptr) {
|
||||
return;
|
||||
}
|
||||
AdapterFree(moduleInfo->moduleName);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
AdapterFree(moduleInfo->name);
|
||||
AdapterFree(moduleInfo->description);
|
||||
AdapterFree(moduleInfo->moduleType);
|
||||
OHOS::ModuleInfoUtils::ClearModuleInfoDeviceType(moduleInfo->deviceType, DEVICE_TYPE_SIZE);
|
||||
#endif
|
||||
OHOS::ModuleInfoUtils::ClearModuleInfoMetaData(moduleInfo->metaData, METADATA_SIZE);
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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 "module_info_utils.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
void ModuleInfoUtils::CopyModuleInfo(ModuleInfo *des, ModuleInfo src)
|
||||
{
|
||||
if (des == nullptr) {
|
||||
return;
|
||||
}
|
||||
SetModuleInfoModuleName(des, src.moduleName);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
SetModuleInfoName(des, src.name);
|
||||
SetModuleInfoDescription(des, src.description);
|
||||
SetModuleInfoModuleType(des, src.moduleType);
|
||||
SetModuleInfoDeviceType(des, src.deviceType, DEVICE_TYPE_SIZE);
|
||||
des->isDeliveryInstall = src.isDeliveryInstall;
|
||||
#endif
|
||||
SetModuleInfoMetaData(des, src.metaData, METADATA_SIZE);
|
||||
}
|
||||
|
||||
void ModuleInfoUtils::ClearModuleInfoMetaData(MetaData **metaData, uint32_t numOfMetaData)
|
||||
{
|
||||
if (metaData == nullptr || numOfMetaData > METADATA_SIZE) {
|
||||
return;
|
||||
}
|
||||
for (uint32_t i = 0; i < numOfMetaData; i++) {
|
||||
if (metaData[i] != nullptr) {
|
||||
AdapterFree(metaData[i]->name);
|
||||
AdapterFree(metaData[i]->value);
|
||||
AdapterFree(metaData[i]->extra);
|
||||
AdapterFree(metaData[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleInfoUtils::ClearModuleInfo(ModuleInfo *moduleInfo)
|
||||
{
|
||||
if (moduleInfo == nullptr) {
|
||||
return;
|
||||
}
|
||||
AdapterFree(moduleInfo->moduleName);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
AdapterFree(moduleInfo->name);
|
||||
AdapterFree(moduleInfo->description);
|
||||
AdapterFree(moduleInfo->moduleType);
|
||||
ClearModuleInfoDeviceType(moduleInfo->deviceType, DEVICE_TYPE_SIZE);
|
||||
#endif
|
||||
ClearModuleInfoMetaData(moduleInfo->metaData, METADATA_SIZE);
|
||||
}
|
||||
|
||||
bool ModuleInfoUtils::SetModuleInfoModuleName(ModuleInfo *moduleInfo, const char *moduleName)
|
||||
{
|
||||
if (moduleInfo == nullptr || moduleName == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(moduleInfo->moduleName);
|
||||
moduleInfo->moduleName = Utils::Strdup(moduleName);
|
||||
return moduleInfo->moduleName != nullptr;
|
||||
}
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
bool ModuleInfoUtils::SetModuleInfoName(ModuleInfo *moduleInfo, const char *name)
|
||||
{
|
||||
if (moduleInfo == nullptr || name == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(moduleInfo->name);
|
||||
moduleInfo->name = Utils::Strdup(name);
|
||||
return moduleInfo->name != nullptr;
|
||||
}
|
||||
|
||||
bool ModuleInfoUtils::SetModuleInfoDescription(ModuleInfo *moduleInfo, const char *description)
|
||||
{
|
||||
if (moduleInfo == nullptr || description == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(moduleInfo->description);
|
||||
moduleInfo->description = Utils::Strdup(description);
|
||||
return moduleInfo->description != nullptr;
|
||||
}
|
||||
|
||||
bool ModuleInfoUtils::SetModuleInfoModuleType(ModuleInfo *moduleInfo, const char *moduleType)
|
||||
{
|
||||
if (moduleInfo == nullptr || moduleType == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AdapterFree(moduleInfo->moduleType);
|
||||
moduleInfo->moduleType = Utils::Strdup(moduleType);
|
||||
return moduleInfo->moduleType != nullptr;
|
||||
}
|
||||
|
||||
bool ModuleInfoUtils::SetModuleInfoDeviceType(ModuleInfo *moduleInfo, char **deviceType, uint32_t numOfDeviceType)
|
||||
{
|
||||
if (moduleInfo == nullptr || deviceType == nullptr || numOfDeviceType > DEVICE_TYPE_SIZE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ClearModuleInfoDeviceType(moduleInfo->deviceType, DEVICE_TYPE_SIZE);
|
||||
|
||||
for (uint32_t i = 0; i < numOfDeviceType; i++) {
|
||||
if (deviceType[i] != nullptr) {
|
||||
moduleInfo->deviceType[i] = Utils::Strdup(deviceType[i]);
|
||||
if (moduleInfo->deviceType[i] == nullptr) {
|
||||
ClearModuleInfoDeviceType(moduleInfo->deviceType, DEVICE_TYPE_SIZE);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ModuleInfoUtils::ClearModuleInfoDeviceType(char **deviceType, uint32_t numOfdeviceType)
|
||||
{
|
||||
if (deviceType == nullptr || numOfdeviceType == 0 || numOfdeviceType > DEVICE_TYPE_SIZE) {
|
||||
return;
|
||||
}
|
||||
for (uint32_t i = 0; i < numOfdeviceType; i++) {
|
||||
AdapterFree(deviceType[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool ModuleInfoUtils::SetModuleInfoMetaData(ModuleInfo *moduleInfo, MetaData **metaData, uint32_t numOfMetaData)
|
||||
{
|
||||
if (moduleInfo == nullptr || metaData == nullptr || numOfMetaData > METADATA_SIZE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ClearModuleInfoMetaData(moduleInfo->metaData, METADATA_SIZE);
|
||||
|
||||
for (uint32_t i = 0; i < numOfMetaData; i++) {
|
||||
if (metaData[i] != nullptr) {
|
||||
moduleInfo->metaData[i] = reinterpret_cast<MetaData *>(AdapterMalloc(sizeof(MetaData)));
|
||||
if (moduleInfo->metaData[i] == nullptr ||
|
||||
memset_s(moduleInfo->metaData[i], sizeof(MetaData), 0, sizeof(MetaData)) != EOK) {
|
||||
ClearModuleInfoMetaData(moduleInfo->metaData, i);
|
||||
return false;
|
||||
}
|
||||
if (metaData[i]->name != nullptr) {
|
||||
moduleInfo->metaData[i]->name = Utils::Strdup(metaData[i]->name);
|
||||
}
|
||||
if (metaData[i]->value != nullptr) {
|
||||
moduleInfo->metaData[i]->value = Utils::Strdup(metaData[i]->value);
|
||||
}
|
||||
if (metaData[i]->extra != nullptr) {
|
||||
moduleInfo->metaData[i]->extra = Utils::Strdup(metaData[i]->extra);
|
||||
}
|
||||
|
||||
if ((metaData[i]->name != nullptr && moduleInfo->metaData[i]->name == nullptr) ||
|
||||
(metaData[i]->value != nullptr && moduleInfo->metaData[i]->value == nullptr) ||
|
||||
(metaData[i]->extra != nullptr && moduleInfo->metaData[i]->extra == nullptr)) {
|
||||
ClearModuleInfoMetaData(moduleInfo->metaData, i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // OHOS
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 "bundle_manager.h"
|
||||
#include "bundlems_slite_client.h"
|
||||
#include "want.h"
|
||||
|
||||
extern "C" {
|
||||
bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback)
|
||||
{
|
||||
return OHOS::BundleMsClient::GetInstance().Install(hapPath, installParam, installerCallback);
|
||||
}
|
||||
|
||||
bool Uninstall(const char *bundleName, const InstallParam *installParam, InstallerCallback installerCallback)
|
||||
{
|
||||
return OHOS::BundleMsClient::GetInstance().Uninstall(bundleName, installParam, installerCallback);
|
||||
}
|
||||
|
||||
uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo)
|
||||
{
|
||||
return OHOS::BundleMsClient::GetInstance().QueryAbilityInfo(want, abilityInfo);
|
||||
}
|
||||
|
||||
uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo)
|
||||
{
|
||||
return OHOS::BundleMsClient::GetInstance().GetBundleInfo(bundleName, flags, bundleInfo);
|
||||
}
|
||||
|
||||
uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len)
|
||||
{
|
||||
return OHOS::BundleMsClient::GetInstance().GetBundleInfos(flags, bundleInfos, len);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 "bundle_manager_inner.h"
|
||||
|
||||
#include "bundlems_slite_client.h"
|
||||
|
||||
extern "C" {
|
||||
int GetInstallState(const char *bundleName)
|
||||
{
|
||||
return OHOS::BundleMsClient::GetInstance().GetInstallState(bundleName);
|
||||
}
|
||||
}
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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 "bundlems_slite_client.h"
|
||||
|
||||
#include "adapter.h"
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "bundle_mgr_service.h"
|
||||
#include "bundlems_log.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "ohos_mem_pool.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "unistd.h"
|
||||
#include "utils.h"
|
||||
#include "want_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
const unsigned int ERROR_SLEEP_TIMES = 300;
|
||||
const unsigned int RETRY_TIMES = 10;
|
||||
Bmsbuff *g_bmsbuff = nullptr;
|
||||
|
||||
bool BundleMsClient::Initialize() const
|
||||
{
|
||||
if (bmsProxy_ != nullptr) {
|
||||
return true;
|
||||
}
|
||||
int retry = RETRY_TIMES;
|
||||
while (retry--) {
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BMS_SERVICE, BMS_SLITE_FEATURE);
|
||||
if (iUnknown == nullptr) {
|
||||
osDelay(ERROR_SLEEP_TIMES); // sleep 300ms
|
||||
continue;
|
||||
}
|
||||
|
||||
(void)iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&bmsProxy_);
|
||||
if (bmsProxy_ == nullptr) {
|
||||
osDelay(ERROR_SLEEP_TIMES); // sleep 300ms
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BundleMsClient::Install(const char *hapPath, const InstallParam *installParam,
|
||||
InstallerCallback installerCallback) const
|
||||
{
|
||||
if (g_bmsbuff == nullptr) {
|
||||
g_bmsbuff = reinterpret_cast<Bmsbuff *>(OhosMalloc(MEM_TYPE_APPFMK_LSRAM, sizeof(Bmsbuff)));
|
||||
}
|
||||
BundleMgrService *service = BundleMgrService::GetInstance();
|
||||
if (service == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (hapPath == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memset_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, 0, MAX_PATH_LEN) != 0) {
|
||||
return false;
|
||||
}
|
||||
int len = strlen(hapPath);
|
||||
if (len >= MAX_PATH_LEN) {
|
||||
return false;
|
||||
}
|
||||
if (memcpy_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, hapPath, len + 1) != 0) {
|
||||
return false;
|
||||
}
|
||||
g_bmsbuff->bundleInstallerCallback = installerCallback;
|
||||
Request request = {
|
||||
.msgId = BMS_INSTALL_MSG,
|
||||
.data = nullptr,
|
||||
.len = 0,
|
||||
.msgValue = 0,
|
||||
};
|
||||
|
||||
int32_t ret = SAMGR_SendRequest(service->GetIdentity(), &request, nullptr);
|
||||
return ret == ERR_OK;
|
||||
}
|
||||
|
||||
bool BundleMsClient::Uninstall (const char *bundleName, const InstallParam *installParam,
|
||||
InstallerCallback installerCallback) const
|
||||
{
|
||||
BundleMgrService *service = BundleMgrService::GetInstance();
|
||||
if (service == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (bundleName == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (g_bmsbuff == nullptr) {
|
||||
g_bmsbuff = reinterpret_cast<Bmsbuff *>(OhosMalloc(MEM_TYPE_APPFMK_LSRAM, sizeof(Bmsbuff)));
|
||||
}
|
||||
if (memset_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, 0, MAX_PATH_LEN) != 0) {
|
||||
return false;
|
||||
}
|
||||
int len = strlen(bundleName);
|
||||
if (len >= MAX_PATH_LEN) {
|
||||
return false;
|
||||
}
|
||||
if (memcpy_s(g_bmsbuff->bundleParameter, MAX_PATH_LEN, bundleName, len + 1) != 0) {
|
||||
return false;
|
||||
}
|
||||
g_bmsbuff->bundleInstallerCallback = installerCallback;
|
||||
Request request = {
|
||||
.msgId = BMS_UNINSTALL_MSG,
|
||||
.data = nullptr,
|
||||
.len = 0,
|
||||
.msgValue = 0,
|
||||
};
|
||||
int32_t ret = SAMGR_SendRequest(service->GetIdentity(), &request, nullptr);
|
||||
return ret == ERR_OK;
|
||||
}
|
||||
|
||||
uint8_t BundleMsClient::QueryAbilityInfo (const Want *want, AbilityInfo *abilityInfo) const
|
||||
{
|
||||
if (!Initialize()) {
|
||||
return -1;
|
||||
}
|
||||
return bmsProxy_->QueryAbilityInfo(want, abilityInfo);
|
||||
}
|
||||
|
||||
uint8_t BundleMsClient::GetBundleInfo (const char *bundleName, int32_t flags, BundleInfo *bundleInfo) const
|
||||
{
|
||||
if (!Initialize()) {
|
||||
return -1;
|
||||
}
|
||||
return bmsProxy_->GetBundleInfo(bundleName, flags, bundleInfo);
|
||||
}
|
||||
|
||||
uint8_t BundleMsClient::GetBundleInfos (int32_t flags, BundleInfo **bundleInfos, int32_t *len) const
|
||||
{
|
||||
if (!Initialize()) {
|
||||
return -1;
|
||||
}
|
||||
return bmsProxy_->GetBundleInfos(flags, bundleInfos, len);
|
||||
}
|
||||
|
||||
int8_t BundleMsClient::GetInstallState (const char *bundleName) const
|
||||
{
|
||||
if (!Initialize()) {
|
||||
return -1;
|
||||
}
|
||||
return bmsProxy_->GetInstallState(bundleName);
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#include "token_generate.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
namespace OHOS {
|
||||
constexpr uint8_t TIME_LENGTH = 32;
|
||||
int32_t TokenGenerate::token_ = 0;
|
||||
|
||||
uint64_t TokenGenerate::GenerateToken()
|
||||
{
|
||||
int curSecond = time(nullptr);
|
||||
if (token_ == INT32_MAX - 1) {
|
||||
token_ = 0;
|
||||
}
|
||||
|
||||
return (((uint64_t) curSecond << TIME_LENGTH) + ((uint64_t) token_++));
|
||||
}
|
||||
} // namespace OHOS
|
||||
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
|
||||
`bundle_manager.h` is devoted to support some interface functions to other outside process. By using these functions, other modules in the system can obtain some application infomation, install and uninstall application.
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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_BUNDLE_DAEMON_INTERFACE_H
|
||||
#define OHOS_BUNDLE_DAEMON_INTERFACE_H
|
||||
|
||||
#include "iproxy_server.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
const char BDS_SERVICE[] = "bundle_daemon";
|
||||
|
||||
enum BmsCmd {
|
||||
EXTRACT_HAP = 0, // extract hap to code path
|
||||
RENAME_DIR, // rename code path or json path
|
||||
CREATE_PERMISSION_DIR, // create permission dir
|
||||
CREATE_DATA_DIRECTORY, // create data path
|
||||
STORE_CONTENT_TO_FILE, // store content to json path
|
||||
MOVE_FILE, // move file to target dictionary
|
||||
REMOVE_FILE, // delete json path
|
||||
REMOVE_INSTALL_DIRECTORY, // clear app data path and code path
|
||||
BDS_CMD_END,
|
||||
REGISTER_CALLBACK, // register bundle_daemon callback
|
||||
BDS_CALLBACK // callback message
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif /* OHOS_BUNDLE_DAEMON_INTERFACE_H */
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_BUNDLE_INNER_INTERFACE_H
|
||||
#define OHOS_BUNDLE_INNER_INTERFACE_H
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "bundle_info.h"
|
||||
#include "iproxy_server.h"
|
||||
#include "want.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
const char BMS_SERVICE[] = "bundlems";
|
||||
const char BMS_FEATURE[] = "BmsFeature";
|
||||
const char BMS_INNER_FEATURE[] = "BmsInnerFeature";
|
||||
|
||||
enum BmsCmd {
|
||||
QUERY_ABILITY_INFO = 0,
|
||||
GET_BUNDLE_INFO,
|
||||
CHANGE_CALLBACK_SERVICE_IDENTITY,
|
||||
GET_BUNDLENAME_FOR_UID,
|
||||
GET_BUNDLE_INFOS,
|
||||
QUERY_KEEPALIVE_BUNDLE_INFOS,
|
||||
GET_BUNDLE_INFOS_BY_METADATA,
|
||||
CHECK_SYS_CAP,
|
||||
GET_SYS_CAP,
|
||||
BMS_INNER_BEGIN,
|
||||
INSTALL = BMS_INNER_BEGIN, // bms install application
|
||||
UNINSTALL,
|
||||
#ifdef OHOS_DEBUG
|
||||
SET_EXTERNAL_INSTALL_MODE,
|
||||
SET_SIGN_DEBUG_MODE,
|
||||
SET_SIGN_MODE,
|
||||
#endif
|
||||
BMS_CMD_END
|
||||
};
|
||||
|
||||
struct BmsServerProxy {
|
||||
INHERIT_SERVER_IPROXY;
|
||||
uint8_t (*QueryAbilityInfo)(const Want *want, AbilityInfo *abilityInfo);
|
||||
uint8_t (*GetBundleInfo)(const char *bundleName, int32_t flags, BundleInfo *bundleInfo);
|
||||
uint8_t (*GetBundleInfos)(int flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
uint8_t (*QueryKeepAliveBundleInfos)(BundleInfo **bundleInfos, int32_t *len);
|
||||
uint8_t (*GetBundleNameForUid)(int32_t uid, char **bundleName);
|
||||
};
|
||||
|
||||
struct BmsInnerServerProxy {
|
||||
INHERIT_SERVER_IPROXY;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif /* OHOS_BUNDLE_INNER_INTERFACE_H */
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_BMS_INTERFACE_H
|
||||
#define OHOS_BMS_INTERFACE_H
|
||||
|
||||
#include "feature.h"
|
||||
#include "iproxy_server.h"
|
||||
#include "want.h"
|
||||
#include "install_param.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "bundle_info.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
const char BMS_SERVICE[] = "bundlems";
|
||||
const char BMS_FEATURE[] = "BmsFeature";
|
||||
const char BMS_SLITE_FEATURE[] = "BmsSliteFeature";
|
||||
const char BMS_INNER_FEATURE[] = "BmsInnerFeature";
|
||||
const unsigned int MAX_PATH_LEN = 256;
|
||||
|
||||
typedef struct {
|
||||
char bundleParameter[MAX_PATH_LEN];
|
||||
InstallParam *bundleInstallParam;
|
||||
InstallerCallback bundleInstallerCallback;
|
||||
} Bmsbuff;
|
||||
|
||||
struct BmsSliteInterface {
|
||||
INHERIT_IUNKNOWN;
|
||||
bool (*Install)(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback);
|
||||
bool (*Uninstall)(const char *bundleName, const InstallParam *installParam, InstallerCallback installerCallback);
|
||||
uint8_t (*QueryAbilityInfo)(const Want *want, AbilityInfo *abilityInfo);
|
||||
uint8_t (*GetBundleInfo)(const char *bundleName, int32_t flags, BundleInfo *bundleInfo);
|
||||
uint8_t (*GetBundleInfos)(int32_t flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
int8_t (*GetInstallState)(const char *bundleName);
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif // OHOS_BMS_INTERFACE_H
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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_BUNDLE_MANAGER_INNER_H
|
||||
#define OHOS_BUNDLE_MANAGER_INNER_H
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "slite_ability.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef enum {
|
||||
BMS_NOT_INSTALLED = -1,
|
||||
BMS_FIRST_FINISHED_PROCESS = 55,
|
||||
BMS_THIRD_FINISHED_PROCESS = 90,
|
||||
BMS_FOUR_FINISHED_PROCESS = 95,
|
||||
BMS_INSTALLATION_COMPLETED = 100
|
||||
} InstallStateLabel;
|
||||
|
||||
typedef struct {
|
||||
InstallStateLabel installStateLabel;
|
||||
char *bundleName;
|
||||
} InstallationProgress;
|
||||
|
||||
/**
|
||||
* @brief Get the install state of the bundle.
|
||||
*
|
||||
* @param bundleName Indicates the name of the bundle.
|
||||
* @return Returns the install state of the bundle.
|
||||
*
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
int GetInstallState(const char *bundleName);
|
||||
|
||||
/**
|
||||
* @brief Install a simulated bundle for the native ability .
|
||||
*
|
||||
* @param abilityInfo Indicates the info of the ability.
|
||||
* @param ability Indicates the object of the ability.
|
||||
* @return Returns the install result.
|
||||
*
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
int InstallNativeAbility(const AbilityInfo *abilityInfo, const OHOS::SliteAbility *ability);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif /* OHOS_BUNDLE_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,18 @@
|
||||
## Introduction
|
||||
|
||||
- `AbilityInfo` ability information such as bundleName, srcPath(file path of one application), iconPath, isVisible etc..
|
||||
- `AppexecfwkErrors` an emum including some error codes occurred when functions of `Bundle manager service` (BMS) return corresponding errors.
|
||||
- `ElementName` who encapsulates bundleName, deviceId and abilityName of one application to query ability information.
|
||||
- `BundleInfo` application information, including, versionName, smallIconPath, bigIconPath, iconPath, versionCode etc..
|
||||
- `ModuleInfo` encapsulating moduleName, description, name, moduleType, isDeliveryInstall, deviceType and metaData.
|
||||
## Directions
|
||||
|
||||
```
|
||||
.
|
||||
├── ability_info.h
|
||||
├── appexecfwk_errors.h
|
||||
├── bundle_info.h
|
||||
├── element_name.h
|
||||
├── module_info.h
|
||||
└── README.md
|
||||
```
|
||||
Executable
+168
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* 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 BundleManager
|
||||
* @{
|
||||
*
|
||||
* @brief Provides structures and functions for managing application bundles and obtaining application information.
|
||||
*
|
||||
* You can use functions provided by this module to install, update, or uninstall an application, obtain
|
||||
* {@link AbilityInfo} and {@link BundleInfo} about an application, and obtain the bundle name of an application based
|
||||
* on the application's user ID (UID).
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ability_info.h
|
||||
*
|
||||
* @brief Declares structures and functions for managing ability information.
|
||||
*
|
||||
* You can use the function provided in this file to clear ability information.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_INFO_H
|
||||
#define OHOS_ABILITY_INFO_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "stdint.h"
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
/**
|
||||
* @brief Defines the maximun length of the system capabiliy name.
|
||||
*/
|
||||
#define MAX_SYSCAP_NAME_LEN 64
|
||||
|
||||
/**
|
||||
* @brief Defines the maximun num of system capabilities.
|
||||
*/
|
||||
#define MAX_SYSCAP_NUM 512
|
||||
|
||||
/**
|
||||
* @brief Enumerates types of templates used by an ability.
|
||||
*/
|
||||
typedef enum {
|
||||
/** Unknown */
|
||||
UNKNOWN = 0,
|
||||
|
||||
/** Page */
|
||||
PAGE,
|
||||
|
||||
/** Service */
|
||||
SERVICE
|
||||
} AbilityType;
|
||||
|
||||
/**
|
||||
* @brief Enumerates startup modes of an ability.
|
||||
*/
|
||||
typedef enum {
|
||||
/** Singleton mode, allowing only one instance */
|
||||
SINGLETON = 0,
|
||||
|
||||
/** Standard mode, allowing multiple instances */
|
||||
STANDARD
|
||||
} LaunchMode;
|
||||
|
||||
/**
|
||||
* @brief Defines the system capability name.
|
||||
*/
|
||||
typedef struct {
|
||||
char name[MAX_SYSCAP_NAME_LEN];
|
||||
} SystemCapName;
|
||||
|
||||
/**
|
||||
* @brief Defines the system capability information.
|
||||
*/
|
||||
typedef struct {
|
||||
int32_t systemCapNum;
|
||||
SystemCapName *systemCapName;
|
||||
} SystemCapability;
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Defines the ability information.
|
||||
*/
|
||||
typedef struct {
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
/** Whether the ability is visible */
|
||||
bool isVisible;
|
||||
|
||||
/** Template used by the ability */
|
||||
AbilityType abilityType;
|
||||
|
||||
/** Startup mode of the ability */
|
||||
LaunchMode launchMode;
|
||||
|
||||
/**
|
||||
* Pointer to the name of the HAP package to which the ability belongs. The HAP information is encapsulated in a
|
||||
* {@link ModuleInfo} object.
|
||||
*/
|
||||
char *moduleName;
|
||||
|
||||
/** Pointer to the class name of the ability */
|
||||
char *name;
|
||||
|
||||
/** Pointer to the description of the ability */
|
||||
char *description;
|
||||
|
||||
/** Pointer to the icon path of the ability */
|
||||
char *iconPath;
|
||||
|
||||
/** Pointer to the device ID */
|
||||
char *deviceId;
|
||||
|
||||
/** Pointer to the ability name visible to users */
|
||||
char *label;
|
||||
|
||||
/** Pointer to the deviceCapability */
|
||||
SystemCapability deviceCap;
|
||||
#else
|
||||
/** Pointer to the source code path. This field is available only to basic watches. */
|
||||
char *srcPath;
|
||||
#endif
|
||||
/** Pointer to the application bundle name */
|
||||
char *bundleName;
|
||||
} AbilityInfo;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
/**
|
||||
* @brief Clears an {@link AbilityInfo} object.
|
||||
*
|
||||
* This function clears and releases the memory occupied by the fields of the pointer type included in the specified
|
||||
* {@link AbilityInfo} object.
|
||||
* @param abilityInfo Indicates the pointer to the {@link AbilityInfo} object to clear.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void ClearAbilityInfo(AbilityInfo *abilityInfo);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // OHOS_ABILITY_INFO_H
|
||||
/** @} */
|
||||
+364
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
* 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 BundleManager
|
||||
* @{
|
||||
*
|
||||
* @brief Provides structures and functions for managing application bundles and obtaining application information.
|
||||
*
|
||||
* You can use functions provided by this module to install, update, or uninstall an application, obtain
|
||||
* {@link AbilityInfo} and {@link BundleInfo} about an application, and obtain the bundle name of an application
|
||||
* based on the application's user ID (UID).
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file appexecfwk_errors.h
|
||||
*
|
||||
* @brief Declares error codes returned by bundle management functions.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OHOS_APPEXECFWK_ERRORS_H
|
||||
#define OHOS_APPEXECFWK_ERRORS_H
|
||||
|
||||
/**
|
||||
* @brief Enumerates error codes provided by the Bundle Manager Service.
|
||||
*/
|
||||
enum AppexecfwkErrors {
|
||||
/** The function is successfully called. */
|
||||
ERR_OK = 0,
|
||||
|
||||
/** Incorrect parameter for querying {@link AbilityInfo} or {@link BundleInfo}. */
|
||||
ERR_APPEXECFWK_QUERY_PARAMETER_ERROR,
|
||||
|
||||
/** No {@link AbilityInfo} or {@link BundleInfo} is found. */
|
||||
ERR_APPEXECFWK_QUERY_NO_INFOS,
|
||||
|
||||
/** An error occurred when initializing {@link BundleInfo} or {@link AbilityInfo} during information query. */
|
||||
ERR_APPEXECFWK_QUERY_INFOS_INIT_ERROR,
|
||||
|
||||
/** The object or pointer is null. */
|
||||
ERR_APPEXECFWK_OBJECT_NULL,
|
||||
|
||||
/** Failed to install the application due to an internal logic error. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_ERROR = 10,
|
||||
|
||||
/** Failed to install the application due to incorrect parameters. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARAM_ERROR,
|
||||
|
||||
/** Failed to install the application because the installation file path is invalid. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_FILE_PATH_INVALID,
|
||||
|
||||
/** Failed to install the application because the installation file does not exist. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_FILE_NOT_EXISTS,
|
||||
|
||||
/** Failed to install the application because the installation file name is invalid. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_INVALID_FILE_NAME,
|
||||
|
||||
/** Failed to install the application due to incorrect file content. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_BAD_FILE,
|
||||
|
||||
/** Failed to install the application due to a file creation error. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_CREATE_FILE_ERROR,
|
||||
|
||||
/** Failed to install the application because an error occurred when creating the permission file directory. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_CREATE_PERMISSIONS_DIR_ERROR,
|
||||
|
||||
/** Failed to install the application due to a path renaming error. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_RENAME_DIR_ERROR,
|
||||
/** Failed to install the application due to a file renaming error. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_RENAME_FILE_ERROR,
|
||||
|
||||
/** Failed to install the application due to an error occurred when creating the data path. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_CREATE_DATA_DIR_ERROR,
|
||||
|
||||
/** Failed to install the application due to an error occurred when recording installation information. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_RECORD_INFO_ERROR,
|
||||
|
||||
/** Failed to install the application due to an error occurred when backing up the UID and GID. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_UID_AND_GID_BACKUP_ERROR,
|
||||
|
||||
/** Failed to install the application because an application of a later version has been installed. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_VERSION_DOWNGRADE,
|
||||
|
||||
/**
|
||||
* Failed to install the application because the number of installed applications exceeds the maximum (30). This
|
||||
* error code is available only to basic watches.
|
||||
*/
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_BUNDLE_NUMBER,
|
||||
|
||||
/** Failed to install the application due to an error occurred when storing permission information. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_STORE_PERMISSIONS_ERROR,
|
||||
|
||||
/**
|
||||
* Failed to install the application due to invalid file data. This error code is available only to basic
|
||||
* watches.
|
||||
*/
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_FILE_DATA_INVALID,
|
||||
|
||||
/** Failed to install the application due to unmatched signature used for version update. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_INCOMPATIBLE_SIGNATURE,
|
||||
|
||||
/** Failed to install the application due to unmatched provisioning information during signature verification. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_INVALID_PROVISIONINFO,
|
||||
|
||||
/** Failed to install the application due to an error occurred when processing the signature file. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_OPERATE_SIGNED_FILE_ERROR,
|
||||
|
||||
/** Failed to install the application due to an error occurred when parsing the application signature. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_APP_SIGNATURE_ERROR,
|
||||
|
||||
/** Failed to install the application due to an error occurred when parsing the file signature. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_SIGNATURE_ERROR,
|
||||
|
||||
/** Failed to install the application due to an internal error during signature verification. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_INTERNAL_SIGNATURE_ERROR,
|
||||
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_GET_JS_ENGINE_VERSION_ERROR,
|
||||
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_TRANSFORM_BC_FILE_ERROR,
|
||||
|
||||
/** Failed to install the application due to an error occurred when setting the signature verification mode. */
|
||||
ERR_APPEXECFWK_SET_DEBUG_MODE_ERROR,
|
||||
|
||||
/** Failed to parse the file. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_ERROR = 40,
|
||||
|
||||
/** Failed to parse the bundle name. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_BUNDLENAME_ERROR,
|
||||
|
||||
/** Invalid bundle name. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_INVALID_BUNDLENAME,
|
||||
|
||||
/** Failed to parse the vendor information. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_VENDOR_ERROR,
|
||||
|
||||
/** Failed to parse the version code. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_VERSIONCODE_ERROR,
|
||||
|
||||
/** Failed to parse the version name. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_VERSIONNAME_ERROR,
|
||||
|
||||
/** Failed to parse the installation permission information. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PERMISSIONS_ERROR,
|
||||
|
||||
/** Failed to parse the API version. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_API_VERSION_ERROR,
|
||||
|
||||
/** Failed to parse the device configuration. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DEVICE_CONFIG_ERROR,
|
||||
|
||||
/** Failed to parse the <b>isKeepAlive</b> field of the application. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_KEEPALIVE_ERROR,
|
||||
|
||||
/**
|
||||
* Failed to parse the <b>name</b> field of the application's HAP package. The HAP information is encapsulated in
|
||||
* a {@link ModuleInfo} object.
|
||||
*/
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_MODULENAME_ERROR,
|
||||
|
||||
/** Invalid HAP name. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_INVALID_MODULENAME,
|
||||
|
||||
/** Failed to parse the HAP description information. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_MODULE_DESCRIPTION_ERROR,
|
||||
|
||||
/** Failed to parse the <b>deviceType</b> field of the application's HAP package. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DEVICETYPE_ERROR,
|
||||
|
||||
/** Failed to parse the <b>deviceCapability</b> field of the application's HAP package. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DEVICECAP_ERROR,
|
||||
|
||||
/** Failed to parse the HAP information. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_ERROR,
|
||||
|
||||
/** Failed to parse the <b>moduleName</b> field of the application's HAP package. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_MODULENAME_ERROR,
|
||||
|
||||
/** Invalid HAP type. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_MODULETYPE_ERROR,
|
||||
|
||||
/** Failed to parse the <b>isDeliveryInstall</b> field of the application's HAP package. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DISTRO_DELIVERY_ERROR,
|
||||
|
||||
/** Failed to parse the {@link MetaData} information. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_METADATA_ERROR,
|
||||
|
||||
/** Failed to parse the {@link AbilityInfo}. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITIES_ERROR,
|
||||
|
||||
/** Failed to parse the class name of the ability. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_NAME_ERROR,
|
||||
|
||||
/** Failed to parse the template used by the ability. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_TYPE_ERROR,
|
||||
|
||||
/** Failed to parse the icon path of the ability. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_ICONPATH_ERROR,
|
||||
|
||||
/** Failed to parse the label of the ability. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_LABEL_ERROR,
|
||||
|
||||
/** Failed to parse the description of the ability. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_DESCRIPTION_ERROR,
|
||||
|
||||
/** Failed to parse the startup mode of the ability. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_LAUNCHTYPE_ERROR,
|
||||
|
||||
/** Failed to parse the <b>isVisible</b> field of the ability. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ABILITY_VISIBLE_ERROR,
|
||||
|
||||
/** Invalid length of the bundle name. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_INVALID_BUNDLENAME_LENGTH,
|
||||
|
||||
/** The parsed application label exceeds the maximum length (255 bytes). */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_LABEL_LENGTH_ERROR,
|
||||
|
||||
/** The parsed application version name exceeds the maximum length (127 bytes). */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_VERSIONNAME_LENGTH_ERROR,
|
||||
|
||||
/** The parsed application metadata name exceeds the maximum length (255 bytes). */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_METADATA_NAME_LENGTH_ERROR,
|
||||
|
||||
/** The parsed application metadata value exceeds the maximum length (255 bytes). */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_METADATA_VALUE_LENGTH_ERROR,
|
||||
|
||||
/** The parsed application vendor name exceeds the maximum length (255 bytes). */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_VENDOR_LENGTH_ERROR,
|
||||
|
||||
/** The parsed HAP name exceeds the maximum length (31 bytes). */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_MODULENAME_LENGTH_ERROR,
|
||||
|
||||
/** The parsed ability class name exceeds the maximum length (127 bytes). */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_ABILITYNAME_LENGTH_ERROR,
|
||||
|
||||
/** The parsed ability description exceeds the maximum length (255 bytes). */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_ABILITY_DESCRIPTION_LENGTH_ERROR,
|
||||
|
||||
/** The parsed ability label exceeds the maximum length (255 bytes). */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXCEED_MAX_ABILITY_LABEL_LENGTH_ERROR,
|
||||
|
||||
/** Failed to initialize the extractor. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXTRACTOR_NOT_INIT,
|
||||
|
||||
/** Failed to extract information from the HAP package. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_EXTRACT_HAP_ERROR,
|
||||
|
||||
/** Failed to parse the JavaScript path. This error code is available only to basic watches. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_JS_DIR_ERROR,
|
||||
|
||||
/** The resource index does not exist. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_RESOURCE_INDEX_NOT_EXISTS,
|
||||
|
||||
/** Failed to parse the label resource. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_LABEL_RES_ERROR,
|
||||
|
||||
/** Failed to parse the icon resource. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_ICON_RES_ERROR,
|
||||
|
||||
/** Failed to parse the description resource. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_PARSE_DESCRIPTION_RES_ERROR,
|
||||
|
||||
/** Failed to install the application due to a request sending error. */
|
||||
ERR_APPEXECFWK_INSTALL_FAILED_SEND_REQUEST_ERROR,
|
||||
|
||||
/** Failed to uninstall the application due to an internal error. */
|
||||
ERR_APPEXECFWK_UNINSTALL_FAILED_INTERNAL_ERROR = 90,
|
||||
|
||||
/** Failed to uninstall the application due to incorrect input parameters. */
|
||||
ERR_APPEXECFWK_UNINSTALL_FAILED_PARAM_ERROR,
|
||||
|
||||
/** Failed to uninstall the application because it does not exist. */
|
||||
ERR_APPEXECFWK_UNINSTALL_FAILED_BUNDLE_NOT_EXISTS,
|
||||
|
||||
/** Failed to uninstall the application due to an error occurred when deleting the path. */
|
||||
ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_DIRS_ERROR,
|
||||
|
||||
/** Failed to uninstall the application due to an error occurred when deleting the installation record. */
|
||||
ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_RECORD_INFO_ERROR,
|
||||
|
||||
/** Failed to uninstall the application due to an error occurred when deleting the permission information. */
|
||||
ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_PERMISSIONS_ERROR,
|
||||
|
||||
/** Failed to uninstall the application because the application cannot be uninstalled. */
|
||||
ERR_APPEXECFWK_UNINSTALL_FAILED_BUNDLE_NOT_UNINSTALLABLE,
|
||||
|
||||
/** Failed to uninstall the application due to an error occurred when deleting the UID information. */
|
||||
ERR_APPEXECFWK_UNINSTALL_FAILED_DELETE_UID_INFO_ERROR,
|
||||
|
||||
/** Failed to uninstall the application due to a request sending error. */
|
||||
ERR_APPEXECFWK_UNINSTALL_FAILED_SEND_REQUEST_ERROR,
|
||||
|
||||
/** Incorrect dump information. */
|
||||
ERR_APPEXECFWK_DUMP_ERROR = 100,
|
||||
|
||||
/** Incorrect command. */
|
||||
ERR_APPEXECFWK_COMMAND_ERROR,
|
||||
|
||||
/** Failed to register the callback. */
|
||||
ERR_APPEXECFWK_CALLBACK_REGISTER_FAILED,
|
||||
|
||||
/** Failed to unregister the callback. */
|
||||
ERR_APPEXECFWK_CALLBACK_UNREGISTER_FAILED,
|
||||
|
||||
/** Failed to generate a service ID for the current process. */
|
||||
ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED,
|
||||
|
||||
/** Failed to transmit the service ID of the current process. */
|
||||
ERR_APPEXECFWK_CALLBACK_SERVICEID_TRANSMITTED_FAILED,
|
||||
|
||||
/** The callback is never registered. */
|
||||
ERR_APPEXECFWK_CALLBACK_NEVER_REGISTERED,
|
||||
|
||||
/** Failed to obtain the bundle names of all applications in the system. */
|
||||
ERR_APPEXECFWK_CALLBACK_OBTAIN_ALL_BUNDLE_FAILED,
|
||||
|
||||
/** The required callback is unavailable. */
|
||||
ERR_APPEXECFWK_CALLBACK_NULL_CORRESPONDING_CALLBACK,
|
||||
|
||||
/** Failed to obtain the installation type (installation or uninstallation). */
|
||||
ERR_APPEXECFWK_CALLBACK_GET_INSTALLTYPE_FAILED,
|
||||
|
||||
/** Incorrect installation type. */
|
||||
ERR_APPEXECFWK_CALLBACK_GET_ERROR_INSTALLTYPE,
|
||||
|
||||
/** Serialization failed. */
|
||||
ERR_APPEXECFWK_SERIALIZATION_FAILED,
|
||||
|
||||
/** Deserialization failed. */
|
||||
ERR_APPEXECFWK_DESERIALIZATION_FAILED,
|
||||
|
||||
/** Internal system error. */
|
||||
ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR,
|
||||
|
||||
/** No bundle name associated with the UID is found. */
|
||||
ERR_APPEXECFWK_NO_BUNDLENAME_FOR_UID,
|
||||
|
||||
/** The {@link IpcIo} structure is unavailable. */
|
||||
ERR_APPEXECFWK_IPCIO_UNAVAILABLED,
|
||||
|
||||
/** An error occurred when calling the <b>invoke</b> function of the Bundle Manager Service. */
|
||||
ERR_APPEXECFWK_INVOKE_ERROR,
|
||||
|
||||
/** The server that invokes the Bundle Manager Service does not have required permission. */
|
||||
ERR_APPEXECFWK_PERMISSION_DENIED,
|
||||
};
|
||||
#endif // OHOS_APPEXECFWK_ERRORS_H
|
||||
/** @} */
|
||||
Executable
+166
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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 BundleManager
|
||||
* @{
|
||||
*
|
||||
* @brief Provides structures and functions for managing application bundles and obtaining application information.
|
||||
*
|
||||
* You can use functions provided by this module to install, update, or uninstall an application, obtain
|
||||
* {@link AbilityInfo} and {@link BundleInfo} about an application, and obtain the bundle name of an application based
|
||||
* on the application's user ID (UID).
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bundle_info.h
|
||||
*
|
||||
* @brief Declares structures and functions for managing application bundle information.
|
||||
*
|
||||
* You can use the function provided in this file to clear bundle information.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OHOS_BUNDLE_INFO_H
|
||||
#define OHOS_BUNDLE_INFO_H
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "module_info.h"
|
||||
#include "stdint.h"
|
||||
|
||||
/**
|
||||
* @brief Defines the bundle information.
|
||||
*/
|
||||
typedef struct {
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
/** Whether the application is kept alive */
|
||||
bool isKeepAlive;
|
||||
|
||||
/**
|
||||
* Whether the application is a local application. A local application refers to an application developed using
|
||||
* C++ in the system. The value <b>true</b> indicates a local application, and <b>false</b> indicates a non-local
|
||||
* application.
|
||||
*/
|
||||
bool isNativeApp;
|
||||
|
||||
/** UID allocated during application installation */
|
||||
int32_t uid;
|
||||
|
||||
/** Application group ID allocated during application installation */
|
||||
int32_t gid;
|
||||
#endif
|
||||
/**
|
||||
* Whether the application is a system application. System applications cannot be uninstalled. The value
|
||||
* <b>true</b> indicates a system application, and <b>false</b> indicates a non-system application.
|
||||
*/
|
||||
bool isSystemApp;
|
||||
|
||||
/** Minimum API version required */
|
||||
int32_t compatibleApi;
|
||||
|
||||
/** Target API version */
|
||||
int32_t targetApi;
|
||||
|
||||
/** Version code of the application, which is the internal version number */
|
||||
int32_t versionCode;
|
||||
|
||||
/** Pointer to the version name visible to users */
|
||||
char *versionName;
|
||||
|
||||
/** Pointer to the bundle name of the application */
|
||||
char *bundleName;
|
||||
|
||||
/** Pointer to the application name visible to users */
|
||||
char *label;
|
||||
|
||||
/** Pointer to the big icon of the application */
|
||||
char *bigIconPath;
|
||||
|
||||
/**
|
||||
* Pointer to the installation path of the application, which is in the <b>/app/run/<i>bundle name</i></b>
|
||||
* format
|
||||
*/
|
||||
char *codePath;
|
||||
|
||||
/** Pointer to the path for storing data files of the application. The data path is <b>/app/data</b>. */
|
||||
char *dataPath;
|
||||
|
||||
/** Pointer to the vendor name of the application */
|
||||
char *vendor;
|
||||
|
||||
/**
|
||||
* Pointer to the HAP package information about the application. The HAP information is encapsulated in
|
||||
* {@link ModuleInfo} objects.
|
||||
*/
|
||||
ModuleInfo *moduleInfos;
|
||||
|
||||
/** Number of {@link ModuleInfo} objects included in the application */
|
||||
int32_t numOfModule;
|
||||
|
||||
/**
|
||||
* Application ID, which uniquely identifies an application. It is a combination of the bundle name and
|
||||
* signature of the application.
|
||||
*/
|
||||
char *appId;
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
/**
|
||||
* Pointer to the ability information about the application. The ability information is encapsulated in
|
||||
* {@link AbilityInfo} objects.
|
||||
*/
|
||||
AbilityInfo *abilityInfos;
|
||||
|
||||
/** Number of {@link AbilityInfo} objects in the application */
|
||||
int32_t numOfAbility;
|
||||
#else
|
||||
/**
|
||||
* Pointer to the path for storing the small icon of the application. This field is available only to basic
|
||||
* watches.
|
||||
*/
|
||||
char *smallIconPath;
|
||||
|
||||
/** Pointer to the ability information about the application. This field is available only to basic watches. */
|
||||
AbilityInfo *abilityInfo;
|
||||
#endif
|
||||
} BundleInfo;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
/**
|
||||
* @brief Clears a {@link BundleInfo} object.
|
||||
*
|
||||
* This function clears and releases the memory occupied by the fields of the pointer type included in the specified
|
||||
* {@link BundleInfo} object.
|
||||
* @param bundleInfo Indicates the pointer to the {@link BundleInfo} object to clear.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void ClearBundleInfo(BundleInfo *bundleInfo);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // OHOS_BUNDLE_INFO_H
|
||||
/** @} */
|
||||
Executable
+255
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* 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 BundleManager
|
||||
* @{
|
||||
*
|
||||
* @brief Provides structures and functions for managing application bundles and obtaining application information.
|
||||
*
|
||||
* You can use functions provided by this module to install, update, or uninstall an application, obtain
|
||||
* {@link AbilityInfo} and {@link BundleInfo} about an application, and obtain the bundle name of an application
|
||||
* based on the application's user ID (UID).
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bundle_manager.h
|
||||
*
|
||||
* @brief Declares functions used for managing application bundles and obtaining bundle information.
|
||||
*
|
||||
* You can use functions provided in this file to install, update, or uninstall an application, obtain
|
||||
* {@link AbilityInfo} and {@link BundleInfo} about an application, obtain the bundle name of an application based
|
||||
* on the application's user ID (UID), and obtain {@link BundleInfo} objects of all applications or keep-alive
|
||||
* applications in the system.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OHOS_BUNDLEMANAGER_INTERFACE_H
|
||||
#define OHOS_BUNDLEMANAGER_INTERFACE_H
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "bundle_info.h"
|
||||
#include "bundle_status_callback.h"
|
||||
#include "install_param.h"
|
||||
#include "stdint.h"
|
||||
#include "want.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Called when an application is installed, updated, or uninstalled.
|
||||
*
|
||||
* This function can be registered through {@link Install} and {@link Uninstall} to receive the installation, update,
|
||||
* and uninstallation result.
|
||||
*
|
||||
* @param resultCode Indicates the status code returned for the application installation, update, or uninstallation
|
||||
* result. For details, see {@link AppexecfwkErrors}.
|
||||
* @param resultMessage Indicates the result message returned with the status code.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef void (*InstallerCallback)(const uint8_t resultCode, const void *resultMessage);
|
||||
|
||||
/**
|
||||
* @brief Registers a callback to monitor the installation, update, and uninstallation state changes of an application.
|
||||
*
|
||||
* @param BundleStatusCallback Indicates the pointer to the callback to be invoked when the installation, update, or
|
||||
* uninstallation state of the monitored application changes.
|
||||
* @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in
|
||||
* {@link AppexecfwkErrors} otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t RegisterCallback(BundleStatusCallback *BundleStatusCallback);
|
||||
|
||||
/**
|
||||
* @brief Unregisters a callback previously registered for monitoring the installation, update, and uninstallation stat
|
||||
* changes of an application.
|
||||
*
|
||||
* @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in
|
||||
* {@link AppexecfwkErrors} otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t UnregisterCallback();
|
||||
|
||||
/**
|
||||
* @brief Installs or updates an application.
|
||||
*
|
||||
*
|
||||
* @param hapPath Indicates the pointer to the path for storing the OpenHarmony Ability Package (HAP) of the application
|
||||
* to install or update.
|
||||
* @param installParam Indicates the pointer to the parameters used for application installation or update.
|
||||
* @param installerCallback Indicates the callback to be invoked for notifying the installation or update result.
|
||||
* @return Returns <b>true</b> if this function is successfully called; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback);
|
||||
|
||||
/**
|
||||
* @brief Uninstalls an application.
|
||||
*
|
||||
* @param bundleName Indicates the pointer to the bundle name of the application to uninstall.
|
||||
* @param installParam Indicates the pointer to the parameters used for application uninstallation.
|
||||
* @param installerCallback Indicates the callback to be invoked for notifying the uninstallation result.
|
||||
* @return Returns <b>true</b> if this function is successfully called; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool Uninstall(const char *bundleName, const InstallParam *installParam, InstallerCallback installerCallback);
|
||||
|
||||
/**
|
||||
* @brief Queries the {@link AbilityInfo} of an ability based on the information carried in the {@link Want}
|
||||
* structure.
|
||||
* @attention Before querying an {@link AbilityInfo} object, you should first call <b>memset</b> on the
|
||||
* constructed {@link AbilityInfo} object so that each field in it can be properly initialized
|
||||
* for carrying the obtained information.
|
||||
* @param want Indicates the pointer to the {@link Want} structure used for querying the specified ability.
|
||||
* @param abilityInfo Indicates the pointer to the obtained {@link AbilityInfo} object.
|
||||
*
|
||||
* @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in
|
||||
* {@link AppexecfwkErrors} otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo);
|
||||
|
||||
/**
|
||||
* @brief Obtains the {@link BundleInfo} of an application based on the specified bundle name.
|
||||
*
|
||||
* @attention Before querying a {@link BundleInfo} object, you should first call <b>memset</b> on the constructed
|
||||
* {@link BundleInfo} object so that each field in it can be properly initialized for carrying the
|
||||
* obtained information.
|
||||
* @param bundleName Indicates the pointer to the name of the application bundle to query.
|
||||
* @param flags Specifies whether the obtained {@link BundleInfo} object can contain {@link AbilityInfo}. The value
|
||||
* <b>1</b> indicates that it can contain {@link AbilityInfo}, and <b>0</b> indicates that it cannot.
|
||||
* @param bundleInfo Indicates the pointer to the obtained {@link BundleInfo} object.
|
||||
*
|
||||
* @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in
|
||||
* {@link AppexecfwkErrors} otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo);
|
||||
|
||||
/**
|
||||
* @brief Obtains the {@link BundleInfo} of all bundles in the system.
|
||||
*
|
||||
* @param flags Specifies whether each of the obtained {@link BundleInfo} objects can contain {@link AbilityInfo}.
|
||||
* The value <b>1</b> indicates that it can contain {@link AbilityInfo}, and <b>0</b> indicates that
|
||||
* it cannot.
|
||||
* @param bundleInfos Indicates the double pointer to the obtained {@link BundleInfo} objects.
|
||||
* @param len Indicates the pointer to the number of {@link BundleInfo} objects obtained.
|
||||
* @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in
|
||||
* {@link AppexecfwkErrors} otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
|
||||
/**
|
||||
* @brief Obtains the {@link BundleInfo} of all keep-alive applications in the system.
|
||||
*
|
||||
* @param bundleInfos Indicates the double pointer to the obtained {@link BundleInfo} objects.
|
||||
* @param len Indicates the pointer to the number of {@link BundleInfo} objects obtained.
|
||||
* @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in
|
||||
* {@link AppexecfwkErrors} otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint8_t QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len);
|
||||
|
||||
/**
|
||||
* @brief Obtains the {@link BundleInfo} of application bundles based on the specified {@link MetaData}.
|
||||
*
|
||||
* @param metaDataKey Indicates the pointer to the metadata name in the {@link MetaData}.
|
||||
* @param bundleInfos Indicates the double pointer to the obtained {@link BundleInfo} objects.
|
||||
* @param len Indicates the pointer to the number of {@link BundleInfo} objects obtained.
|
||||
* @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in
|
||||
* {@link AppexecfwkErrors} otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint8_t GetBundleInfosByMetaData(const char *metaDataKey, BundleInfo **bundleInfos, int32_t *len);
|
||||
|
||||
/**
|
||||
* @brief Obtains the bundle name of an application based on the specified UID.
|
||||
*
|
||||
* @param uid Indicates the UID of the application to query.
|
||||
* @param bundleName Indicates the double pointer to the bundle name of the application.
|
||||
* @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in
|
||||
* {@link AppexecfwkErrors} otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint8_t GetBundleNameForUid(int32_t uid, char **bundleName);
|
||||
|
||||
/**
|
||||
* @brief Check if the specify syscap name is supported by the system.
|
||||
*
|
||||
* @param sysCapName Indicates the syscap name to check.
|
||||
* @return Returns <b>true</b> if syscap name is supported; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 4
|
||||
* @version 4
|
||||
*/
|
||||
bool HasSystemCapability(const char *sysCapName);
|
||||
|
||||
/**
|
||||
* @brief Obtains all the system available syscap name.
|
||||
*
|
||||
* @return Returns SystemCapability pointer if this function is successfully called; returns nullptr otherwise.
|
||||
*
|
||||
* @since 4
|
||||
* @version 4
|
||||
*/
|
||||
SystemCapability *GetSystemAvailableCapabilities();
|
||||
|
||||
/**
|
||||
* @brief Free the system available syscap memory
|
||||
*
|
||||
* @param sysCaps Indicates the pointer to the obtained {@link SystemCapability} objects.
|
||||
*
|
||||
* @since 4
|
||||
* @version 4
|
||||
*/
|
||||
void FreeSystemAvailableCapabilitiesInfo(SystemCapability *sysCap);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif /* OHOS_BUNDLEMANAGER_INTERFACE_H */
|
||||
/** @} */
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 BundleManager
|
||||
* @{
|
||||
*
|
||||
* @brief Provides structures and functions for managing application bundles and obtaining application information.
|
||||
*
|
||||
* You can use functions provided by this module to install, update, or uninstall an application, obtain
|
||||
* {@link AbilityInfo} and {@link BundleInfo} about an application, and obtain the bundle name of an application
|
||||
* based on the application's user ID (UID).
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bundle_status_callback.h
|
||||
*
|
||||
* @brief Declares the callback invoked upon state changes of an application and the structure defining the callback
|
||||
* information.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OHOS_BUNDLE_STATUS_CALLBACK_H
|
||||
#define OHOS_BUNDLE_STATUS_CALLBACK_H
|
||||
|
||||
/**
|
||||
* @brief Called when the installation, update, or uninstallation state of an application changes.
|
||||
*
|
||||
* This callback is used to listen for state change results of applications in the system.
|
||||
* @param installType Indicates the installation, update, or uninstallation state. The value <b>0</b> indicates that
|
||||
* the application is being installed or updated, and <b>1</b> indicates that the application is
|
||||
* being uninstalled.
|
||||
* @param resultCode Indicates the status code returned for the application installation, update, or uninstallation
|
||||
* result. For details, see {@link AppexecfwkErrors}.
|
||||
* @param resultMessage Indicates the pointer to the result message returned with the status code.
|
||||
* @param bundleName Indicates the pointer to the name of the bundle whose state has changed.
|
||||
* @param data Indicates the pointer to the data that will be used by the callback upon a state change. The data is
|
||||
* passed through {@link BundleStatusCallback} during callback registration.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef void (*BundleStateCallback)(const uint8_t installType, const uint8_t resultCode, const void *resultMessage,
|
||||
const char *bundleName, void *data);
|
||||
|
||||
/**
|
||||
* @brief Defines the application state callback information.
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* Pointer to the bundle name of the application that the callback listens to. If this parameter is set to
|
||||
* <b>nullptr</b>, the callback listens to all applications in the system.
|
||||
*/
|
||||
char *bundleName;
|
||||
|
||||
/**
|
||||
* Pointer to the registered data that will be used by {@link BundleStateCallback}.
|
||||
*/
|
||||
void *data;
|
||||
|
||||
/**
|
||||
* Callback to be invoked upon application state changes.
|
||||
*/
|
||||
BundleStateCallback callBack;
|
||||
} BundleStatusCallback;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
/**
|
||||
* @brief Clears and releases the memory occupied by the {@link BundleStatusCallback} structure.
|
||||
*
|
||||
*
|
||||
* @param bundleStatusCallback Indicates the pointer to the {@link BundleStatusCallback} structure to clear.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void ClearBundleStatusCallback(BundleStatusCallback *bundleStatusCallback);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
#endif // OHOS_BUNDLE_STATUS_CALLBACK_H
|
||||
/** @} */
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 BundleManager
|
||||
* @{
|
||||
*
|
||||
* @brief Provides structures and functions for managing application bundles and obtaining application information.
|
||||
*
|
||||
* You can use functions provided by this module to install, update, or uninstall an application, obtain
|
||||
* {@link AbilityInfo} and {@link BundleInfo} about an application, and obtain the bundle name of an application
|
||||
* based on the application's user ID (UID).
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file element_name.h
|
||||
*
|
||||
* @brief Declares the structure that defines the required information for querying {@link AbilityInfo}, including
|
||||
* the device ID, bundle name, and class name, and functions for setting such information.
|
||||
*
|
||||
* You can use functions provided in this file to specify the information for querying {@link AbilityInfo}.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ELEMENT_NAME_H
|
||||
#define OHOS_ELEMENT_NAME_H
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
#include <serializer.h>
|
||||
#endif
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* @brief Defines the ability information.
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* Pointer to the ID of the device running the application
|
||||
*/
|
||||
char *deviceId;
|
||||
|
||||
/**
|
||||
* Pointer to the bundle name of the application
|
||||
*/
|
||||
char *bundleName;
|
||||
|
||||
/**
|
||||
* Pointer to the class name of the ability
|
||||
*/
|
||||
char *abilityName;
|
||||
} ElementName;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
/**
|
||||
* @brief Clears the internal data of a specified <b>ElementName</b>.
|
||||
*
|
||||
* After {@link AbilityInfo} is queried, clear the internal data of an <b>ElementName</b> if it is no longer required.
|
||||
* @param element Indicates the pointer to the <b>ElementName</b> to clear.
|
||||
*/
|
||||
void ClearElement(ElementName *element);
|
||||
|
||||
/**
|
||||
* @brief Sets the device ID used to query {@link AbilityInfo}.
|
||||
*
|
||||
* @param element Indicates the pointer to the <b>ElementName</b> to set.
|
||||
* @param deviceId Indicates the pointer to the device ID to set.
|
||||
*
|
||||
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
|
||||
*/
|
||||
bool SetElementDeviceID(ElementName *element, const char *deviceId);
|
||||
|
||||
/**
|
||||
* @brief Sets the bundle name used to query {@link AbilityInfo}.
|
||||
*
|
||||
* @param element Indicates the pointer to the <b>ElementName</b> to set.
|
||||
* @param bundleName Indicates the pointer to the bundle name to set.
|
||||
*
|
||||
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
|
||||
*/
|
||||
bool SetElementBundleName(ElementName *element, const char *bundleName);
|
||||
|
||||
/**
|
||||
* @brief Sets the class name of the ability used to query {@link AbilityInfo}.
|
||||
*
|
||||
* @param element Indicates the pointer to the <b>ElementName</b> to set.
|
||||
* @param abilityName Indicates the pointer to the class name to set.
|
||||
*
|
||||
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
|
||||
*/
|
||||
bool SetElementAbilityName(ElementName *element, const char *abilityName);
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
bool SerializeElement(IpcIo *io, const ElementName *element);
|
||||
bool DeserializeElement(ElementName *element, IpcIo *io);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // OHOS_ELEMENT_NAME_H
|
||||
/** @} */
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 BundleManager
|
||||
* @{
|
||||
*
|
||||
* @brief Provides structures and functions for managing application bundles and obtaining application information.
|
||||
*
|
||||
* You can use functions provided by this module to install, update, or uninstall an application, obtain
|
||||
* {@link AbilityInfo} and {@link BundleInfo} about an application, and obtain the bundle name of an application
|
||||
* based on the application's user ID (UID).
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file installParam.h
|
||||
*
|
||||
* @brief Declares the parameters that users can specify when they install, update, or uninstall an application.
|
||||
*
|
||||
* The parameters involve the application installation or update path and whether to retain particular data during
|
||||
* application uninstallation.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef OHOS_INSTALL_PARAM_H
|
||||
#define OHOS_INSTALL_PARAM_H
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
enum InstallLocation {
|
||||
/**
|
||||
* The installation or update path is <b>storage/app</b> when {@link installLocation} is set to <b>1</b>.
|
||||
*/
|
||||
INSTALL_LOCATION_INTERNAL_ONLY = 1,
|
||||
/**
|
||||
* The installation or update path is <b>sdcard/app</b> when {@link installLocation} is set to <b>2</b>.
|
||||
*/
|
||||
INSTALL_LOCATION_PREFER_EXTERNAL = 2,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines parameters used for application installation, update, or uninstallation.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Installation or update path of the application */
|
||||
int32_t installLocation;
|
||||
|
||||
/** Whether to retain particular data during application uninstallation */
|
||||
bool keepData;
|
||||
} InstallParam;
|
||||
|
||||
#endif // OHOS_INSTALL_PARAM_H
|
||||
/** @} */
|
||||
+49
@@ -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.
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
import("//build/lite/ndk/ndk.gni")
|
||||
static_library("capability_api_simulator") {
|
||||
sources = [ "${appexecfwk_lite_path}/interfaces/kits/bundle_lite/js/builtin/src/capability_module.cpp" ]
|
||||
cflags = [ "-fPIC" ]
|
||||
cflags += [ "-Wall" ]
|
||||
cflags_cc = cflags
|
||||
include_dirs = [
|
||||
"//foundation/ace/ace_engine_lite/interfaces/innerkits/builtin/base",
|
||||
"//foundation/ace/ace_engine_lite/interfaces/innerkits/builtin/jsi",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite/js/builtin/include",
|
||||
"//foundation/communication/ipc_lite/interfaces/kits",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
|
||||
]
|
||||
defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ]
|
||||
outdir = rebase_path("$root_out_dir")
|
||||
ldflags = [ "-L$outdir" ]
|
||||
}
|
||||
|
||||
shared_library("capability_api") {
|
||||
sources = [ "${appexecfwk_lite_path}/interfaces/kits/bundle_lite/js/builtin/src/capability_module.cpp" ]
|
||||
cflags = [ "-fPIC" ]
|
||||
cflags += [ "-Wall" ]
|
||||
cflags_cc = cflags
|
||||
include_dirs = [
|
||||
"//foundation/ace/ace_engine_lite/interfaces/innerkits/builtin/base",
|
||||
"//foundation/ace/ace_engine_lite/interfaces/innerkits/builtin/jsi",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite/js/builtin/include",
|
||||
"//foundation/communication/ipc_lite/interfaces/kits",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
|
||||
]
|
||||
defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ]
|
||||
outdir = rebase_path("$root_out_dir")
|
||||
ldflags = [ "-L$outdir" ]
|
||||
}
|
||||
@@ -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 CAPABILITY_MODULE_H
|
||||
#define CAPABILITY_MODULE_H
|
||||
|
||||
#include "jsi.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ACELite {
|
||||
class CapabilityModule {
|
||||
public:
|
||||
/**
|
||||
* judge if the system has the capability
|
||||
*
|
||||
* @param thisVal Indicates function execute context
|
||||
* @param args Indicates the function arguments
|
||||
* @param argsSize Indicates the size of function arguments
|
||||
*/
|
||||
static JSIValue HasCapability(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize);
|
||||
};
|
||||
|
||||
void InitCapabilityModule(JSIValue exports);
|
||||
} // namespace ACELite
|
||||
} // namespace OHOS
|
||||
#endif // CAPABILITY_MODULE_H
|
||||
@@ -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 "capability_module.h"
|
||||
#include "bundle_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ACELite {
|
||||
JSIValue CapabilityModule::HasCapability(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize)
|
||||
{
|
||||
if (argsSize < 1) {
|
||||
return JSI::CreateBoolean(false);
|
||||
}
|
||||
char *str = JSI::ValueToString(args[0]);
|
||||
if (str == nullptr) {
|
||||
return JSI::CreateBoolean(false);
|
||||
}
|
||||
bool hasCap = HasSystemCapability(str);
|
||||
ace_free(str);
|
||||
return JSI::CreateBoolean(hasCap);
|
||||
}
|
||||
|
||||
void InitCapabilityModule(JSIValue exports)
|
||||
{
|
||||
JSI::SetModuleAPI(exports, "has", CapabilityModule::HasCapability);
|
||||
}
|
||||
} // namespace ACELite
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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 BundleManager
|
||||
* @{
|
||||
*
|
||||
* @brief Provides structures and functions for managing application bundles and obtaining application information.
|
||||
*
|
||||
* You can use functions provided by this module to install, update, or uninstall an application, obtain
|
||||
* {@link AbilityInfo} and {@link BundleInfo} about an application, and obtain the bundle name of an application based
|
||||
* on the application's user ID (UID).
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file module_info.h
|
||||
*
|
||||
* @brief Declares structures and functions for managing HAP package information.
|
||||
*
|
||||
* The HAP package is used to deploy {@link Ability} instances. It is a module package consisting of the code,
|
||||
* resources, third-party libraries, and an application configuration file. You can use the function provided in this
|
||||
* file to clear HAP information.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OHOS_BUNDLE_MODULE_INFO_H
|
||||
#define OHOS_BUNDLE_MODULE_INFO_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "stdint.h"
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
#define DEVICE_TYPE_SIZE 16
|
||||
#endif
|
||||
#define METADATA_SIZE 16
|
||||
|
||||
/**
|
||||
* @brief Defines the metadata information in a {@link ModuleInfo} object.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Pointer to the metadata name */
|
||||
char *name;
|
||||
|
||||
/** Pointer to the metadata value */
|
||||
char *value;
|
||||
|
||||
/** Extra data. You can customize this field as required. */
|
||||
char *extra;
|
||||
} MetaData;
|
||||
|
||||
/**
|
||||
* @brief Defines the HAP information.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Pointer to the HAP package name */
|
||||
char *moduleName;
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
|
||||
/** Pointer to the description of the HAP package */
|
||||
char *description;
|
||||
|
||||
/** Pointer to the class name of the HAP package */
|
||||
char *name;
|
||||
|
||||
/** Type of the HAP package, either <b>Entry.hap</b> or <b>Feature.hap</b> */
|
||||
char *moduleType;
|
||||
|
||||
/** Whether the HAP package is installed while the user is installing the application */
|
||||
bool isDeliveryInstall;
|
||||
|
||||
/**
|
||||
* Pointer to the types of devices that can run the application. The maximum size of the device type array is
|
||||
* {@link DEVICE_TYPE_SIZE}.
|
||||
*/
|
||||
char *deviceType[DEVICE_TYPE_SIZE];
|
||||
#endif
|
||||
|
||||
/** Pointer to the metadata array whose maximum size is {@link METADATA_SIZE} */
|
||||
MetaData *metaData[METADATA_SIZE];
|
||||
} ModuleInfo;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
/**
|
||||
* @brief Clears a {@link ModuleInfo} object.
|
||||
*
|
||||
* This function clears and releases the memory occupied by the fields of the pointer type included in the specified
|
||||
* {@link ModuleInfo} object.
|
||||
* @param moduleInfo Indicates the pointer to the {@link ModuleInfo} object to clear.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void ClearModuleInfo(ModuleInfo *moduleInfo);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // OHOS_BUNDLE_MODULE_INFO_H
|
||||
/** @} */
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup BundleManager
|
||||
*
|
||||
* @brief Provides structures and functions for managing application bundles and obtaining application information.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bundle_manager.h
|
||||
*
|
||||
* @brief Declares functions used for managing application bundles and obtaining bundle information.
|
||||
*
|
||||
* You can use functions provided in this file to install, update, or uninstall an application, obtain
|
||||
* {@link AbilityInfo} and {@link BundleInfo} about an application, obtain the bundle name of an application based
|
||||
* on the application's user ID (UID), and obtain {@link BundleInfo} objects of all applications or keep-alive
|
||||
* applications in the system.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef OHOS_BUNDLEMANAGER_INTERFACE_H
|
||||
#define OHOS_BUNDLEMANAGER_INTERFACE_H
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "bundle_info.h"
|
||||
#include "bundle_status_callback.h"
|
||||
#include "install_param.h"
|
||||
#include "stdint.h"
|
||||
#include "want.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @brief Called when an application is installed, updated, or uninstalled.
|
||||
*
|
||||
* This function can be registered through {@link Install} and {@link Uninstall} to receive the installation, update,
|
||||
* and uninstallation result.
|
||||
*
|
||||
* @param resultCode Indicates the status code returned for the application installation, update, or uninstallation
|
||||
* result. For details, see {@link AppexecfwkErrors}.
|
||||
* @param resultMessage Indicates the result message returned with the status code.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef void (*InstallerCallback)(const uint8_t resultCode, const void *resultMessage);
|
||||
|
||||
/**
|
||||
* @brief Installs or updates an application.
|
||||
*
|
||||
*
|
||||
* @param hapPath Indicates the pointer to the path for storing the OpenHarmony Ability Package (HAP) of the application
|
||||
* to install or update.
|
||||
* @param installParam Indicates the pointer to the parameters used for application installation or update.
|
||||
* @param installerCallback Indicates the callback to be invoked for notifying the installation or update result.
|
||||
* @return Returns <b>true</b> if this function is successfully called; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback);
|
||||
|
||||
/**
|
||||
* @brief Uninstalls an application.
|
||||
*
|
||||
* @param bundleName Indicates the pointer to the bundle name of the application to uninstall.
|
||||
* @param installParam Indicates the pointer to the parameters used for application uninstallation.
|
||||
* @param installerCallback Indicates the callback to be invoked for notifying the uninstallation result.
|
||||
* @return Returns <b>true</b> if this function is successfully called; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
bool Uninstall(const char *bundleName, const InstallParam *installParam, InstallerCallback installerCallback);
|
||||
|
||||
/**
|
||||
* @brief Queries the {@link AbilityInfo} of an ability based on the information carried in the {@link Want}
|
||||
* structure.
|
||||
* @attention Before querying an {@link AbilityInfo} object, you should first call <b>memset</b> on the
|
||||
* constructed {@link AbilityInfo} object so that each field in it can be properly initialized
|
||||
* for carrying the obtained information.
|
||||
* @param want Indicates the pointer to the {@link Want} structure used for querying the specified ability.
|
||||
* @param abilityInfo Indicates the pointer to the obtained {@link AbilityInfo} object.
|
||||
*
|
||||
* @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in
|
||||
* {@link AppexecfwkErrors} otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo);
|
||||
|
||||
/**
|
||||
* @brief Obtains the {@link BundleInfo} of an application based on the specified bundle name.
|
||||
*
|
||||
* @attention Before querying a {@link BundleInfo} object, you should first call <b>memset</b> on the constructed
|
||||
* {@link BundleInfo} object so that each field in it can be properly initialized for carrying the
|
||||
* obtained information.
|
||||
* @param bundleName Indicates the pointer to the name of the application bundle to query.
|
||||
* @param flags Specifies whether the obtained {@link BundleInfo} object can contain {@link AbilityInfo}. The value
|
||||
* <b>1</b> indicates that it can contain {@link AbilityInfo}, and <b>0</b> indicates that it cannot.
|
||||
* @param bundleInfo Indicates the pointer to the obtained {@link BundleInfo} object.
|
||||
*
|
||||
* @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in
|
||||
* {@link AppexecfwkErrors} otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo);
|
||||
|
||||
/**
|
||||
* @brief Obtains the {@link BundleInfo} of all bundles in the system.
|
||||
*
|
||||
* @param flags Specifies whether each of the obtained {@link BundleInfo} objects can contain {@link AbilityInfo}.
|
||||
* The value <b>1</b> indicates that it can contain {@link AbilityInfo}, and <b>0</b> indicates that
|
||||
* it cannot.
|
||||
* @param bundleInfos Indicates the double pointer to the obtained {@link BundleInfo} objects.
|
||||
* @param len Indicates the pointer to the number of {@link BundleInfo} objects obtained.
|
||||
* @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in
|
||||
* {@link AppexecfwkErrors} otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif /* OHOS_BUNDLEMANAGER_INTERFACE_H */
|
||||
/** @} */
|
||||
@@ -1,3 +0,0 @@
|
||||
详见:https://gitee.com/openharmony/docs/blob/master/readme/用户程序框架子系统README.md
|
||||
|
||||
see: https://gitee.com/openharmony/docs/blob/master/docs-en/readme/application-framework.md
|
||||
@@ -0,0 +1 @@
|
||||
unittest
|
||||
@@ -0,0 +1,101 @@
|
||||
# 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")
|
||||
|
||||
config("bundle_config") {
|
||||
defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ]
|
||||
cflags_cc = [ "-std=c++14" ]
|
||||
}
|
||||
|
||||
shared_library("bundlems") {
|
||||
configs -= [ "//build/lite/config:language_cpp" ]
|
||||
configs += [ ":bundle_config" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Wno-format",
|
||||
"-Wno-format-extra-args",
|
||||
]
|
||||
cflags_cc = cflags
|
||||
|
||||
sources = [
|
||||
"src/bundle_daemon_client.cpp",
|
||||
"src/bundle_extractor.cpp",
|
||||
"src/bundle_info_creator.cpp",
|
||||
"src/bundle_inner_feature.cpp",
|
||||
"src/bundle_installer.cpp",
|
||||
"src/bundle_manager_service.cpp",
|
||||
"src/bundle_map.cpp",
|
||||
"src/bundle_ms_feature.cpp",
|
||||
"src/bundle_ms_host.cpp",
|
||||
"src/bundle_parser.cpp",
|
||||
"src/bundle_res_transform.cpp",
|
||||
"src/bundle_util.cpp",
|
||||
"src/extractor_util.cpp",
|
||||
"src/hap_sign_verify.cpp",
|
||||
"src/zip_file.cpp",
|
||||
]
|
||||
include_dirs = [
|
||||
"//base/global/resmgr_lite/interfaces/innerkits/include",
|
||||
"${aafwk_lite_path}/services/abilitymgr_lite/include",
|
||||
"${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite",
|
||||
"${aafwk_lite_path}/interfaces/kits/ability_lite",
|
||||
"${aafwk_lite_path}/interfaces/kits/want_lite",
|
||||
"${aafwk_lite_path}/frameworks/want_lite/include",
|
||||
"${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite",
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite/include",
|
||||
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
|
||||
"${appexecfwk_lite_path}/utils/bundle_lite",
|
||||
"//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/cJSON",
|
||||
"//third_party/zlib",
|
||||
"//third_party/zlib/contrib/minizip",
|
||||
"//base/security/permission/interfaces/kits/permission_lite",
|
||||
"//base/security/permission/services/permission_lite/pms/include",
|
||||
"//base/security/appverify/interfaces/innerkits/appverify_lite/include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//utils/native/lite/include",
|
||||
"//utils/native/lite/memory",
|
||||
"include",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
|
||||
"//base/global/resmgr_lite/frameworks/resmgr_lite:global_resmgr",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//base/security/appverify/interfaces/innerkits/appverify_lite:verify",
|
||||
"//build/lite/config/component/cJSON:cjson_shared",
|
||||
"//build/lite/config/component/zlib:zlib_shared",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
|
||||
]
|
||||
}
|
||||
|
||||
generate_notice_file("appexecfwk_services_lite_notice_file") {
|
||||
module_name = "appexecfwk_services_lite"
|
||||
module_source_dir_list = [
|
||||
"//third_party/cJSON",
|
||||
"//third_party/zlib",
|
||||
"//third_party/bounds_checking_function",
|
||||
]
|
||||
}
|
||||
|
||||
lite_component("appexecfwk_services_lite") {
|
||||
features = [
|
||||
":bundlems",
|
||||
"tools:bm",
|
||||
"bundle_daemon:bundle_daemon",
|
||||
]
|
||||
}
|
||||
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
+54
@@ -0,0 +1,54 @@
|
||||
# BMS - Bundle manager service of OpenHarmony
|
||||
|
||||
## Introduction
|
||||
|
||||
`Bundle manager service` (BMS) is aiming at installing/uninstalling application and managing bundleInfo.
|
||||
|
||||
## Features
|
||||
|
||||
- install application, include read files, parse files, create files, write to files and remove files.
|
||||
- uninstall application
|
||||
- manage bundleInfo
|
||||
- a `bm` tool who has capacity to install, uninstall applications and to dump some information of the specified applications.
|
||||
|
||||
## Directions
|
||||
|
||||
```
|
||||
.
|
||||
├── BUILD.gn
|
||||
├── include
|
||||
│ ├── bundle_common.h # common setting info
|
||||
│ ├── bundle_extractor.h # bundle extractor
|
||||
│ ├── bundle_installer.h # implementation of installing and uninstalling bundle
|
||||
│ ├── bundle_manager_service.h # bundle service task initialize and implementation of message process
|
||||
│ ├── bundle_map.h # manage bundleInfo
|
||||
│ ├── bundle_message_id.h # bundle message id setting
|
||||
│ ├── bundle_ms_feature.h # BMS feature in Service Manager
|
||||
│ ├── bundle_ms_host.h # register BMS in the Service Manager
|
||||
│ ├── bundle_parser.h # parser bundle
|
||||
│ ├── bundle_util.h # bundle util method
|
||||
│ ├── extractor_util.h # extractor util method
|
||||
│ ├── hap_sign_verify.h # verify signature of the hap package
|
||||
│ └── zip_file.h # zip or unzip the hap package
|
||||
├── README.md
|
||||
├── src
|
||||
│ ├── bundle_extractor.cpp
|
||||
│ ├── bundle_installer.cpp
|
||||
│ ├── bundle_manager_service.cpp
|
||||
│ ├── bundle_map.cpp
|
||||
│ ├── bundle_ms_feature.cpp
|
||||
│ ├── bundle_ms_host.cpp
|
||||
│ ├── bundle_parser.cpp
|
||||
│ ├── bundle_util.cpp
|
||||
│ ├── extractor_util.cpp
|
||||
│ ├── hap_sign_verify.cpp
|
||||
│ └── zip_file.cpp
|
||||
└── tools
|
||||
├── BUILD.gn
|
||||
├── include
|
||||
│ └── command_parser.h
|
||||
└── src
|
||||
├── command_parser.cpp
|
||||
└── main.cpp
|
||||
|
||||
```
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
# 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("bundle_daemon_lite_notice_file") {
|
||||
module_name = "bundle_daemon_lite"
|
||||
module_source_dir_list = [
|
||||
"//third_party/cJSON",
|
||||
"//third_party/zlib",
|
||||
]
|
||||
}
|
||||
|
||||
executable("bundle_daemon") {
|
||||
sources = [
|
||||
"../src/extractor_util.cpp",
|
||||
"../src/zip_file.cpp",
|
||||
"src/bundle_daemon.cpp",
|
||||
"src/bundle_daemon_handler.cpp",
|
||||
"src/bundle_file_utils.cpp",
|
||||
"src/bundlems_client.cpp",
|
||||
"src/main.cpp",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Wno-format",
|
||||
]
|
||||
cflags_cc = cflags
|
||||
|
||||
ldflags = [
|
||||
"-lstdc++",
|
||||
"-Wl,-Map=bundle_daemon_tool.map",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//build/lite/config/component/zlib:zlib_shared",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite",
|
||||
"${appexecfwk_lite_path}/utils/bundle_lite",
|
||||
"${appexecfwk_lite_path}/services/bundlemgr_lite/include",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/innerkits/samgr",
|
||||
"//foundation/distributedschedule/samgr_lite/interfaces/innerkits/registry",
|
||||
"//third_party/zlib/contrib/minizip",
|
||||
"//utils/native/lite/include",
|
||||
]
|
||||
}
|
||||
@@ -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_BUNDLE_DAEMON_H
|
||||
#define OHOS_BUNDLE_DAEMON_H
|
||||
|
||||
#include "bundle_daemon_handler.h"
|
||||
#include "bundle_daemon_interface.h"
|
||||
#include "bundlems_client.h"
|
||||
#include "nocopyable.h"
|
||||
#include "service.h"
|
||||
|
||||
namespace OHOS {
|
||||
typedef int32_t (*InvokeFunc)(IpcIo *req);
|
||||
class BundleDaemon : public Service, NoCopyable {
|
||||
public:
|
||||
static BundleDaemon &GetInstance()
|
||||
{
|
||||
static BundleDaemon instance;
|
||||
return instance;
|
||||
}
|
||||
static int32_t Invoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply);
|
||||
private:
|
||||
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:
|
||||
BundleDaemon();
|
||||
~BundleDaemon();
|
||||
Identity identity_ {};
|
||||
BundleDaemonHandler handler_ {};
|
||||
BundleMsClient *bundleMsClient_ { nullptr };
|
||||
|
||||
static int32_t RegisterCallbackInvoke(IpcIo *req);
|
||||
static int32_t ExtractHapInvoke(IpcIo *req);
|
||||
static int32_t RenameFileInvoke(IpcIo *req);
|
||||
static int32_t CreatePermissionInvoke(IpcIo *req);
|
||||
static int32_t CreateDataDirectoryInvoke(IpcIo *req);
|
||||
static int32_t StoreContentToFileInvoke(IpcIo *req);
|
||||
static int32_t MoveFileInvoke(IpcIo *req);
|
||||
static int32_t RemoveFileInvoke(IpcIo *req);
|
||||
static int32_t RemoveInstallDirectoryInvoke(IpcIo *req);
|
||||
static constexpr InvokeFunc invokeFuncs[BDS_CMD_END] {
|
||||
BundleDaemon::ExtractHapInvoke,
|
||||
BundleDaemon::RenameFileInvoke,
|
||||
BundleDaemon::CreatePermissionInvoke,
|
||||
BundleDaemon::CreateDataDirectoryInvoke,
|
||||
BundleDaemon::StoreContentToFileInvoke,
|
||||
BundleDaemon::MoveFileInvoke,
|
||||
BundleDaemon::RemoveFileInvoke,
|
||||
BundleDaemon::RemoveInstallDirectoryInvoke,
|
||||
};
|
||||
};
|
||||
|
||||
struct DefaultFeatureApi {
|
||||
INHERIT_SERVER_IPROXY;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
|
||||
Identity identity;
|
||||
} BundleDaemonFeature;
|
||||
} // OHOS
|
||||
#endif // OHOS_BUNDLE_DAEMON_H
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_BUNDLE_DAEMON_HANDLER_H
|
||||
#define OHOS_BUNDLE_DAEMON_HANDLER_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "nocopyable.h"
|
||||
#include "ohos_types.h"
|
||||
|
||||
namespace OHOS {
|
||||
class BundleDaemonHandler : public NoCopyable {
|
||||
public:
|
||||
int32_t ExtractHap(const char *hapPath, const char *codePath);
|
||||
int32_t RenameFile(const char *oldFile, const char *newFile);
|
||||
int32_t CreatePermissionDir();
|
||||
int32_t CreateDataDirectory(const char *dataPath, int32_t uid, int32_t gid, bool isChown);
|
||||
int32_t StoreContentToFile(const char *filePath, const void *buffer, uint32_t size);
|
||||
int32_t MoveFile(const char *oldFile, const char *newFile);
|
||||
int32_t RemoveFile(const char *file);
|
||||
int32_t RemoveInstallDirectory(const char *codePath, const char *dataPath, bool keepData);
|
||||
private:
|
||||
bool IsValideCodePath(const char *codePath);
|
||||
bool IsValideDataPath(const char *codePath);
|
||||
bool IsValideJsonPath(const char *jsonPath);
|
||||
bool IsValideSystemPath(const char *jsonPath);
|
||||
};
|
||||
} // OHOS
|
||||
#endif // OHOS_BUNDLE_DAEMON_HANDLER_H
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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_BUNDLE_DAEMON_LOG_H
|
||||
#define OHOS_BUNDLE_DAEMON_LOG_H
|
||||
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "bundle_deamon"
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN 0xD001100
|
||||
|
||||
#define PRINTD(name, fmt, ...) HILOG_DEBUG(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define PRINTI(name, fmt, ...) HILOG_INFO(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define PRINTW(name, fmt, ...) HILOG_WARN(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define PRINTE(name, fmt, ...) HILOG_ERROR(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
} // OHOS
|
||||
#endif // OHOS_BUNDLE_DAEMON_LOG_H
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_BUNDLE_FILE_UTILS_H
|
||||
#define OHOS_BUNDLE_FILE_UTILS_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "nocopyable.h"
|
||||
#include "utils_list.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
const char PATH_SEPARATOR = '/';
|
||||
}
|
||||
class BundleFileUtils : public NoCopyable {
|
||||
public:
|
||||
static bool MkRecursiveDir(const char *dir, bool isReadOthers);
|
||||
static bool IsExistDir(const char *path);
|
||||
static bool IsExistFile(const char *file);
|
||||
static bool RemoveFile(const char *path);
|
||||
static bool RenameFile(const char *oldDir, const char *newDir);
|
||||
static bool ChownFile(const char *file, int32_t uid, int32_t gid);
|
||||
static bool WriteFile(const char *file, const void *buffer, uint32_t size);
|
||||
static bool IsValidPath(const std::string &rootDir, const std::string &path);
|
||||
static std::string GetPathDir(const std::string &path);
|
||||
};
|
||||
} // OHOS
|
||||
#endif // OHOS_BUNDLE_FILE_UTILS_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_BUNDLEMS_CLIENT_H
|
||||
#define OHOS_BUNDLEMS_CLIENT_H
|
||||
|
||||
#include "liteipc_adapter.h"
|
||||
#include "nocopyable.h"
|
||||
#include "ohos_types.h"
|
||||
|
||||
namespace OHOS {
|
||||
class BundleMsClient : public NoCopyable {
|
||||
public:
|
||||
explicit BundleMsClient(const SvcIdentity &svcIdentity);
|
||||
~BundleMsClient() {};
|
||||
int32_t SendReply(int32_t result);
|
||||
private:
|
||||
SvcIdentity svcIdentity_ {};
|
||||
};
|
||||
} // OHOS
|
||||
#endif // OHOS_BUNDLEMS_CLIENT_H
|
||||
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* 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 "bundle_daemon.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "bundle_daemon_log.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "ohos_errno.h"
|
||||
#include "ohos_init.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "serializer.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr int STACK_SIZE = 0x800;
|
||||
constexpr int QUEUE_SIZE = 20;
|
||||
constexpr pid_t BMS_UID = 7;
|
||||
}
|
||||
constexpr InvokeFunc BundleDaemon::invokeFuncs[];
|
||||
|
||||
static BundleDaemonFeature g_defaultApi = {
|
||||
SERVER_IPROXY_IMPL_BEGIN,
|
||||
.Invoke = BundleDaemon::Invoke,
|
||||
IPROXY_END,
|
||||
};
|
||||
|
||||
static void Init()
|
||||
{
|
||||
SamgrLite *samgrLite = SAMGR_GetInstance();
|
||||
if (samgrLite == nullptr) {
|
||||
PRINTE("BundleDaemon", "get samgr is nullptr");
|
||||
return;
|
||||
}
|
||||
BOOL result = samgrLite->RegisterService(&BundleDaemon::GetInstance());
|
||||
if (!result) {
|
||||
PRINTE("BundleDaemon", "register bundle_daemon service fail");
|
||||
return;
|
||||
}
|
||||
result = samgrLite->RegisterDefaultFeatureApi(BDS_SERVICE, GET_IUNKNOWN(g_defaultApi));
|
||||
PRINTE("BundleDaemon", "register default feature api %{public}s", result ? "success" : "fail");
|
||||
}
|
||||
SYSEX_SERVICE_INIT(Init);
|
||||
|
||||
BundleDaemon::BundleDaemon()
|
||||
{
|
||||
this->Service::GetName = BundleDaemon::GetServiceName;
|
||||
this->Service::Initialize = BundleDaemon::ServiceInitialize;
|
||||
this->Service::MessageHandle = BundleDaemon::ServiceMessageHandle;
|
||||
this->Service::GetTaskConfig = BundleDaemon::GetServiceTaskConfig;
|
||||
}
|
||||
|
||||
|
||||
BundleDaemon::~BundleDaemon()
|
||||
{
|
||||
delete bundleMsClient_;
|
||||
}
|
||||
|
||||
const char *BundleDaemon::GetServiceName(Service *service)
|
||||
{
|
||||
(void)service;
|
||||
return BDS_SERVICE;
|
||||
}
|
||||
|
||||
BOOL BundleDaemon::ServiceInitialize(Service *service, Identity identity)
|
||||
{
|
||||
if (service == nullptr) {
|
||||
return FALSE;
|
||||
}
|
||||
BundleDaemon *bundleDaemon = static_cast<BundleDaemon *>(service);
|
||||
bundleDaemon->identity_ = identity;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
TaskConfig BundleDaemon::GetServiceTaskConfig(Service *service)
|
||||
{
|
||||
TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, STACK_SIZE, QUEUE_SIZE, SINGLE_TASK};
|
||||
return config;
|
||||
}
|
||||
|
||||
BOOL BundleDaemon::ServiceMessageHandle(Service *service, Request *request)
|
||||
{
|
||||
if (request == nullptr) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int32_t BundleDaemon::Invoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply)
|
||||
{
|
||||
PRINTI("BundleDaemon", "bundle_daemon invoke start %{public}d", funcId);
|
||||
if (origin == nullptr || req == nullptr) {
|
||||
PRINTE("BundleDaemon", "invalid param");
|
||||
return EC_INVALID;
|
||||
}
|
||||
// check permission
|
||||
pid_t uid = GetCallingUid(origin);
|
||||
if (uid != BMS_UID) {
|
||||
PRINTE("BundleDaemon", "permission denied");
|
||||
return EC_PERMISSION;
|
||||
}
|
||||
if (funcId == REGISTER_CALLBACK) {
|
||||
#ifdef __LINUX__
|
||||
return EC_SUCCESS;
|
||||
#else
|
||||
return RegisterCallbackInvoke(req);
|
||||
#endif
|
||||
}
|
||||
#ifndef __LINUX__
|
||||
if (BundleDaemon::GetInstance().bundleMsClient_ == nullptr) {
|
||||
PRINTE("BundleDaemon", "bundleMsClient is nullptr");
|
||||
return EC_NOINIT;
|
||||
}
|
||||
#endif
|
||||
int32_t ret = EC_COMMU;
|
||||
if (funcId >= EXTRACT_HAP && funcId < BDS_CMD_END) {
|
||||
ret = (BundleDaemon::invokeFuncs[funcId])(req);
|
||||
}
|
||||
#ifdef __LINUX__
|
||||
IpcIoPushInt32(reply, ret);
|
||||
return ret;
|
||||
#else
|
||||
return BundleDaemon::GetInstance().bundleMsClient_->SendReply(ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t BundleDaemon::RegisterCallbackInvoke(IpcIo *req)
|
||||
{
|
||||
SvcIdentity *svcIdentity = IpcIoPopSvc(req);
|
||||
if (svcIdentity == nullptr) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
BundleDaemon::GetInstance().bundleMsClient_ = new BundleMsClient(*svcIdentity);
|
||||
return BundleDaemon::GetInstance().bundleMsClient_->SendReply(EC_SUCCESS);
|
||||
}
|
||||
|
||||
static int32_t ObtainStringFromIpc(IpcIo *req, std::string &firstStr, std::string &secondStr)
|
||||
{
|
||||
#ifdef __LINUX__
|
||||
size_t length = 0;
|
||||
std::string innerStr = reinterpret_cast<char *>(IpcIoPopString(req, &length));
|
||||
#else
|
||||
BuffPtr *buff = IpcIoPopDataBuff(req);
|
||||
if (buff == nullptr || buff->buffSz == 0) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
std::string innerStr = reinterpret_cast<char *>(buff->buff);
|
||||
#endif
|
||||
uint32_t len = IpcIoPopUint16(req);
|
||||
if (innerStr.length() <= len) {
|
||||
#ifndef __LINUX__
|
||||
FreeBuffer(nullptr, buff->buff);
|
||||
#endif
|
||||
return EC_INVALID;
|
||||
}
|
||||
firstStr = innerStr.substr(0, len);
|
||||
secondStr = innerStr.substr(len);
|
||||
#ifndef __LINUX__
|
||||
FreeBuffer(nullptr, buff->buff);
|
||||
#endif
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t BundleDaemon::ExtractHapInvoke(IpcIo *req)
|
||||
{
|
||||
std::string hapPath = "";
|
||||
std::string codePath = "";
|
||||
int32_t ret = ObtainStringFromIpc(req, hapPath, codePath);
|
||||
if (ret != EC_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
return BundleDaemon::GetInstance().handler_.ExtractHap(hapPath.c_str(), codePath.c_str());
|
||||
}
|
||||
|
||||
int32_t BundleDaemon::RenameFileInvoke(IpcIo *req)
|
||||
{
|
||||
std::string oldFile = "";
|
||||
std::string newFile = "";
|
||||
int32_t ret = ObtainStringFromIpc(req, oldFile, newFile);
|
||||
if (ret != EC_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
return BundleDaemon::GetInstance().handler_.RenameFile(oldFile.c_str(), newFile.c_str());
|
||||
}
|
||||
|
||||
int32_t BundleDaemon::CreatePermissionInvoke(IpcIo *req)
|
||||
{
|
||||
return BundleDaemon::GetInstance().handler_.CreatePermissionDir();
|
||||
}
|
||||
|
||||
int32_t BundleDaemon::CreateDataDirectoryInvoke(IpcIo *req)
|
||||
{
|
||||
size_t len = 0;
|
||||
const char *dataPath = reinterpret_cast<char *>(IpcIoPopString(req, &len));
|
||||
if (dataPath == nullptr || len == 0) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
int32_t uid = IpcIoPopInt32(req);
|
||||
int32_t gid = IpcIoPopInt32(req);
|
||||
bool isChown = IpcIoPopBool(req);
|
||||
|
||||
return BundleDaemon::GetInstance().handler_.CreateDataDirectory(dataPath, uid, gid, isChown);
|
||||
}
|
||||
|
||||
int32_t BundleDaemon::StoreContentToFileInvoke(IpcIo *req)
|
||||
{
|
||||
size_t len = 0;
|
||||
const char *path = reinterpret_cast<char *>(IpcIoPopString(req, &len));
|
||||
if (path == nullptr || len == 0) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
#ifdef __LINUX__
|
||||
size_t buffLen = 0;
|
||||
const char *buff = reinterpret_cast<char *>(IpcIoPopString(req, &buffLen));
|
||||
if (buff == nullptr || buffLen == 0) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
int32_t ret = BundleDaemon::GetInstance().handler_.StoreContentToFile(path, buff, buffLen);
|
||||
#else
|
||||
BuffPtr *buffPtr = IpcIoPopDataBuff(req);
|
||||
if (buffPtr == nullptr || buffPtr->buffSz == 0) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
char *buff = reinterpret_cast<char *>(buffPtr->buff);
|
||||
if (buff == nullptr) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
|
||||
int32_t ret = BundleDaemon::GetInstance().handler_.StoreContentToFile(path, buff, buffPtr->buffSz);
|
||||
FreeBuffer(nullptr, buffPtr->buff);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t BundleDaemon::MoveFileInvoke(IpcIo *req)
|
||||
{
|
||||
size_t len = 0;
|
||||
const char *oldFile = reinterpret_cast<char *>(IpcIoPopString(req, &len));
|
||||
if (oldFile == nullptr || len == 0) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
const char *newFile = reinterpret_cast<char *>(IpcIoPopString(req, &len));
|
||||
if (newFile == nullptr || len == 0) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
return BundleDaemon::GetInstance().handler_.MoveFile(oldFile, newFile);
|
||||
}
|
||||
|
||||
int32_t BundleDaemon::RemoveFileInvoke(IpcIo *req)
|
||||
{
|
||||
size_t len = 0;
|
||||
const char *path = reinterpret_cast<char *>(IpcIoPopString(req, &len));
|
||||
if (path == nullptr || len == 0) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
return BundleDaemon::GetInstance().handler_.RemoveFile(path);
|
||||
}
|
||||
|
||||
int32_t BundleDaemon::RemoveInstallDirectoryInvoke(IpcIo *req)
|
||||
{
|
||||
std::string codePath = "";
|
||||
std::string dataPath = "";
|
||||
int32_t ret = ObtainStringFromIpc(req, codePath, dataPath);
|
||||
if (ret != EC_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
bool keepData = IpcIoPopBool(req);
|
||||
return BundleDaemon::GetInstance().handler_.RemoveInstallDirectory(codePath.c_str(), dataPath.c_str(), keepData);
|
||||
}
|
||||
} // OHOS
|
||||
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* 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 "bundle_daemon_handler.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "bundle_daemon_log.h"
|
||||
#include "bundle_file_utils.h"
|
||||
#include "extractor_util.h"
|
||||
#include "ohos_errno.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
const char *PERMISSIONS_PATH = "/storage/app/etc/permissions/";
|
||||
constexpr pid_t PMS_UID = 7;
|
||||
constexpr pid_t PMS_GID = 7;
|
||||
const std::string JSON_PATH = "/app/etc/";
|
||||
const std::string HAP_CODE_PATH = "/app/run/";
|
||||
const std::string HAP_DATA_PATH = "/app/data/";
|
||||
const std::string SYSTEM_HAP_PATH = "/system/internal";
|
||||
const std::string THIRD_HAP_PATH = "/system/external";
|
||||
const std::string SDCARD = "/sdcard";
|
||||
const std::string STORAGE = "/storage";
|
||||
}
|
||||
|
||||
int32_t BundleDaemonHandler::ExtractHap(const char *hapPath, const char *codePath)
|
||||
{
|
||||
char realHapPath[PATH_MAX + 1] = { '\0' };
|
||||
if (hapPath == nullptr || realpath(hapPath, realHapPath) == nullptr) {
|
||||
PRINTE("BundleDaemonHandler", "realPath fail!");
|
||||
return EC_INVALID;
|
||||
}
|
||||
ExtractorUtil extractorUtil(realHapPath);
|
||||
if (!extractorUtil.Init()) {
|
||||
PRINTE("BundleDaemonHandler", "init fail!");
|
||||
return EC_NOINIT;
|
||||
}
|
||||
|
||||
// check and mkdir code path
|
||||
if (!IsValideCodePath(codePath)) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
if (!BundleFileUtils::RemoveFile(codePath)) {
|
||||
PRINTE("BundleDaemonHandler", "remove codePath fail!");
|
||||
return EC_NODIR;
|
||||
}
|
||||
std::string codeDir = std::string(codePath);
|
||||
if (codeDir.back() != PATH_SEPARATOR) {
|
||||
codeDir += PATH_SEPARATOR;
|
||||
}
|
||||
|
||||
if (!BundleFileUtils::MkRecursiveDir(codeDir.c_str(), true)) {
|
||||
PRINTE("BundleDaemonHandler", "create codePath fail!");
|
||||
return EC_NODIR;
|
||||
}
|
||||
|
||||
// unzip one by one
|
||||
const std::vector<std::string> &fileNames = extractorUtil.GetZipFileNames();
|
||||
for (const auto &fileName : fileNames) {
|
||||
if (fileName.find("..") != std::string::npos) {
|
||||
PRINTE("BundleDaemonHandler", "zip file is invalid!");
|
||||
return EC_NODIR;
|
||||
}
|
||||
if (fileName.back() == PATH_SEPARATOR) {
|
||||
continue;
|
||||
}
|
||||
const std::string dir = BundleFileUtils::GetPathDir(fileName);
|
||||
if (!dir.empty()) {
|
||||
std::string fileDir = codeDir + dir;
|
||||
if (!BundleFileUtils::MkRecursiveDir(fileDir.c_str(), false)) {
|
||||
PRINTE("BundleDaemonHandler", "create other dir fail!");
|
||||
return EC_NODIR;
|
||||
}
|
||||
}
|
||||
std::string filePath = codeDir + fileName;
|
||||
if (!extractorUtil.ExtractFileToPath(filePath, fileName)) {
|
||||
PRINTE("BundleDaemonHandler", "ExtractFileToPath fail!");
|
||||
return EC_NODIR;
|
||||
}
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t BundleDaemonHandler::RenameFile(const char *oldFile, const char *newFile)
|
||||
{
|
||||
char realOldPath[PATH_MAX + 1] = { '\0' };
|
||||
if (oldFile == nullptr || realpath(oldFile, realOldPath) == nullptr) {
|
||||
PRINTE("BundleDaemonHandler", "realPath fail!");
|
||||
return EC_INVALID;
|
||||
}
|
||||
if (!(IsValideCodePath(realOldPath) && IsValideCodePath(newFile)) &&
|
||||
!(IsValideJsonPath(realOldPath) && IsValideJsonPath(newFile))) {
|
||||
PRINTE("BundleDaemonHandler", "file path is invalid");
|
||||
return EC_INVALID;
|
||||
}
|
||||
if (!BundleFileUtils::RenameFile(realOldPath, newFile)) {
|
||||
PRINTE("BundleDaemonHandler", "rename dir fail");
|
||||
return EC_NODIR;
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t BundleDaemonHandler::CreatePermissionDir()
|
||||
{
|
||||
if (!BundleFileUtils::MkRecursiveDir(PERMISSIONS_PATH, false)) {
|
||||
PRINTE("BundleDaemonHandler", "mk dir fail");
|
||||
return EC_NODIR;
|
||||
}
|
||||
if (!BundleFileUtils::ChownFile(PERMISSIONS_PATH, PMS_UID, PMS_GID)) {
|
||||
PRINTE("BundleDaemonHandler", "chown permission path fail");
|
||||
return EC_PERMISSION;
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t BundleDaemonHandler::CreateDataDirectory(const char *dataPath, int32_t uid, int32_t gid, bool isChown)
|
||||
{
|
||||
if (!IsValideDataPath(dataPath)) {
|
||||
PRINTE("BundleDaemonHandler", "bundleName is nullptr");
|
||||
return EC_INVALID;
|
||||
}
|
||||
std::string dataDir = std::string(dataPath);
|
||||
if (dataDir.back() != PATH_SEPARATOR) {
|
||||
dataDir += PATH_SEPARATOR;
|
||||
}
|
||||
|
||||
if (!BundleFileUtils::IsExistDir(dataDir.c_str())) {
|
||||
if (!BundleFileUtils::MkRecursiveDir(dataDir.c_str(), false)) {
|
||||
PRINTE("BundleDaemonHandler", "create dataPath fail");
|
||||
return EC_NODIR;
|
||||
}
|
||||
}
|
||||
|
||||
if (isChown && !BundleFileUtils::ChownFile(dataDir.c_str(), uid, gid)) {
|
||||
PRINTE("BundleDaemonHandler", "chown file fail");
|
||||
return EC_NOFILE;
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t BundleDaemonHandler::RemoveInstallDirectory(const char *codePath, const char *dataPath, bool keepData)
|
||||
{
|
||||
bool result = IsValideCodePath(codePath) && BundleFileUtils::RemoveFile(codePath);
|
||||
if (!keepData) {
|
||||
result = IsValideDataPath(dataPath) && BundleFileUtils::RemoveFile(dataPath) && result;
|
||||
}
|
||||
return result ? EC_SUCCESS : EC_NODIR;
|
||||
}
|
||||
|
||||
int32_t BundleDaemonHandler::StoreContentToFile(const char *filePath, const void *buffer, uint32_t size)
|
||||
{
|
||||
if (!IsValideJsonPath(filePath)) {
|
||||
PRINTE("BundleDaemonHandler", "store content file path invalid");
|
||||
return EC_NOFILE;
|
||||
}
|
||||
// mkdir root dir
|
||||
const std::string dir = BundleFileUtils::GetPathDir(filePath);
|
||||
if (dir.empty()) {
|
||||
PRINTE("BundleDaemonHandler", "store content file dir invalid");
|
||||
return EC_NODIR;
|
||||
}
|
||||
if (!BundleFileUtils::IsExistDir(dir.c_str())) {
|
||||
if (!BundleFileUtils::MkRecursiveDir(dir.c_str(), true)) {
|
||||
PRINTE("BundleDaemonHandler", "mkdir content json path fail");
|
||||
return EC_NODIR;
|
||||
}
|
||||
}
|
||||
|
||||
if (!BundleFileUtils::WriteFile(filePath, buffer, size)) {
|
||||
PRINTE("BundleDaemonHandler", "save content to file fail");
|
||||
BundleFileUtils::RemoveFile(filePath);
|
||||
return EC_NODIR;
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t BundleDaemonHandler::MoveFile(const char *oldFile, const char *newFile)
|
||||
{
|
||||
char realOldPath[PATH_MAX + 1] = { '\0' };
|
||||
if (oldFile == nullptr || realpath(oldFile, static_cast<char *>(realOldPath)) == nullptr) {
|
||||
PRINTE("BundleDaemonHandler", "realPath oldFile fail!");
|
||||
return EC_INVALID;
|
||||
}
|
||||
|
||||
if (BundleFileUtils::IsExistFile(static_cast<char *>(realOldPath))) {
|
||||
if (!BundleFileUtils::RenameFile(static_cast<char *>(realOldPath), newFile)) {
|
||||
PRINTE("BundleDaemonHandler", "RenameFile fail!");
|
||||
return EC_FAILURE;
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
if (BundleFileUtils::IsExistFile(newFile)) {
|
||||
PRINTE("BundleDaemonHandler", "target file exist!");
|
||||
return EC_INVALID;
|
||||
}
|
||||
if (!BundleFileUtils::IsExistDir(newFile)) {
|
||||
BundleFileUtils::MkRecursiveDir(newFile, true);
|
||||
}
|
||||
|
||||
DIR *dir = opendir(static_cast<char *>(realOldPath));
|
||||
if (dir == nullptr) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
dirent *ent;
|
||||
while ((ent = readdir(dir)) != nullptr) {
|
||||
if ((strcmp(ent->d_name, ".") == 0) || (strcmp(ent->d_name, "..")) == 0) {
|
||||
continue;
|
||||
}
|
||||
std::string oldFileName = std::string(realOldPath) + PATH_SEPARATOR + ent->d_name;
|
||||
if (BundleFileUtils::IsExistDir(oldFileName.c_str())) {
|
||||
continue;
|
||||
}
|
||||
std::string newFileName = std::string(newFile) + PATH_SEPARATOR + ent->d_name;
|
||||
if (!BundleFileUtils::RenameFile(oldFileName.c_str(), newFileName.c_str())) {
|
||||
PRINTW("BundleDaemonHandler", "RenameFile fail!");
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
BundleFileUtils::RemoveFile(static_cast<char *>(realOldPath));
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t BundleDaemonHandler::RemoveFile(const char *filePath)
|
||||
{
|
||||
char realFilePath[PATH_MAX + 1] = { '\0' };
|
||||
if (filePath == nullptr || realpath(filePath, realFilePath) == nullptr) {
|
||||
PRINTE("BundleDaemonHandler", "realPath fail!");
|
||||
return EC_INVALID;
|
||||
}
|
||||
if (!IsValideJsonPath(realFilePath) && !IsValideSystemPath(realFilePath) &&
|
||||
!IsValideCodePath(realFilePath)) {
|
||||
PRINTE("BundleDaemonHandler", "file path is invalid");
|
||||
return EC_INVALID;
|
||||
}
|
||||
if (!BundleFileUtils::RemoveFile(realFilePath)) {
|
||||
PRINTE("BundleDaemonHandler", "clear content to file fail");
|
||||
return EC_NODIR;
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
bool BundleDaemonHandler::IsValideCodePath(const char *codePath)
|
||||
{
|
||||
if (codePath == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return BundleFileUtils::IsValidPath(STORAGE + HAP_CODE_PATH, codePath) ||
|
||||
BundleFileUtils::IsValidPath(SDCARD + HAP_CODE_PATH, codePath);
|
||||
}
|
||||
|
||||
bool BundleDaemonHandler::IsValideDataPath(const char *dataPath)
|
||||
{
|
||||
if (dataPath == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return BundleFileUtils::IsValidPath(STORAGE + HAP_DATA_PATH, dataPath) ||
|
||||
BundleFileUtils::IsValidPath(SDCARD + HAP_DATA_PATH, dataPath);
|
||||
}
|
||||
|
||||
bool BundleDaemonHandler::IsValideJsonPath(const char *jsonPath)
|
||||
{
|
||||
if (jsonPath == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return BundleFileUtils::IsValidPath(STORAGE + JSON_PATH, jsonPath);
|
||||
}
|
||||
|
||||
bool BundleDaemonHandler::IsValideSystemPath(const char *path)
|
||||
{
|
||||
if (path == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return BundleFileUtils::IsValidPath(SYSTEM_HAP_PATH, path) ||
|
||||
BundleFileUtils::IsValidPath(THIRD_HAP_PATH, path);
|
||||
}
|
||||
} // OHOS
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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 "bundle_file_utils.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "bundle_daemon_log.h"
|
||||
#include "securec.h"
|
||||
|
||||
namespace OHOS {
|
||||
bool BundleFileUtils::IsExistDir(const char *path)
|
||||
{
|
||||
if (path == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct stat buf = {};
|
||||
if (stat(path, &buf) != 0) {
|
||||
return false;
|
||||
}
|
||||
return S_ISDIR(buf.st_mode);
|
||||
}
|
||||
|
||||
bool BundleFileUtils::IsExistFile(const char *file)
|
||||
{
|
||||
if (file == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct stat buf = {};
|
||||
if (stat(file, &buf) != 0) {
|
||||
return false;
|
||||
}
|
||||
return S_ISREG(buf.st_mode);
|
||||
}
|
||||
|
||||
bool BundleFileUtils::MkRecursiveDir(const char *dir, bool isReadOthers)
|
||||
{
|
||||
if (dir == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (IsExistDir(dir)) {
|
||||
return true;
|
||||
}
|
||||
size_t len = strlen(dir);
|
||||
if (len == 0 || len > PATH_MAX) {
|
||||
return false;
|
||||
}
|
||||
// Create directories level by level
|
||||
char rootDir[PATH_MAX] = { '\0' };
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
rootDir[i] = dir[i];
|
||||
if ((rootDir[i] == PATH_SEPARATOR || i == (len - 1)) && !IsExistDir(rootDir)) {
|
||||
mode_t mode = S_IRWXU | S_IRWXG | S_IXOTH;
|
||||
mode |= (isReadOthers ? S_IROTH : 0);
|
||||
if (mkdir(rootDir, mode) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BundleFileUtils::RemoveFile(const char *path)
|
||||
{
|
||||
if (IsExistFile(path)) {
|
||||
return remove(path) == 0;
|
||||
} else if (IsExistDir(path)) {
|
||||
DIR *dir = opendir(path);
|
||||
if (dir == nullptr) {
|
||||
return false;
|
||||
}
|
||||
struct dirent *dp = nullptr;
|
||||
// Remove file before delete the directory
|
||||
while ((dp = readdir(dir)) != nullptr) {
|
||||
if ((strcmp(dp->d_name, ".") == 0) || (strcmp(dp->d_name, "..")) == 0) {
|
||||
continue;
|
||||
}
|
||||
std::string dirName = std::string(path) + "/" + dp->d_name;
|
||||
if (dirName.length() >= PATH_MAX || !RemoveFile(dirName.c_str())) {
|
||||
closedir(dir);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
return remove(path) == 0;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool BundleFileUtils::RenameFile(const char *oldFile, const char *newFile)
|
||||
{
|
||||
if (oldFile == nullptr || newFile == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (!RemoveFile(newFile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return rename(oldFile, newFile) == 0;
|
||||
}
|
||||
|
||||
bool BundleFileUtils::ChownFile(const char *file, int32_t uid, int32_t gid)
|
||||
{
|
||||
if (file == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return chown(file, uid, gid) == 0;
|
||||
}
|
||||
|
||||
bool BundleFileUtils::WriteFile(const char *file, const void *buffer, uint32_t size)
|
||||
{
|
||||
if (file == nullptr || buffer == nullptr || size == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t fp = open(file, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
if (fp < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (write(fp, buffer, size) != static_cast<int32_t>(size)) {
|
||||
close(fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
close(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BundleFileUtils::IsValidPath(const std::string &rootDir, const std::string &path)
|
||||
{
|
||||
if (rootDir.find(PATH_SEPARATOR) != 0 || rootDir.rfind(PATH_SEPARATOR) != (rootDir.size() - 1) ||
|
||||
rootDir.find("..") != std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
if (path.find("..") != std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
return path.compare(0, rootDir.size(), rootDir) == 0;
|
||||
}
|
||||
|
||||
std::string BundleFileUtils::GetPathDir(const std::string &path)
|
||||
{
|
||||
std::size_t pos = path.rfind(PATH_SEPARATOR);
|
||||
if (pos == std::string::npos) {
|
||||
return std::string();
|
||||
}
|
||||
return path.substr(0, pos + 1);
|
||||
}
|
||||
} // OHOS
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 "bundlems_client.h"
|
||||
|
||||
#include "bundle_daemon_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
BundleMsClient::BundleMsClient(const SvcIdentity &svcIdentity)
|
||||
: svcIdentity_(svcIdentity)
|
||||
{
|
||||
}
|
||||
|
||||
int32 BundleMsClient::SendReply(int32 result)
|
||||
{
|
||||
IpcIo request;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0);
|
||||
IpcIoPushInt32(&request, result);
|
||||
return Transact(nullptr, svcIdentity_, BDS_CALLBACK, &request, nullptr, LITEIPC_FLAG_ONEWAY, nullptr);
|
||||
}
|
||||
} // 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 <unistd.h>
|
||||
#ifdef __LINUX__
|
||||
#include <ctime>
|
||||
#endif
|
||||
|
||||
#include "samgr_lite.h"
|
||||
|
||||
extern "C" void __attribute__((weak)) HOS_SystemInit(void)
|
||||
{
|
||||
SAMGR_Bootstrap();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#ifdef __LINUX__
|
||||
// wait samgr to start
|
||||
sleep(1);
|
||||
#endif
|
||||
HOS_SystemInit();
|
||||
while (true) {
|
||||
pause();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 BUNDLE_APP_INFO_H
|
||||
#define BUNDLE_APP_INFO_H
|
||||
|
||||
#include "ohos_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef enum {
|
||||
BUNDLE_INSTALL_DOING = 0,
|
||||
BUNDLE_INSTALL_OK = 1,
|
||||
BUNDLE_INSTALL_FAIL = 2
|
||||
} InstallState;
|
||||
|
||||
/* update bundle state to UI task */
|
||||
typedef enum {
|
||||
BUNDLE_INSTALL,
|
||||
BUNDLE_UNINSTALL,
|
||||
BUNDLE_UPDATE,
|
||||
} BundleState;
|
||||
|
||||
typedef struct {
|
||||
char *bundleName;
|
||||
char *label;
|
||||
char *smallIconPath;
|
||||
char *bigIconPath;
|
||||
InstallState installState;
|
||||
uint8 installProcess;
|
||||
} BundleInstallMsg;
|
||||
|
||||
/**
|
||||
* add for app market
|
||||
*/
|
||||
int BundleCallbackFunc(unsigned char operationResult, const char *bundleName, unsigned char errorcode);
|
||||
|
||||
int ReportSystemBundleInstallProcess(unsigned char process, const char *bundleName, unsigned char installState);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* BUNDLE_APP_INFO_H */
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
* 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_BUNDLE_COMMON_H
|
||||
#define OHOS_BUNDLE_COMMON_H
|
||||
|
||||
#include "pms.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "module_info.h"
|
||||
#include "stdint.h"
|
||||
|
||||
namespace OHOS {
|
||||
const char PROFILE_NAME[] = "config.json";
|
||||
const char JSON_SUFFIX[] = ".json";
|
||||
const char PATH_SEPARATOR[] = "/";
|
||||
const char FILE_DELIMITER[] = "_";
|
||||
const char MODULE_ENTRY[] = "entry";
|
||||
const char MODULE_FEATURE[] = "feature";
|
||||
const uint16_t PATH_LENGTH = 256;
|
||||
const uint8_t ICON_NUM = 2;
|
||||
const uint16_t MAX_METADATA_NAME = 255;
|
||||
const uint16_t MAX_METADATA_VALUE = 255;
|
||||
const uint16_t MAX_NAME_LEN = 255;
|
||||
const uint16_t MAX_DECRIPTION_LEN = 255;
|
||||
const uint16_t MAX_VENDOR_LEN = 255;
|
||||
const uint8_t MAX_MODULENAME_LEN = 31;
|
||||
const uint8_t MAX_ABILITY_NAME_LEN = 255;
|
||||
const int8_t PROFILE_INVALID = -1;
|
||||
const int8_t BUNDLENAME_INVALID = -2;
|
||||
const int8_t VERSION_CODE_INVALID = -3;
|
||||
const uint8_t MAX_SINGLE_DIGIT_VALUE = 10;
|
||||
const uint8_t ZERO_ASCII_NUM = 48;
|
||||
// bundle type
|
||||
const uint8_t SYSTEM_APP_FLAG = 0;
|
||||
const uint8_t THIRD_SYSTEM_APP_FLAG = 1;
|
||||
const uint8_t THIRD_APP_FLAG = 2;
|
||||
|
||||
const uint8_t MIN_BUNDLE_NAME_LEN = 7;
|
||||
const uint8_t MAX_BUNDLE_NAME_LEN = 127;
|
||||
|
||||
const char LABEL_ID[] = "labelId";
|
||||
const char ICON_ID[] = "iconId";
|
||||
const char MODULE_DES_ID[] = "descriptionId";
|
||||
const char ABILITY_DES_ID[] = "descriptionId";
|
||||
const char RESOURCES_INDEX[] = "/resources.index";
|
||||
const char DEFAULT_LABEL_SETTING[] = "$string:";
|
||||
const char DEFAULT_DESC_SETTING[] = "$string:";
|
||||
const char DEFAULT_ICON_SETTING_BEGIN[] = "$media:";
|
||||
// app config
|
||||
const char PROFILE_KEY_APP[] = "app";
|
||||
const char PROFILE_KEY_VENDOR[] = "vendor";
|
||||
const char PROFILE_KEY_BUNDLENAME[] = "bundleName";
|
||||
const char PROFILE_KEY_VERSION[] = "version";
|
||||
const char PROFILE_KEY_VERSION_CODE[] = "code";
|
||||
const char PROFILE_KEY_VERSION_NAME[] = "name";
|
||||
const char PROFILE_KEY_APIVERSION[] = "apiVersion";
|
||||
const char PROFILE_KEY_APIVERSION_COMPATIBLE[] = "compatible";
|
||||
const char PROFILE_KEY_APIVERSION_TARGET[] = "target";
|
||||
// deviceConfig
|
||||
const char PROFILE_KEY_DEVICECONFIG[] = "deviceConfig";
|
||||
const char PROFILE_KEY_DEVICECONFIG_DEFAULT[] = "default";
|
||||
const char PROFILE_KEY_KEEPALIVE[] = "keepAlive";
|
||||
// module config
|
||||
const char PROFILE_KEY_MODULE[] = "module";
|
||||
const char PROFILE_KEY_MODULE_NAME[] = "name";
|
||||
const char PROFILE_KEY_MODULE_DESCRIPTION[] = "description";
|
||||
const char PROFILE_KEY_MODULE_DEVICETYPE[] = "deviceType";
|
||||
const char PROFILE_KEY_MODULE_DISTRO[] = "distro";
|
||||
const char PROFILE_KEY_MODULE_DISTRO_DELIVERY[] = "deliveryWithInstall";
|
||||
const char PROFILE_KEY_MODULE_DISTRO_MODULENAME[] = "moduleName";
|
||||
const char PROFILE_KEY_MODULE_DISTRO_MODULETYPE[] = "moduleType";
|
||||
const char PROFILE_KEY_MODULE_METADATA[] = "metaData";
|
||||
const char PROFILE_KEY_MODULE_METADATA_CUSTOMIZEDATA[] = "customizeData";
|
||||
const char PROFILE_KEY_MODULE_METADATA_NAME[] = "name";
|
||||
const char PROFILE_KEY_MODULE_METADATA_VALUE[] = "value";
|
||||
const char PROFILE_KEY_MODULE_METADATA_EXTRA[] = "extra";
|
||||
const char PROFILE_KEY_MODULE_ABILITIES[] = "abilities";
|
||||
const char PROFILE_KEY_MODULE_ABILITY_NAME[] = "name";
|
||||
const char PROFILE_KEY_MODULE_ABLLITY_DESCRIPTION[] = "description";
|
||||
const char PROFILE_KEY_MODULE_ABILITY_LABEL[] = "label";
|
||||
const char PROFILE_KEY_MODULE_ABILITY_ICON[] = "icon";
|
||||
const char PROFILE_KEY_MODULE_ABILITY_TYPE[] = "type";
|
||||
const char PROFILE_KEY_MODULE_ABILITY_LAUNCHTYPE[] = "launchType";
|
||||
const char PROFILE_KEY_MODULE_ABILITY_VISIBLE[] = "visible";
|
||||
const char PROFILE_KEY_MODULE_ABILITY_DEVICE_CAP[] = "deviceCapability";
|
||||
// js config
|
||||
const char PROFILE_KEY_JS[] = "js";
|
||||
|
||||
const char PROFILE_KEY_REQPERMISSIONS[] = "reqPermissions";
|
||||
const char PROFILE_KEY_REQPERMISSIONS_NAME[] = "name";
|
||||
const char PROFILE_KEY_REQPERMISSIONS_REASON[] = "reason";
|
||||
const char PROFILE_KEY_REQPERMISSIONS_USEDSCENE[] = "usedScene";
|
||||
const char PROFILE_KEY_REQPERMISSIONS_WHEN[] = "when";
|
||||
|
||||
const char ASSETS[] = "/assets/";
|
||||
|
||||
const char GRANTTIME_INUSE[] = "inuse";
|
||||
const char GRANTTIME_ALWAYS[] = "always";
|
||||
// shared lib path
|
||||
const char SHARED_LIB_NAME[] = "shared_libs";
|
||||
const char SHARED_LIB_PATH[] = "/storage/app/libs";
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
const char DEFAULT_DEVICE_TYPE[] = "smartVision";
|
||||
const char INSTALL_PATH[] = "/storage/app/run";
|
||||
const char DATA_PATH[] = "/storage/app/data";
|
||||
const char JSON_PATH[] = "/storage/app/etc/bundles/";
|
||||
const char EXTEANAL_INSTALL_PATH[] = "/sdcard/app/run";
|
||||
const char EXTEANAL_DATA_PATH[] = "/sdcard/app/data";
|
||||
const char SYSTEM_BUNDLE_PATH[] = "/system/internal";
|
||||
const char THIRD_SYSTEM_BUNDLE_PATH[] = "/system/external";
|
||||
const char UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON[] = "/storage/app/etc/uninstalled_delbundle.json";
|
||||
const char THIRD_SYSTEM_BUNDLE_JSON[] = "/storage/app/etc/third_system_bundle.json";
|
||||
const char UID_GID_MAP[] = "uid_gid_map";
|
||||
const char INSTALL_FILE_SUFFIX[] = ".hap";
|
||||
// uid and gid
|
||||
const int8_t INVALID_UID = -1;
|
||||
const int8_t INVALID_GID = -1;
|
||||
const uint32_t BASE_SYS_UID = 100;
|
||||
const uint32_t BASE_SYS_VEN_UID = 1000;
|
||||
const uint32_t MAX_SYS_VEN_UID = 9999;
|
||||
const uint32_t BASE_APP_UID = 10000;
|
||||
const char PROFILE_KEY_UID_SIZE[] = "size";
|
||||
const char PROFILE_KEY_UID_AND_GID[] = "uid_and_gid";
|
||||
|
||||
const uint8_t MAX_VERSION_NAME_LEN = 127;
|
||||
const uint16_t MAX_LABLE_LEN = 255;
|
||||
#else
|
||||
const char DEFAULT_DEVICE_TYPE[] = "fitnessWatch";
|
||||
const char INSTALL_PATH[] = "user/ace/run";
|
||||
const char DATA_PATH[] = "user/ace/data";
|
||||
const char SYSTEM_BUNDLE_PATH[] = "system/ace/sys";
|
||||
const char THIRD_SYSTEM_BUNDLE_PATH[] = "system/ace/vendor";
|
||||
const char UNINSTALL_THIRD_SYSTEM_BUNDLE_JSON[] = "user/ace/etc/uninstalled_delbundle.json";
|
||||
const char THIRD_SYSTEM_BUNDLE_JSON[] = "user/ace/etc/third_system_bundle.json";
|
||||
const char JSON_PATH[] = "user/ace/etc/bundles/";
|
||||
const char JSON_PATH_NO_SLASH_END[] = "user/ace/etc/bundles";
|
||||
// store bundle permissions for IAM
|
||||
const char PERMISSIONS_PATH[] = "user/ace/etc/permissions";
|
||||
const char ASSET_JS_PATH[] = "/assets/js/default";
|
||||
const char ICON_NAME[] = "/icon.bin";
|
||||
const char SMALL_ICON_NAME[] = "/icon_small.bin";
|
||||
const char DEFAULT_ICON_SETTING[] = "$media:icon";
|
||||
const char INSTALL_FILE_SUFFIX[] = ".bin";
|
||||
const char TMP_RESOURCE_DIR[] = "user/ace/run/tmpResource";
|
||||
const char RESOURCES_RAW_FILE[] = "/resources/rawfile";
|
||||
const char RAW_FILE[] = "/rawfile";
|
||||
const uint16_t READ_SIZE = 1024 * 4;
|
||||
const uint8_t MAGIC_NUMBER_LEN = 1;
|
||||
const uint8_t INT_LENGTH = 4;
|
||||
const uint8_t LONG_LENGTH = 8;
|
||||
const uint16_t MAX_INT = 256;
|
||||
const uint8_t MAX_VERSION_NAME_LEN = 20;
|
||||
const uint8_t MAX_LABLE_LEN = 30;
|
||||
const uint8_t MAX_THIRD_BUNDLE_NUMBER = 30;
|
||||
|
||||
struct SignatureInfo {
|
||||
char *bundleName;
|
||||
char *appId;
|
||||
char **restricPermission;
|
||||
uint32_t restricNum;
|
||||
};
|
||||
#endif
|
||||
// InstallRecord key
|
||||
const char JSON_MAIN_KEY[] = "packages";
|
||||
const char JSON_SUB_KEY_PACKAGE[] = "bundleName";
|
||||
const char JSON_SUB_KEY_CODEPATH[] = "codePath";
|
||||
const char JSON_SUB_KEY_APPID[] = "appID";
|
||||
const char JSON_SUB_KEY_VERSIONCODE[] = "versionCode";
|
||||
const char JSON_SUB_KEY_JSENGINE_VERSION[] = "JsEngineVersion";
|
||||
const char JSON_SUB_KEY_TRANSFORM_RESULT[] = "transformResult";
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
const char JSON_SUB_KEY_UID[] = "uid";
|
||||
const char JSON_SUB_KEY_GID[] = "gid";
|
||||
#endif
|
||||
|
||||
struct ProfileVersion {
|
||||
uint32_t versionCode;
|
||||
char *versionName;
|
||||
};
|
||||
|
||||
struct ProfileApiVersion {
|
||||
int32_t minApiVersion;
|
||||
int32_t maxApiVersion;
|
||||
};
|
||||
|
||||
struct AbilityRes {
|
||||
uint32_t iconId;
|
||||
uint32_t labelId;
|
||||
uint32_t descriptionId;
|
||||
uint32_t index;
|
||||
};
|
||||
|
||||
struct BundleRes {
|
||||
char *bundleName;
|
||||
uint32_t moduleDescriptionId;
|
||||
AbilityRes *abilityRes;
|
||||
uint32_t totalNumOfAbilityRes;
|
||||
};
|
||||
|
||||
struct BundleProfile {
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
bool isKeepAlive;
|
||||
bool isNativeApp;
|
||||
#endif
|
||||
char *bundleName;
|
||||
char *vendor;
|
||||
char *label;
|
||||
char *iconPath;
|
||||
ProfileVersion profileVersion;
|
||||
ProfileApiVersion profileApiVersion;
|
||||
ModuleInfo moduleInfo;
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
AbilityInfo *abilityInfos;
|
||||
uint32_t numOfAbility;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct Permissions {
|
||||
int32_t permNum;
|
||||
PermissionTrans *permissionTrans;
|
||||
};
|
||||
|
||||
struct InstallRecord {
|
||||
char *bundleName;
|
||||
char *codePath;
|
||||
char *appId; // it contains bundleName and cert publicKey
|
||||
#ifndef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
#ifndef __LINUX__
|
||||
#ifdef BC_TRANS_ENABLE
|
||||
char *jsEngineVersion;
|
||||
int32_t transformResult; // 0: success, -1: fail
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
int32_t versionCode;
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
int32_t uid;
|
||||
int32_t gid;
|
||||
#endif
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLE_COMMON_H
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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_BUNLDE_DAEMON_CLIENT_H
|
||||
#define OHOS_BUNLDE_DAEMON_CLIENT_H
|
||||
|
||||
#include <semaphore.h>
|
||||
|
||||
#include "ohos_errno.h"
|
||||
#include "iproxy_client.h"
|
||||
#include "liteipc_adapter.h"
|
||||
#include "mutex_lock.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
class BundleDaemonClient : public NoCopyable {
|
||||
public:
|
||||
static BundleDaemonClient &GetInstance()
|
||||
{
|
||||
static BundleDaemonClient instance;
|
||||
return instance;
|
||||
}
|
||||
bool Initialize();
|
||||
int32_t ExtractHap(const char *hapFile, const char *codePath);
|
||||
int32_t RenameFile(const char *oldFile, const char *newFile);
|
||||
int32_t CreatePermissionDir();
|
||||
int32_t CreateDataDirectory(const char *dataPath, int32_t uid, int32_t gid, bool isChown);
|
||||
int32_t StoreContentToFile(const char *file, const void *buffer, uint32_t size);
|
||||
int32_t MoveFile(const char *oldFile, const char *newFile);
|
||||
int32_t RemoveFile(const char *file);
|
||||
int32_t RemoveInstallDirectory(const char *codePath, const char *dataPath, bool keepData);
|
||||
int32_t CallClientInvoke(int32_t funcId, const char *firstPath, const char *secondPath);
|
||||
static int32_t BundleDaemonCallback(const IpcContext* context, void *ipcMsg, IpcIo *io, void *arg);
|
||||
static int32_t DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* arg);
|
||||
static int Notify(IOwner owner, int code, IpcIo *reply);
|
||||
|
||||
private:
|
||||
BundleDaemonClient() = default;
|
||||
~BundleDaemonClient();
|
||||
|
||||
IClientProxy *bdsClient_ { nullptr };
|
||||
SvcIdentity svcIdentity_ {};
|
||||
SvcIdentity bdsSvcIdentity_ {};
|
||||
uint32_t cbid_ = INVALID_INDEX;
|
||||
sem_t sem_;
|
||||
Mutex mutex_;
|
||||
int32_t result_ = EC_FAILURE;
|
||||
bool initialized_ = false;
|
||||
|
||||
static void *RegisterDeathCallback(void *);
|
||||
int32_t RegisterCallback();
|
||||
int32_t WaitResultSync(int32_t result);
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNLDE_DAEMON_CLIENT_H
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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_BUNDLE_EXTRACTOR_H
|
||||
#define OHOS_BUNDLE_EXTRACTOR_H
|
||||
|
||||
#include "stdint.h"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
class BundleExtractor {
|
||||
public:
|
||||
static uint8_t ExtractHapProfile(const std::string &hapFile, std::ostringstream &profileStream);
|
||||
private:
|
||||
BundleExtractor() = default;
|
||||
~BundleExtractor() = default;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLE_EXTRACTOR_H
|
||||
+43
@@ -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_BUNDLE_INFO_CREATOR_H
|
||||
#define OHOS_BUNDLE_INFO_CREATOR_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "bundle_common.h"
|
||||
#include "bundle_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
class BundleInfoCreator {
|
||||
public:
|
||||
BundleInfoCreator() = default;
|
||||
~BundleInfoCreator() = default;
|
||||
|
||||
static BundleInfo *CreateBundleInfo(const BundleProfile &bundleProfile, const std::string &installDirPath,
|
||||
const std::string &dataDirPath, const BundleRes &bundleRes);
|
||||
static uint8_t SaveBundleInfo(const BundleProfile &bundleProfile, BundleInfo **bundleInfo);
|
||||
private:
|
||||
static bool SetBundleInfo(const BundleProfile &bundleProfile, const std::string &installDirPath,
|
||||
const std::string &dataDirPath, BundleInfo *bundleInfo);
|
||||
static bool SetModuleInfos(const BundleProfile &bundleProfile, BundleInfo *bundleInfo);
|
||||
static bool SetAbilityInfos(const BundleProfile &bundleProfile, const std::string &codePath,
|
||||
BundleInfo *bundleInfo);
|
||||
static bool SetAbilityInfo(const BundleProfile &bundleProfile, const std::string &codePath,
|
||||
BundleInfo *bundleInfo, uint32_t index);
|
||||
}; // namespace OHOS
|
||||
}
|
||||
#endif // OHOS_BUNDLE_INFO_CREATOR_H
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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_BUNDLE_INNER_FEATURE_H
|
||||
#define OHOS_BUNDLE_INNER_FEATURE_H
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "bundle_inner_interface.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "feature.h"
|
||||
#include "iproxy_server.h"
|
||||
#include "iunknown.h"
|
||||
#include "nocopyable.h"
|
||||
#include "ohos_types.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
typedef uint8_t (*BundleInvokeType)(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
|
||||
struct SvcIdentityInfo {
|
||||
char *path;
|
||||
char *bundleName;
|
||||
SvcIdentity *svc;
|
||||
int32_t installLocation;
|
||||
bool keepData;
|
||||
};
|
||||
|
||||
class BundleInnerFeature : private Feature {
|
||||
public:
|
||||
static BundleInnerFeature *GetInstance()
|
||||
{
|
||||
static BundleInnerFeature instance;
|
||||
return &instance;
|
||||
}
|
||||
~BundleInnerFeature();
|
||||
static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply);
|
||||
|
||||
private:
|
||||
BundleInnerFeature();
|
||||
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);
|
||||
|
||||
static uint8_t InstallInnerBundle(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
static uint8_t GetSvcIdentityInfo(
|
||||
OHOS::SvcIdentityInfo *info, const SvcIdentity *svc, const char *reqPath, IpcIo *req);
|
||||
static uint8_t UninstallInnerBundle(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
#ifdef OHOS_DEBUG
|
||||
static uint8_t SetExternalInstallMode(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
static uint8_t SetInnerDebugMode(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
static uint8_t SetInnerSignMode(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
#endif
|
||||
|
||||
Identity identity_;
|
||||
static BundleInvokeType BundleMsInvokeFuc[BMS_CMD_END - BMS_INNER_BEGIN];
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(BundleInnerFeature);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
INHERIT_IUNKNOWNENTRY(BmsInnerServerProxy);
|
||||
BundleInnerFeature *bundleInnerFeature;
|
||||
} BmsInnerImpl;
|
||||
|
||||
IUnknown *GetBmsInnerFeatureApi(Feature *feature);
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLE_INNER_FEATURE_H
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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_BUNDLE_INSTALLER_H
|
||||
#define OHOS_BUNDLE_INSTALLER_H
|
||||
|
||||
#include "bundle_common.h"
|
||||
#include "bundle_info.h"
|
||||
#include "bundle_info_utils.h"
|
||||
#include "install_param.h"
|
||||
#include "hap_sign_verify.h"
|
||||
#include "stdint.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
class BundleInstaller {
|
||||
public:
|
||||
BundleInstaller(const std::string &codeDirPath, const std::string &dataDirPath);
|
||||
~BundleInstaller();
|
||||
|
||||
uint8_t Install(const char *path, const InstallParam &installParam);
|
||||
uint8_t Uninstall(const char *bundleName, const InstallParam &installParam);
|
||||
std::string GetCodeDirPath() const;
|
||||
std::string GetDataDirPath() const;
|
||||
private:
|
||||
uint8_t ProcessBundleInstall(const std::string &path, const char *randStr, InstallRecord &installRecord,
|
||||
uint8_t hapType);
|
||||
uint8_t HandleFileAndBackUpRecord(const char *codePath, const char *randStr, InstallRecord &record,
|
||||
bool isUpdate, uint8_t hapType);
|
||||
uint8_t UpdateBundleInfo(const char *appId, const BundleRes &bundleRes, BundleInfo *bundleInfo, bool isUpdate,
|
||||
uint8_t hapType);
|
||||
uint8_t ReshapeAppId(const char *bundleName, std::string &appId);
|
||||
uint8_t CheckProvisionInfoIsValid(const SignatureInfo &signatureInfo, const Permissions &permissions,
|
||||
const char *bundleName);
|
||||
bool MatchPermissions(const std::vector<std::string> & restrictedPermissions,
|
||||
PermissionTrans *permissionsTrans, int32_t permTransNum);
|
||||
bool MatchBundleName(const char *bundleName, const char *matchedBundleName);
|
||||
uint8_t CheckInstallFileIsValid(const char *path);
|
||||
void RecordThirdSystemBundle(const char *bundleName, const char *path);
|
||||
uint8_t StorePermissions(const char *bundleName, PermissionTrans *permissions, int32_t permNum, bool isUpdate);
|
||||
uint8_t CheckVersionAndSignature(const char *bundleName, BundleInfo *bundleInfo);
|
||||
bool RenameJsonFile(const char *fileName, const char *randStr);
|
||||
bool CheckIsThirdSystemBundle(const char *bundleName);
|
||||
bool BackUpInstallRecord(const InstallRecord &record, const char *jsonPath);
|
||||
void InitThirdSystemBundleRecord(const char *bundleName, const char *path);
|
||||
bool BackUpUidAndGidInfo(const InstallRecord &record, const char *jsonPath);
|
||||
void ModifyInstallDirByHapType(const InstallParam &installParam, uint8_t hapType);
|
||||
uint8_t GetHapType(const char *path);
|
||||
void RestoreInstallEnv(const InstallParam &installParam);
|
||||
uint8_t CheckDeviceCapIsValid(BundleInfo *bundleInfo);
|
||||
bool CheckAbilityCapIsValid(AbilityInfo *abilityInfo, char sysCaps[][MAX_SYSCAP_NAME_LEN], int32_t sysNum);
|
||||
|
||||
std::string codeDirPath_;
|
||||
std::string dataDirPath_;
|
||||
};
|
||||
|
||||
#define CHECK_PRO_RESULT(errcode, bundleInfo, permissions, abilityRes) \
|
||||
do { \
|
||||
if (errcode != ERR_OK) { \
|
||||
BundleInfoUtils::FreeBundleInfo(bundleInfo); \
|
||||
AdapterFree(permissions.permissionTrans); \
|
||||
AdapterFree(abilityRes); \
|
||||
return errcode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CLEAR_INSTALL_ENV(bundleInfo) \
|
||||
do { \
|
||||
if (bundleInfo != nullptr) { \
|
||||
BundleDaemonClient::GetInstance().RemoveInstallDirectory( \
|
||||
bundleInfo->codePath, bundleInfo->dataPath, false); \
|
||||
BundleInfoUtils::FreeBundleInfo(bundleInfo); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_PRO_PART_ROLLBACK(errcode, path, permissions, bundleInfo, abilityRes) \
|
||||
do { \
|
||||
if (errcode != ERR_OK && bundleInfo != nullptr) { \
|
||||
BundleDaemonClient::GetInstance().RemoveFile(path.c_str()); \
|
||||
BundleInfoUtils::FreeBundleInfo(bundleInfo); \
|
||||
AdapterFree(permissions.permissionTrans); \
|
||||
AdapterFree(abilityRes); \
|
||||
return errcode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_PRO_ROLLBACK(errcode, permissions, bundleInfo, abilityRes, randStr) \
|
||||
do { \
|
||||
if (errcode != ERR_OK && bundleInfo != nullptr) { \
|
||||
AdapterFree(permissions.permissionTrans); \
|
||||
AdapterFree(abilityRes); \
|
||||
ManagerService::GetInstance().RemoveBundleInfo(bundleInfo->bundleName); \
|
||||
BundleUtil::DeleteJsonFile(bundleInfo->bundleName, randStr); \
|
||||
CLEAR_INSTALL_ENV(bundleInfo); \
|
||||
return errcode; \
|
||||
} \
|
||||
} while (0)
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLE_INSTALLER_H
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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_BUNDLE_LOG_H
|
||||
#define OHOS_BUNDLE_LOG_H
|
||||
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "bundlems"
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN 0xD001100
|
||||
|
||||
#define PRINTD(name, fmt, ...) HILOG_DEBUG(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define PRINTI(name, fmt, ...) HILOG_INFO(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define PRINTW(name, fmt, ...) HILOG_WARN(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define PRINTE(name, fmt, ...) HILOG_ERROR(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
}
|
||||
#endif // OHOS_BUNDLE_LOG_H
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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_BUNDLE_MANAGER_SERVICE_H
|
||||
#define OHOS_BUNDLE_MANAGER_SERVICE_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "ability_service_interface.h"
|
||||
#include "adapter.h"
|
||||
#include "bundle_installer.h"
|
||||
#include "bundle_info.h"
|
||||
#include "bundle_map.h"
|
||||
#include "cJSON.h"
|
||||
#include "message.h"
|
||||
#include "nocopyable.h"
|
||||
#include "stdint.h"
|
||||
|
||||
namespace OHOS {
|
||||
class ManagerService {
|
||||
public:
|
||||
static ManagerService &GetInstance()
|
||||
{
|
||||
static ManagerService instance;
|
||||
return instance;
|
||||
}
|
||||
void ServiceMsgProcess(Request *request);
|
||||
BundleInfo *QueryBundleInfo(const char *bundleName);
|
||||
void RemoveBundleInfo(const char *bundleName);
|
||||
void AddBundleInfo(BundleInfo *info);
|
||||
bool UpdateBundleInfo(BundleInfo *info);
|
||||
uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo& bundleInfo);
|
||||
uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
std::vector<SvcIdentity> GetServiceId() const;
|
||||
int32_t GenerateUid(const char *bundleName, int8_t bundleStyle);
|
||||
void RecycleUid(const char *bundleName);
|
||||
static bool GetAmsInterface(AmsInnerInterface **amsInterface);
|
||||
std::string GetCodeDirPath() const;
|
||||
std::string GetDataDirPath() const;
|
||||
uint8_t SetExternalInstallMode(bool enable);
|
||||
bool IsExternalInstallMode() const;
|
||||
uint8_t SetDebugMode(bool enable);
|
||||
bool IsDebugMode() const;
|
||||
bool HasSystemCapability(const char *bundleName);
|
||||
uint8_t GetSystemAvailableCapabilities(char syscap[][MAX_SYSCAP_NAME_LEN], int32_t *len);
|
||||
#ifdef OHOS_DEBUG
|
||||
uint8_t SetSignMode(bool enable);
|
||||
bool IsSignMode() const;
|
||||
#endif
|
||||
private:
|
||||
ManagerService();
|
||||
~ManagerService();
|
||||
|
||||
void ScanPackages();
|
||||
void ScanSharedLibPath();
|
||||
void ScanAppDir(const char *appDir, const cJSON *uninstallRecord, uint8_t scanFlag);
|
||||
void InstallAllSystemBundle(int32_t scanFlag);
|
||||
void InstallSystemBundle(const char *fileDir, const char *fileName);
|
||||
void ReloadBundleInfo(const char *codePath, const char *appId, const char *bundleName, bool isSystemApp);
|
||||
void ReloadEntireBundleInfo(const char *appPath, const char *bundleName, int32_t versionCode, uint8_t scanFlag);
|
||||
bool CheckSystemBundleIsValid(const char *appPath, char **bundleName, int32_t &versionCode);
|
||||
bool CheckThirdSystemBundleHasUninstalled(const char *bundleName, const cJSON *object);
|
||||
void InstallThirdBundle(const char *path, const SvcIdentity &svc, int32_t installLocation);
|
||||
void AddCallbackServiceId(const SvcIdentity &svc);
|
||||
void RemoveCallbackServiceId(const SvcIdentity &svc);
|
||||
void RestoreUidAndGidMap();
|
||||
bool RecycleInnerUid(const std::string &bundleName, std::map<int, std::string> &innerMap);
|
||||
|
||||
std::map<int, std::string> sysUidMap_;
|
||||
std::map<int, std::string> sysVendorUidMap_;
|
||||
std::map<int, std::string> appUidMap_;
|
||||
BundleInstaller *installer_;
|
||||
BundleMap *bundleMap_;
|
||||
std::vector<SvcIdentity> svcIdentity_;
|
||||
bool IsExternalInstallMode_ { false };
|
||||
bool isDebugMode_ { false };
|
||||
#ifdef OHOS_DEBUG
|
||||
bool isSignMode_ { true };
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(ManagerService);
|
||||
};
|
||||
}
|
||||
#endif // OHOS_BUNDLE_MANAGER_SERVICE_H
|
||||
@@ -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_BUNDLE_MAP_H
|
||||
#define OHOS_BUNDLE_MAP_H
|
||||
|
||||
#include "bundle_info.h"
|
||||
#include "nocopyable.h"
|
||||
#include "stdint.h"
|
||||
#include "utils_list.h"
|
||||
|
||||
namespace OHOS {
|
||||
class BundleMap {
|
||||
public:
|
||||
static BundleMap *GetInstance()
|
||||
{
|
||||
static BundleMap instance;
|
||||
return &instance;
|
||||
}
|
||||
~BundleMap();
|
||||
|
||||
void Add(BundleInfo *bundleInfo);
|
||||
bool Update(BundleInfo *bundleInfo);
|
||||
BundleInfo *Get(const char *bundleName) const;
|
||||
uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const;
|
||||
uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo &bundleInfo) const;
|
||||
void Erase(const char *bundleName);
|
||||
void EraseAll();
|
||||
|
||||
private:
|
||||
BundleMap();
|
||||
void GetCopyBundleInfo(uint32_t flags, const BundleInfo *bundleInfo, BundleInfo &newBundleInfo) const;
|
||||
List<BundleInfo *> *bundleInfos_;
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(BundleMap);
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLE_MAP_H
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_BUNDLE_MESSAGE_ID_H
|
||||
#define OHOS_BUNDLE_MESSAGE_ID_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
enum BmsMsgType {
|
||||
BUNDLE_SERVICE_INITED = 0x1100,
|
||||
BUNDLE_INSTALLED,
|
||||
BUNDLE_UPDATED,
|
||||
BUNDLE_UNINSTALLED,
|
||||
BUNDLE_LIST_CHANGED,
|
||||
BUNDLE_INSTALLATION_PROCESS_REPORTED,
|
||||
// The above value is also for watch gt, don't change the order
|
||||
|
||||
BUNDLE_CHANGE_CALLBACK,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif // OHOS_BUNDLE_MESSAGE_ID_H
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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_BUNDLEMGRSERVICE_SERVICE_H
|
||||
#define OHOS_BUNDLEMGRSERVICE_SERVICE_H
|
||||
|
||||
#include "service.h"
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
const unsigned int BMS_INSTALL_MSG = 100;
|
||||
const unsigned int BMS_UNINSTALL_MSG = 101;
|
||||
|
||||
class BundleMgrService : public Service {
|
||||
public:
|
||||
static BundleMgrService *GetInstance()
|
||||
{
|
||||
static BundleMgrService instance;
|
||||
return &instance;
|
||||
}
|
||||
~BundleMgrService() = default;
|
||||
Identity *GetIdentity();
|
||||
|
||||
private:
|
||||
BundleMgrService();
|
||||
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(BundleMgrService);
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLEMGRSERVICE_SERVICE_H
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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_BUNDLEMANAGERSERVICE_SLITE_FEATURE_H
|
||||
#define OHOS_BUNDLEMANAGERSERVICE_SLITE_FEATURE_H
|
||||
|
||||
#include "gt_bundle_manager_service.h"
|
||||
#include "bundle_service_interface.h"
|
||||
#include "feature.h"
|
||||
#include "iproxy_client.h"
|
||||
#include "iunknown.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
const unsigned int BMS_INSTALL_MSG = 100;
|
||||
typedef int32 (*InvokeFunc)(const void *origin, IpcIo *req);
|
||||
|
||||
class BundleMgrSliteFeature : public Feature {
|
||||
public:
|
||||
static bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback);
|
||||
static bool Uninstall(const char *bundleName, const InstallParam *installParam,
|
||||
InstallerCallback installerCallback);
|
||||
static uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo);
|
||||
static uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo);
|
||||
static uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
static int8_t GetInstallState(const char *bundleName);
|
||||
|
||||
static BundleMgrSliteFeature *GetInstance()
|
||||
{
|
||||
static BundleMgrSliteFeature instance;
|
||||
return &instance;
|
||||
}
|
||||
~BundleMgrSliteFeature() = default;
|
||||
Identity *GetIdentity();
|
||||
|
||||
private:
|
||||
BundleMgrSliteFeature();
|
||||
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_;
|
||||
GtManagerService *gtManagerService_;
|
||||
DISALLOW_COPY_AND_MOVE(BundleMgrSliteFeature);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
INHERIT_IUNKNOWNENTRY(BmsSliteInterface);
|
||||
BundleMgrSliteFeature *bms;
|
||||
} BundleMgrSliteFeatureImpl;
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLEMANAGERSERVICE_SLITE_FEATURE_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_BUNDLE_MS_FEATURE_H
|
||||
#define OHOS_BUNDLE_MS_FEATURE_H
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "bundle_inner_interface.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "feature.h"
|
||||
#include "iproxy_server.h"
|
||||
#include "iunknown.h"
|
||||
#include "nocopyable.h"
|
||||
#include "ohos_types.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
typedef uint8_t (*BundleInvokeType)(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
|
||||
class BundleMsFeature : private Feature {
|
||||
public:
|
||||
static BundleMsFeature *GetInstance()
|
||||
{
|
||||
static BundleMsFeature instance;
|
||||
return &instance;
|
||||
}
|
||||
~BundleMsFeature();
|
||||
static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply);
|
||||
static uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo);
|
||||
static uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo);
|
||||
static uint8_t GetBundleInfos(int flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
static uint8_t QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len);
|
||||
static uint8_t GetBundleInfosByMetaData(const char *metaDataKey, BundleInfo **bundleInfos, int32_t *len);
|
||||
static uint8_t GetBundleNameForUid(int32_t uid, char **bundleName);
|
||||
|
||||
private:
|
||||
BundleMsFeature();
|
||||
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);
|
||||
|
||||
bool BundleServiceTaskInit();
|
||||
static uint8_t HandleGetBundleInfos(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
static uint8_t QueryInnerAbilityInfo(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
static uint8_t GetInnerBundleInfo(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
static uint8_t GetInnerBundleNameForUid(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
static uint8_t ChangeInnerCallbackServiceId(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
static uint8_t HasSystemCapability(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
static uint8_t GetSystemAvailableCapabilities(const uint8_t funcId, IpcIo *req, IpcIo *reply);
|
||||
|
||||
Identity identity_;
|
||||
static BundleInvokeType BundleMsInvokeFuc[BMS_INNER_BEGIN];
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(BundleMsFeature);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
INHERIT_IUNKNOWNENTRY(BmsServerProxy);
|
||||
BundleMsFeature *bundleMsFeature;
|
||||
} BmsImpl;
|
||||
|
||||
IUnknown *GetBmsFeatureApi(Feature *feature);
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLE_MS_FEATURE_H
|
||||
+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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_BUNDLE_MS_HOST_H
|
||||
#define OHOS_BUNDLE_MS_HOST_H
|
||||
|
||||
#include "bundle_ms_feature.h"
|
||||
#include "iproxy_server.h"
|
||||
#include "iunknown.h"
|
||||
#include "service.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
class BundleMsHost : private Service {
|
||||
public:
|
||||
static BundleMsHost *GetInstance()
|
||||
{
|
||||
static BundleMsHost instance;
|
||||
return &instance;
|
||||
}
|
||||
~BundleMsHost() = default;
|
||||
|
||||
private:
|
||||
BundleMsHost();
|
||||
|
||||
Identity identity_ { 0 };
|
||||
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);
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(BundleMsHost);
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLE_MS_HOST_H
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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_BUNDLE_PARSER_H
|
||||
#define OHOS_BUNDLE_PARSER_H
|
||||
|
||||
#include "adapter.h"
|
||||
#include "bundle_common.h"
|
||||
#include "bundle_info.h"
|
||||
#include "stdint.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
namespace OHOS {
|
||||
class BundleParser {
|
||||
public:
|
||||
BundleParser() = default;
|
||||
~BundleParser() = default;
|
||||
|
||||
BundleInfo *ParseHapProfile(const char *path);
|
||||
uint8_t ParseHapProfile(const std::string &path, Permissions &permissions, BundleRes &bundleRes,
|
||||
BundleInfo **bundleInfo);
|
||||
static int8_t ParseBundleParam(const char *path, char **bundleName, int32_t &versionCode);
|
||||
private:
|
||||
static uint8_t ParseJsonInfo(const cJSON *appObject, const cJSON *configObject, const cJSON *moduleObject,
|
||||
BundleProfile &bundleProfile, BundleRes &bundleRes);
|
||||
static uint8_t ParseDeviceConfig(const cJSON *configObject, BundleProfile &bundleProfile);
|
||||
static uint8_t ParseModuleInfo(const cJSON *moduleObject, BundleProfile &bundleProfile, BundleRes &bundleRes);
|
||||
static uint8_t ParseModuleMetaData(const cJSON *moduleObject, BundleProfile &bundleProfile);
|
||||
static uint8_t ParseDeviceType(const cJSON *object, BundleProfile &bundleProfile);
|
||||
static uint8_t ParseAbilityInfos(const cJSON *moduleObject, BundleProfile &bundleProfile, BundleRes &bundleRes);
|
||||
static uint8_t ParseAllAbilityInfo(const cJSON *abilityObjects, BundleProfile &bundleProfile,
|
||||
BundleRes &bundleRes);
|
||||
static uint8_t ParseAbilityType(const cJSON *abilityObjectItem, AbilityInfo &abilityInfo);
|
||||
static uint8_t ParseAbilityLauchMode(const cJSON *abilityObjectItem, AbilityInfo &abilityInfo);
|
||||
static uint8_t ParseAbilityVisible(const cJSON *abilityObjectItem, AbilityInfo &abilityInfo);
|
||||
static uint8_t ParseAbilityDeviceCap(const cJSON *abilityObjectItem, AbilityInfo &abilityInfo);
|
||||
static uint8_t ParsePerAbilityInfo(const cJSON *abilityObjectItem, BundleProfile &bundleProfile,
|
||||
AbilityRes &abilityRes, uint32_t index);
|
||||
static uint8_t ParseModuleDesc(const cJSON *moduleObject, BundleProfile &bundleProfile, BundleRes &bundleRes);
|
||||
static uint8_t ParseAbilityDesc(const cJSON *abilityObject, BundleProfile &bundleProfile, AbilityRes &abilityRes,
|
||||
int32_t index);
|
||||
static uint8_t ParseAbilityIcon(const cJSON *abilityObject, BundleProfile &bundleProfile, AbilityRes &abilityRes,
|
||||
int32_t index);
|
||||
static uint8_t ParseAbilityLabel(const cJSON *abilityObject, BundleProfile &bundleProfile, AbilityRes &abilityRes,
|
||||
int32_t index);
|
||||
static char *ParseValue(const cJSON *object, const char *key);
|
||||
static int32_t ParseValue(const cJSON *object, const char *key, int32_t defaultValue);
|
||||
static cJSON *ParseValue(const cJSON *object, const char *key, cJSON *defaultValue);
|
||||
static bool CheckBundleNameIsValid(const char *bundleName);
|
||||
static uint8_t ParsePermissions(const cJSON *object, Permissions &permissions);
|
||||
static bool SetReqPermission(const cJSON *object, PermissionTrans *permission);
|
||||
static bool CheckAbilityCapIsValid(AbilityInfo &abilityInfo, char sysCaps[][MAX_SYSCAP_NAME_LEN],
|
||||
int sysNum);
|
||||
static uint8_t CheckDeviceCapIsValid(BundleProfile &bundleInfo);
|
||||
};
|
||||
|
||||
#define CHECK_NULL(object, errorCode) \
|
||||
do { \
|
||||
if (object == nullptr) { \
|
||||
return errorCode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_LENGTH(length, maxLength, errorCode) \
|
||||
do { \
|
||||
if (length > maxLength) { \
|
||||
return errorCode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_IS_TRUE(result, errorCode) \
|
||||
do { \
|
||||
if (!(result)) { \
|
||||
return errorCode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_PARSE_RESULT(errorCode, object, bundleProfile) \
|
||||
do { \
|
||||
if (errorCode != ERR_OK) { \
|
||||
FREE_BUNDLE_PROFILE(bundleProfile); \
|
||||
cJSON_Delete(object); \
|
||||
return errorCode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FREE_BUNDLE_PROFILE(bundleProfile) \
|
||||
do { \
|
||||
AdapterFree(bundleProfile.abilityInfos); \
|
||||
for (uint8_t i = 0; i < METADATA_SIZE; i++) { \
|
||||
AdapterFree(bundleProfile.moduleInfo.metaData[i]); \
|
||||
} \
|
||||
} while (0)
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLE_PARSER_H
|
||||
+41
@@ -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_BUNDLE_RES_TRANSFORM_H
|
||||
#define OHOS_BUNDLE_RES_TRANSFORM_H
|
||||
|
||||
#include "bundle_common.h"
|
||||
#include "bundle_info.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
class BundleResTransform {
|
||||
public:
|
||||
BundleResTransform() = default;
|
||||
~BundleResTransform() = default;
|
||||
|
||||
static uint8_t ConvertResInfoToBundleInfo(const std::string &path, const BundleRes &bundleRes,
|
||||
BundleInfo *bundleInfo);
|
||||
private:
|
||||
static bool ConvertIconResToBundleInfo(const std::string &path, uint32_t iconId, BundleInfo *bundleInfo,
|
||||
uint32_t index);
|
||||
static bool ConvertLableResToBundleInfo(const std::string &path, uint32_t labelId, BundleInfo *bundleInfo,
|
||||
uint32_t index);
|
||||
static bool ConvertDesResIdToBundleInfo(const std::string &path, uint32_t desId, BundleInfo *bundleInfo,
|
||||
uint32_t index);
|
||||
}; // namespace OHOS
|
||||
}
|
||||
#endif // OHOS_BUNDLE_RES_TRANSFORM_H
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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_BUNDLE_UTIL_H
|
||||
#define OHOS_BUNDLE_UTIL_H
|
||||
|
||||
#include "bundle_common.h"
|
||||
#include "bundle_info.h"
|
||||
#include "utils_list.h"
|
||||
#include "stdint.h"
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#endif
|
||||
#include "cJSON.h"
|
||||
|
||||
namespace OHOS {
|
||||
class BundleUtil {
|
||||
public:
|
||||
static bool CheckRealPath(const char *path);
|
||||
static bool IsFile(const char *path);
|
||||
static bool IsDir(const char *path);
|
||||
static bool EndWith(const char *str, const char *subStr);
|
||||
static bool StartWith(const char *str, const char *subStr);
|
||||
static cJSON *GetJsonStream(const char *path);
|
||||
static uint32_t GetFileSize(const char *filePath);
|
||||
static cJSON *ConvertInstallRecordToJson(const InstallRecord &installRecord);
|
||||
static char *GetValueFromBundleJson(const char *bundleName, const char *key);
|
||||
static int32_t GetValueFromBundleJson(const char *bundleName, const char *key, int32_t defaultValue);
|
||||
static bool IsDigitStr(const char *str);
|
||||
static void DeleteJsonFile(const char *bundleName, const char *randStr);
|
||||
static bool CheckBundleJsonIsValid(const char *bundleName, char **codePath, char **appId, int32_t &versionCode);
|
||||
static char *Strscat(char *str[], uint32_t len);
|
||||
static void CreateRandStr(char *str, uint32_t len);
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
static cJSON *ConvertUidAndGidToJson(const InstallRecord &installRecord);
|
||||
static bool DeleteUidInfoFromJson(const char *bundleName);
|
||||
#else
|
||||
static bool MkDirs(const char *dir);
|
||||
static bool RemoveDir(const char *dir);
|
||||
static bool RenameDir(const char *oldDir, const char *newDir);
|
||||
static bool RenameFile(const char *oldFile, const char *newFile);
|
||||
static bool StoreJsonContentToFile(const char *packageJson, const cJSON *object);
|
||||
static void FreeStrArrayMemory(char **pointer, uint32_t len);
|
||||
#endif
|
||||
private:
|
||||
BundleUtil() = default;
|
||||
~BundleUtil() = default;
|
||||
|
||||
#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER
|
||||
static cJSON *ObtainUidAndGidJson(bool flag);
|
||||
static bool AddUidAndGidInfo(const InstallRecord &installRecord, cJSON *size, cJSON *uids);
|
||||
static bool DeleteInnerUidInfoFromUidArray(const char *bundleName, cJSON *size, cJSON *uids);
|
||||
#else
|
||||
static char *GetRootDir(const char *dir, int32_t index);
|
||||
static bool CheckDirIsEmpty(const char *dir, List<char *>* list);
|
||||
#endif
|
||||
}; // namespace OHOS
|
||||
}
|
||||
#endif // OHOS_BUNDLE_UTIL_H
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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_LOGGING_H
|
||||
#define OHOS_LOGGING_H
|
||||
|
||||
#ifndef APP_PLATFORM_WATCHGT
|
||||
#include "log.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "bundlems"
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN 0xD001300
|
||||
|
||||
#ifdef APP_PLATFORM_WATCHGT
|
||||
#ifndef HILOG_DEBUG
|
||||
#define HILOG_DEBUG(mod, format, ...)
|
||||
#endif
|
||||
#ifndef HILOG_ERROR
|
||||
#define HILOG_ERROR(mod, format, ...)
|
||||
#endif
|
||||
#ifndef HILOG_FATAL
|
||||
#define HILOG_FATAL(mod, format, ...)
|
||||
#endif
|
||||
#ifndef HILOG_INFO
|
||||
#define HILOG_INFO(mod, format, ...)
|
||||
#endif
|
||||
#ifndef HILOG_WARN
|
||||
#define HILOG_WARN(mod, format, ...)
|
||||
#endif
|
||||
#ifndef HILOG_RACE
|
||||
#define HILOG_RACE(mod, format, ...)
|
||||
#endif
|
||||
#define PRINTD(name, fmt, ...)
|
||||
#define PRINTI(name, fmt, ...)
|
||||
#define PRINTW(name, fmt, ...)
|
||||
#define PRINTE(name, fmt, ...)
|
||||
#else
|
||||
#ifdef OHOS_DEBUG
|
||||
#define PRINTD(name, fmt, ...) HILOG_DEBUG(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTD(name, fmt, ...)
|
||||
#endif
|
||||
#define PRINTI(name, fmt, ...) HILOG_INFO(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define PRINTW(name, fmt, ...) HILOG_WARN(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define PRINTE(name, fmt, ...) HILOG_ERROR(LOG_DOMAIN, "%{public}s::%{public}s(%{public}d): " fmt, \
|
||||
name, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#define CHECK_NULLPTR_RETURN_PTR(point, name, fmt) \
|
||||
do { \
|
||||
if (point == nullptr) { \
|
||||
PRINTE(name, fmt); \
|
||||
return nullptr; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_NULLPTR_RETURN(point, name, fmt) \
|
||||
do { \
|
||||
if (point == nullptr) { \
|
||||
PRINTE(name, fmt); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_NULLPTR_RETURN_CODE(point, name, fmt, code) \
|
||||
do { \
|
||||
if (point == nullptr) { \
|
||||
PRINTE(name, fmt); \
|
||||
return code; \
|
||||
} \
|
||||
} while (0)
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_LOGGING_H
|
||||
+39
@@ -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_BUNDLE_EXTRACTOR_UTIL_H
|
||||
#define OHOS_BUNDLE_EXTRACTOR_UTIL_H
|
||||
|
||||
#include "stdint.h"
|
||||
#include "zip_file.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
class ExtractorUtil {
|
||||
public:
|
||||
explicit ExtractorUtil(const std::string &filePath);
|
||||
~ExtractorUtil();
|
||||
bool Init();
|
||||
bool ExtractFileByName(const std::string &fileName, std::ostream &dest) const;
|
||||
const std::vector<std::string> &GetZipFileNames() const;
|
||||
bool ExtractFileToPath(const std::string &filePath, const std::string &fileName) const;
|
||||
private:
|
||||
ZipFile zipFile_;
|
||||
bool initial_ { false };
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLE_EXTRACTOR_UTIL_H
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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_GT_BUNDLE_EXTRACTOR_H
|
||||
#define OHOS_GT_BUNDLE_EXTRACTOR_H
|
||||
|
||||
#include "bundle_common.h"
|
||||
#include "stdint.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GtBundleExtractor {
|
||||
public:
|
||||
static uint8_t ExtractHap(const char *codePath, const char *bundleName, int32_t fp, uint32_t totalFileSize,
|
||||
uint8_t bundleStyle);
|
||||
static char *ExtractHapProfile(int32_t fp, uint32_t totalFileSize);
|
||||
static uint8_t ExtractBundleParam(const char *path, int32_t &fpStart, char **bundleName);
|
||||
static bool ExtractInstallMsg(const char *path, char **bundleName, char **label, char **smallIconPath,
|
||||
char **bigIconPath);
|
||||
private:
|
||||
static uint8_t ExtractFileDataPos(int32_t fp, uint64_t &filePos);
|
||||
static bool ExtractResourceFile(const char *path, int32_t fp, uint32_t totalFileSize);
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_GT_BUNDLE_EXTRACTOR_H
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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_GT_BUNDLE_INSTALLER_H
|
||||
#define OHOS_GT_BUNDLE_INSTALLER_H
|
||||
|
||||
#include "generate-bytecode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "bundle_common.h"
|
||||
#include "bundle_info.h"
|
||||
#include "bundle_info_utils.h"
|
||||
#include "bundle_manager_inner.h"
|
||||
#include "stdint.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GtBundleInstaller {
|
||||
public:
|
||||
GtBundleInstaller() = default;
|
||||
~GtBundleInstaller() = default;
|
||||
|
||||
uint8_t Install(const char *path);
|
||||
uint8_t Uninstall(const char *bundleName);
|
||||
int8_t getInstallationProgress(const char *bundleName);
|
||||
private:
|
||||
uint8_t PreCheckBundle(const char *path, int32_t &fp, SignatureInfo &signatureInfo, uint32_t &fileSize,
|
||||
uint8_t bundleStyle);
|
||||
uint8_t ProcessBundleInstall(const char *path, const char *randStr, InstallRecord &installRecord,
|
||||
uint8_t bundleStyle);
|
||||
uint8_t HandleFileAndBackUpRecord(const InstallRecord &record, const char *tmpPath, const char *randStr,
|
||||
const char *dataPath, bool isUpdate);
|
||||
uint8_t UpdateBundleInfo(uint8_t bundleStyle, uint32_t labelId, uint32_t iconId, BundleInfo *bundleInfo,
|
||||
bool isUpdate);
|
||||
void RecordThirdSystemBundle(const char *bundleName, const char *path);
|
||||
uint8_t StorePermissions(const char *bundleName, PermissionTrans *permissions, int32_t permNum, bool isUpdate);
|
||||
uint8_t CheckVersionAndSignature(const char *bundleName, const char *appId, BundleInfo *bundleInfo);
|
||||
bool RenameJsonFile(const char *fileName, const char *randStr);
|
||||
bool CheckIsThirdSystemBundle(const char *bundleName);
|
||||
bool BackUpInstallRecord(const InstallRecord &record, const char *jsonPath);
|
||||
void InitThirdSystemBundleRecord(const char *bundleName, const char *path);
|
||||
uint8_t VerifySignature(const char *path, SignatureInfo &signatureInfo, uint32_t &fileSize, uint8_t bundleStyle);
|
||||
bool MatchBundleName(const char *bundleName, const char *matchedBundleName);
|
||||
bool MatchPermissions(char ** restrictedPermissions, uint32_t restricNum, PermissionTrans *permissionsTrans,
|
||||
int32_t permTransNum);
|
||||
uint8_t CheckProvisionInfoIsValid(const SignatureInfo &signatureInfo, const Permissions &permissions,
|
||||
const char *bundleName);
|
||||
char *ReshapeAppId(const char *bundleName, char *appId);
|
||||
uint8_t SwitchErrorCode(int32_t errorCode);
|
||||
uint8_t AddBundleResList(const char *bundleName, uint32_t labelId, uint32_t iconId);
|
||||
uint8_t MoveRawFileToDataPath(const BundleInfo *bundleInfo);
|
||||
uint8_t TransformJsToBc(const char *codePath, InstallRecord &record);
|
||||
|
||||
InstallationProgress installationProgress_;
|
||||
};
|
||||
|
||||
#define FREE_PRO_RESOURCE(fp, permissions, bundleInfo) \
|
||||
do { \
|
||||
if (fp >= 0) { \
|
||||
close(fp); \
|
||||
} \
|
||||
BundleInfoUtils::FreeBundleInfo(bundleInfo); \
|
||||
UI_Free(permissions.permissionTrans); \
|
||||
} while (0)
|
||||
|
||||
#define FREE_SIGNATUREINFO(signatureInfo) \
|
||||
do { \
|
||||
AdapterFree(signatureInfo.appId); \
|
||||
AdapterFree(signatureInfo.bundleName); \
|
||||
BundleUtil::FreeStrArrayMemory(signatureInfo.restricPermission, signatureInfo.restricNum); \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_PRO_RESULT(errcode, fp, permissions, bundleInfo, signatureInfo) \
|
||||
do { \
|
||||
if (errcode != ERR_OK) { \
|
||||
FREE_PRO_RESOURCE(fp, permissions, bundleInfo); \
|
||||
FREE_SIGNATUREINFO(signatureInfo); \
|
||||
return errcode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CLEAR_INSTALL_ENV(bundleInfo) \
|
||||
do { \
|
||||
if (bundleInfo != nullptr) { \
|
||||
BundleUtil::RemoveDir(bundleInfo->codePath); \
|
||||
BundleUtil::RemoveDir(bundleInfo->dataPath); \
|
||||
BundleInfoUtils::FreeBundleInfo(bundleInfo); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_PRO_PART_ROLLBACK(errcode, path, permissions, bundleInfo, signatureInfo) \
|
||||
do { \
|
||||
if (errcode != ERR_OK) { \
|
||||
BundleUtil::RemoveDir(path); \
|
||||
AdapterFree(path); \
|
||||
BundleInfoUtils::FreeBundleInfo(bundleInfo); \
|
||||
FREE_SIGNATUREINFO(signatureInfo); \
|
||||
UI_Free(permissions.permissionTrans); \
|
||||
return errcode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_PRO_ROLLBACK(errcode, permissions, bundleInfo, signatureInfo, randStr) \
|
||||
do { \
|
||||
if (errcode != ERR_OK && bundleInfo != nullptr) { \
|
||||
FREE_SIGNATUREINFO(signatureInfo); \
|
||||
UI_Free(permissions.permissionTrans); \
|
||||
GtManagerService::GetInstance().RemoveBundleInfo(bundleInfo->bundleName); \
|
||||
BundleUtil::DeleteJsonFile(bundleInfo->bundleName, randStr); \
|
||||
CLEAR_INSTALL_ENV(bundleInfo); \
|
||||
return errcode; \
|
||||
} \
|
||||
} while (0)
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_GT_BUNDLE_INSTALLER_H
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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_GT_BUNDLE_MANAGER_SERVICE_H
|
||||
#define OHOS_GT_BUNDLE_MANAGER_SERVICE_H
|
||||
|
||||
#include "adapter.h"
|
||||
#include "bundle_app_info.h"
|
||||
#include "bundle_info.h"
|
||||
#include "bundle_map.h"
|
||||
#include "cJSON.h"
|
||||
#include "gt_bundle_installer.h"
|
||||
#include "stdint.h"
|
||||
#include "want.h"
|
||||
#include "install_param.h"
|
||||
#include "bundle_manager.h"
|
||||
#include "los_list.h"
|
||||
#include "ohos_types.h"
|
||||
|
||||
namespace OHOS {
|
||||
struct ToBeInstalledApp {
|
||||
bool isSystemApp;
|
||||
bool isUpdated;
|
||||
char *path;
|
||||
char *installedPath;
|
||||
};
|
||||
|
||||
class GtManagerService {
|
||||
public:
|
||||
static GtManagerService &GetInstance()
|
||||
{
|
||||
static GtManagerService instance;
|
||||
return instance;
|
||||
}
|
||||
bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback);
|
||||
bool Uninstall(const char *bundleName, const InstallParam *installParam, InstallerCallback installerCallback);
|
||||
uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo);
|
||||
uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo& bundleInfo);
|
||||
uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len);
|
||||
void ScanPackages();
|
||||
void SendBundleListChangedToLauncher(BundleState state, const char *bundleName);
|
||||
BundleInfo *QueryBundleInfo(const char *bundleName);
|
||||
void RemoveBundleInfo(const char *bundleName);
|
||||
void AddBundleInfo(BundleInfo *info);
|
||||
bool UpdateBundleInfo(BundleInfo *info);
|
||||
char *GetAppIdByBundleName(const char *bundleName);
|
||||
uint32_t GetVersionCodeByBundlePath(const char *path, unsigned char *versionCode, uint8_t length);
|
||||
uint32_t GetNumOfThirdBundles();
|
||||
void RemoveBundleResList(const char *bundleName);
|
||||
void AddBundleResList(const BundleRes *bundleRes);
|
||||
void UpdateBundleInfoList();
|
||||
int32_t ReportSystemBundleInstallProcess(uint8_t process, const char *bundleName, uint8_t installState);
|
||||
void ReportInstallProcess(const char *bundleName, uint8_t bundleStyle, uint8_t process);
|
||||
void AddNumOfThirdBundles();
|
||||
void ReduceNumOfThirdBundles();
|
||||
int8_t GetInstallState(const char *bundleName) const;
|
||||
|
||||
private:
|
||||
GtManagerService();
|
||||
~GtManagerService();
|
||||
void ScanSystemApp(const cJSON *uninstallRecord, List<ToBeInstalledApp *> *systemPathList);
|
||||
void ScanThirdApp(const char *appDir, const List<ToBeInstalledApp *> *systemPathList);
|
||||
void InstallAllSystemBundle();
|
||||
void InstallSystemBundle(const char *systemAppPath);
|
||||
bool ReloadBundleInfo(const char *profileDir, const char *appId, bool isSystemApp);
|
||||
void ReloadEntireBundleInfo(const char *appPath, const char *bundleName, List<ToBeInstalledApp *> *systemPathList,
|
||||
int32_t versionCode, uint8_t scanFlag);
|
||||
bool CheckSystemBundleIsValid(const char *appPath, char **bundleName, int32_t &versionCode);
|
||||
bool CheckThirdSystemBundleHasUninstalled(const char *bundleName, const cJSON *object);
|
||||
void AddSystemAppPathList(const char *installedPath, const char *path, List<ToBeInstalledApp *> *systemPathList,
|
||||
bool isSystemApp, bool isUpdated);
|
||||
void RemoveSystemAppPathList(List<ToBeInstalledApp *> *systemPathList);
|
||||
void ClearSystemBundleInstallMsg();
|
||||
void TransformJsToBcWhenRestart(const char *codePath, const char *bundleName);
|
||||
void TransformJsToBc(const char *codePath, const char *bundleJsonPath, cJSON *installRecordObj);
|
||||
bool IsSystemBundleInstalledPath(const char *appPath, const List<ToBeInstalledApp *> *systemPathList);
|
||||
|
||||
GtBundleInstaller *installer_;
|
||||
BundleMap *bundleMap_;
|
||||
List<BundleRes *> *bundleResList_;
|
||||
BundleInstallMsg *systemBundleInstallMsg_;
|
||||
char *jsEngineVer_;
|
||||
uint32_t installedThirdBundleNum_;
|
||||
};
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
#define JS_FILE_PATH_FLASH_LIGHT "system/ace/sys/flashlight.bin"
|
||||
#define JS_FILE_PATH_HEALTH_ECG "system/ace/sys/health_ecg.bin"
|
||||
#define MAX_APP_FILE_PATH_LEN 100
|
||||
typedef struct {
|
||||
LOS_DL_LIST appDoubleList;
|
||||
char filePath[MAX_APP_FILE_PATH_LEN];
|
||||
} AppInfoList;
|
||||
|
||||
AppInfoList *APP_InitAllAppInfo(void);
|
||||
void APP_FreeAllAppInfo(const AppInfoList *list);
|
||||
void EnableServiceWdg(void);
|
||||
void DisableServiceWdg(void);
|
||||
}
|
||||
|
||||
#endif // OHOS_GT_BUNDLE_MANAGER_SERVICE_H
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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_GT_BUNDLE_PARSER_H
|
||||
#define OHOS_GT_BUNDLE_PARSER_H
|
||||
|
||||
#include "bundle_common.h"
|
||||
#include "bundle_info.h"
|
||||
#include "stdint.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GtBundleParser {
|
||||
public:
|
||||
static BundleInfo *ParseHapProfile(const char *path, BundleRes *bundleRes);
|
||||
static uint8_t ParseHapProfile(int32_t fp, uint32_t fileSize, Permissions &permissions, BundleRes &bundleRes,
|
||||
BundleInfo **bundleInfo);
|
||||
static bool ParseBundleAttr(const char *path, char **bundleName, int32_t &versionCode);
|
||||
static uint8_t ConvertResInfoToBundleInfo(const char *path, uint32_t labelId, uint32_t iconId,
|
||||
BundleInfo *bundleInfo);
|
||||
private:
|
||||
static uint8_t ParseJsonInfo(const cJSON *appObject, const cJSON *configObject, const cJSON *moduleObject,
|
||||
BundleProfile &bundleProfile, BundleRes &bundleRes);
|
||||
static BundleInfo *CreateBundleInfo(const char *path, const BundleProfile &bundleProfile,
|
||||
const BundleRes &bundleRes);
|
||||
static bool ConvertIconResToBundleInfo(const char *resPath, uint32_t iconId, BundleInfo *bundleInfo);
|
||||
static uint8_t ParseModuleInfo(const cJSON *moduleObject, BundleProfile &bundleProfile, BundleRes &bundleRes);
|
||||
static uint8_t ParseAbilityInfo(const cJSON *abilityInfoObjects, BundleProfile &bundleProfile,
|
||||
BundleRes &bundleRes);
|
||||
static uint8_t ParseModuleMetaData(const cJSON *moduleObject, BundleProfile &bundleProfile);
|
||||
static bool SetModuleInfos(const BundleProfile &bundleProfile, BundleInfo *bundleInfo);
|
||||
static uint8_t SaveBundleInfo(const BundleProfile &bundleProfile, const BundleRes &bundleRes,
|
||||
BundleInfo **bundleInfo);
|
||||
static bool SetBundleInfo(const char *installedPath, const BundleProfile &bundleProfile,
|
||||
const BundleRes &bundleRes, BundleInfo *bundleInfo);
|
||||
static char *ParseValue(const cJSON *object, const char *key);
|
||||
static int32_t ParseValue(const cJSON *object, const char *key, int32_t defaultValue);
|
||||
static cJSON *ParseValue(const cJSON *object, const char *key, cJSON *defaultValue);
|
||||
static uint8_t ParsePermissions(const cJSON *object, Permissions &permissions);
|
||||
static bool SetReqPermission(const cJSON *object, PermissionTrans *permission);
|
||||
static bool CheckDeviceTypeIsValid(const cJSON *deviceTypeObject);
|
||||
};
|
||||
|
||||
#define CHECK_NULL(object, errorCode) \
|
||||
do { \
|
||||
if (object == nullptr) { \
|
||||
return errorCode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_LENGTH(length, maxLength, errorCode) \
|
||||
do { \
|
||||
if (length > maxLength) { \
|
||||
return errorCode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_IS_TRUE(result, errorCode) \
|
||||
do { \
|
||||
if (!result) { \
|
||||
return errorCode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FREE_BUNDLE_PROFILE(bundleProfile) \
|
||||
do { \
|
||||
for (int32_t i = 0; i < METADATA_SIZE; i++) { \
|
||||
AdapterFree(bundleProfile.moduleInfo.metaData[i]); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define FREE_BUNDLE_RES(bundleRes) \
|
||||
do { \
|
||||
if (bundleRes.abilityRes != nullptr) { \
|
||||
AdapterFree(bundleRes.abilityRes); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_PARSE_RESULT(errorCode, object, bundleProfile, bundleRes) \
|
||||
do { \
|
||||
if (errorCode != ERR_OK) { \
|
||||
FREE_BUNDLE_PROFILE(bundleProfile); \
|
||||
FREE_BUNDLE_RES(bundleRes); \
|
||||
cJSON_Delete(object); \
|
||||
return errorCode; \
|
||||
} \
|
||||
} while (0)
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_GT_BUNDLE_PARSER_H
|
||||
@@ -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_GT_BUNDLE_EXTRACTOR_UTIL_H
|
||||
#define OHOS_GT_BUNDLE_EXTRACTOR_UTIL_H
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
namespace OHOS {
|
||||
class GtExtractorUtil {
|
||||
public:
|
||||
static uint8_t ExtractFileHeaderInfo(int32_t fp, char **bundleName);
|
||||
static uint8_t ExtractFileToPath(const char *appInstallPath, int32_t fp, uint64_t &fileSize, char **fileName,
|
||||
char **relativeFilePath);
|
||||
static uint8_t ExtractFileAttr(int32_t fp, char **fileName, uint32_t &pathLen, uint64_t &fileSize);
|
||||
static uint8_t ExtractFileAttr(int32_t fp, char **fileName, char **relativeFilePath, uint64_t &fileSize);
|
||||
static bool CheckMagicNumber(int32_t fp);
|
||||
static bool HasWrittenFile(const char *installPath, const char *path, const char *filename, int32_t fp,
|
||||
uint64_t size);
|
||||
private:
|
||||
static uint32_t ReadInt(int32_t fp);
|
||||
static uint64_t ReadLong(int32_t fp);
|
||||
static char *ReadString(int32_t fp, uint32_t len);
|
||||
static bool HasCopiedData(const char *filePath, int32_t fp, uint64_t size);
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_GT_BUNDLE_EXTRACTOR_UTIL_H
|
||||
+49
@@ -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_HAP_VERIFY_H
|
||||
#define OHOS_HAP_VERIFY_H
|
||||
|
||||
#include "app_verify_pub.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
struct SignatureInfo {
|
||||
std::string appId;
|
||||
std::string provisionBundleName;
|
||||
std::vector<std::string> restrictedPermissions;
|
||||
};
|
||||
|
||||
class HapSignVerify {
|
||||
public:
|
||||
static uint8_t VerifySignature(const std::string &hapFilepath, SignatureInfo &signatureInfo);
|
||||
private:
|
||||
HapSignVerify() = default;
|
||||
~HapSignVerify() = default;
|
||||
static uint8_t SwitchErrorCode(int32_t errorCode);
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_HAP_VERIFY_H
|
||||
Executable
+183
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* 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_BUNDLE_ZIP_FILE_H
|
||||
#define OHOS_BUNDLE_ZIP_FILE_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "stdint.h"
|
||||
#include "unzip.h"
|
||||
|
||||
namespace OHOS {
|
||||
using ZipPos = ZPOS64_T;
|
||||
using CentralDirEntry = struct CentralDirEntry;
|
||||
using LocalHeader = struct LocalHeader;
|
||||
using EndDir = struct EndDir;
|
||||
using DataDesc = struct DataDesc;
|
||||
using ZipEntry = struct ZipEntry;
|
||||
using ZipEntryMap = std::map<std::string, ZipEntry>;
|
||||
using BytePtr = Byte *;
|
||||
|
||||
// Local file header: descript in APPNOTE-6.3.4
|
||||
// local file header signature 4 bytes (0x04034b50)
|
||||
// version needed to extract 2 bytes
|
||||
// general purpose bit flag 2 bytes
|
||||
// compression method 2 bytes 10
|
||||
// last mod file time 2 bytes
|
||||
// last mod file date 2 bytes
|
||||
// crc-32 4 bytes
|
||||
// compressed size 4 bytes 22
|
||||
// uncompressed size 4 bytes
|
||||
// file name length 2 bytes
|
||||
// extra field length 2 bytes 30
|
||||
struct __attribute__((packed)) LocalHeader {
|
||||
uint32_t signature = 0;
|
||||
uint16_t versionNeeded = 0;
|
||||
uint16_t flags = 0;
|
||||
uint16_t compressionMethod = 0;
|
||||
uint16_t modifiedTime = 0;
|
||||
uint16_t modifiedDate = 0;
|
||||
uint32_t crc = 0;
|
||||
uint32_t compressedSize = 0;
|
||||
uint32_t uncompressedSize = 0;
|
||||
uint16_t nameSize = 0;
|
||||
uint16_t extraSize = 0;
|
||||
};
|
||||
|
||||
// central file header
|
||||
// Central File header:
|
||||
// central file header signature 4 bytes (0x02014b50)
|
||||
// version made by 2 bytes
|
||||
// version needed to extract 2 bytes
|
||||
// general purpose bit flag 2 bytes 10
|
||||
// compression method 2 bytes
|
||||
// last mod file time 2 bytes
|
||||
// last mod file date 2 bytes
|
||||
// crc-32 4 bytes 20
|
||||
// compressed size 4 bytes
|
||||
// uncompressed size 4 bytes
|
||||
// file name length 2 bytes 30
|
||||
// extra field length 2 bytes
|
||||
// file comment length 2 bytes
|
||||
// disk number start 2 bytes
|
||||
// internal file attributes 2 bytes
|
||||
// external file attributes 4 bytes
|
||||
// relative offset of local header 4 bytes 46byte
|
||||
struct __attribute__((packed)) CentralDirEntry {
|
||||
uint32_t signature = 0;
|
||||
uint16_t versionMade = 0;
|
||||
uint16_t versionNeeded = 0;
|
||||
uint16_t flags = 0; // general purpose bit flag
|
||||
uint16_t compressionMethod = 0;
|
||||
uint16_t modifiedTime = 0;
|
||||
uint16_t modifiedDate = 0;
|
||||
uint32_t crc = 0;
|
||||
uint32_t compressedSize = 0;
|
||||
uint32_t uncompressedSize = 0;
|
||||
uint16_t nameSize = 0;
|
||||
uint16_t extraSize = 0;
|
||||
uint16_t commentSize = 0;
|
||||
uint16_t diskNumStart = 0;
|
||||
uint16_t internalAttr = 0;
|
||||
uint32_t externalAttr = 0;
|
||||
uint32_t localHeaderOffset = 0;
|
||||
};
|
||||
|
||||
struct __attribute__((packed)) EndDir {
|
||||
uint32_t signature = 0;
|
||||
uint16_t numDisk = 0;
|
||||
uint16_t startDiskOfCentralDir = 0;
|
||||
uint16_t totalEntriesInThisDisk = 0;
|
||||
uint16_t totalEntries = 0;
|
||||
uint32_t sizeOfCentralDir = 0;
|
||||
uint32_t offset = 0;
|
||||
uint16_t commentLen = 0;
|
||||
};
|
||||
|
||||
// Data descriptor:
|
||||
// data descriptor signature 4 bytes (0x06054b50)
|
||||
// crc-32 4 bytes
|
||||
// compressed size 4 bytes
|
||||
// uncompressed size 4 bytes
|
||||
// This descriptor MUST exist if bit 3 of the general purpose bit flag is set (see below).
|
||||
// It is byte aligned and immediately follows the last byte of compressed data.
|
||||
struct __attribute__((packed)) DataDesc {
|
||||
uint32_t signature = 0;
|
||||
uint32_t crc = 0;
|
||||
uint32_t compressedSize = 0;
|
||||
uint32_t uncompressedSize = 0;
|
||||
};
|
||||
|
||||
struct ZipEntry {
|
||||
ZipEntry() = default;
|
||||
explicit ZipEntry(const CentralDirEntry ¢ralEntry);
|
||||
~ZipEntry() = default;
|
||||
|
||||
uint16_t compressionMethod = 0;
|
||||
uint32_t uncompressedSize = 0;
|
||||
uint32_t compressedSize = 0;
|
||||
uint32_t localHeaderOffset = 0;
|
||||
uint32_t crc = 0;
|
||||
uint16_t flags = 0;
|
||||
std::string fileName;
|
||||
};
|
||||
|
||||
// zip file extract class for bundle format.
|
||||
class ZipFile {
|
||||
public:
|
||||
explicit ZipFile(const std::string &pathName);
|
||||
~ZipFile();
|
||||
|
||||
bool Open();
|
||||
void Close();
|
||||
// set this zip content start offset and length in the zip file form pathName.
|
||||
void SetContentLocation(ZipPos start, size_t length);
|
||||
|
||||
const ZipEntryMap &GetAllEntries() const;
|
||||
bool GetEntry(const std::string &entryName, ZipEntry &resultEntry) const;
|
||||
bool ExtractFile(const std::string &file, std::ostream &dest) const;
|
||||
const std::vector<std::string> &GetFileNames() const;
|
||||
|
||||
private:
|
||||
bool CheckEndDir(const EndDir &endDir) const;
|
||||
bool ParseEndDirectory();
|
||||
bool ParseAllEntries();
|
||||
size_t GetLocalHeaderSize(const uint16_t nameSize = 0, const uint16_t extraSize = 0) const;
|
||||
bool CheckDataDesc(const ZipEntry &zipEntry, const LocalHeader &localHeader) const;
|
||||
bool CheckCoherencyLocalHeader(const ZipEntry &zipEntry, uint16_t &extraSize) const;
|
||||
bool UnzipWithStore(const ZipEntry &zipEntry, const uint16_t extraSize, std::ostream &dest) const;
|
||||
bool UnzipWithInflated(const ZipEntry &zipEntry, const uint16_t extraSize, std::ostream &dest) const;
|
||||
bool SeekToEntryStart(const ZipEntry &zipEntry, const uint16_t extraSize) const;
|
||||
bool InitZStream(z_stream &zstream) const;
|
||||
bool ReadZStream(const BytePtr &buffer, z_stream &zstream, uint32_t &remainCompressedSize) const;
|
||||
|
||||
private:
|
||||
std::string pathName_;
|
||||
FILE* file_ = nullptr;
|
||||
EndDir endDir_;
|
||||
ZipEntryMap entriesMap_;
|
||||
// offset of central directory relative to zip file.
|
||||
ZipPos centralDirPos_ = 0;
|
||||
// this zip content length in the zip file.
|
||||
ZipPos fileLength_ = 0;
|
||||
// entryName vector
|
||||
std::vector<std::string> fileNames_;
|
||||
bool isOpen_ = false;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_BUNDLE_ZIP_FILE_H
|
||||
+405
@@ -0,0 +1,405 @@
|
||||
/*
|
||||
* 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 "bundle_daemon_client.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "adapter.h"
|
||||
#include "bundle_daemon_interface.h"
|
||||
#include "bundle_log.h"
|
||||
#include "iproxy_client.h"
|
||||
#include "ohos_errno.h"
|
||||
#include "samgr_lite.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr unsigned SLEEP_TIME = 200000;
|
||||
}
|
||||
#ifdef __LINUX__
|
||||
int BundleDaemonClient::Notify(IOwner owner, int code, IpcIo *reply)
|
||||
{
|
||||
if ((reply == nullptr) || (owner == nullptr)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Notify ipc is nullptr");
|
||||
return OHOS_FAILURE;
|
||||
}
|
||||
BundleDaemonClient *client = reinterpret_cast<BundleDaemonClient *>(owner);
|
||||
if (client == nullptr) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
client->result_ = IpcIoPopInt32(reply);
|
||||
int value;
|
||||
sem_getvalue(&client->sem_, &value);
|
||||
if (value <= 0) {
|
||||
sem_post(&client->sem_);
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
#else
|
||||
int32_t BundleDaemonClient::BundleDaemonCallback(const IpcContext* context, void *ipcMsg, IpcIo *io, void *arg)
|
||||
{
|
||||
BundleDaemonClient *client = reinterpret_cast<BundleDaemonClient *>(arg);
|
||||
if (client == nullptr) {
|
||||
if (ipcMsg != nullptr) {
|
||||
FreeBuffer(nullptr, ipcMsg);
|
||||
}
|
||||
return EC_INVALID;
|
||||
}
|
||||
|
||||
client->result_ = IpcIoPopInt32(io);
|
||||
if (ipcMsg != nullptr) {
|
||||
FreeBuffer(nullptr, ipcMsg);
|
||||
}
|
||||
int value;
|
||||
sem_getvalue(&client->sem_, &value);
|
||||
if (value <= 0) {
|
||||
sem_post(&client->sem_);
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t BundleDaemonClient::DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* arg)
|
||||
{
|
||||
if (ipcMsg != nullptr) {
|
||||
FreeBuffer(nullptr, ipcMsg);
|
||||
}
|
||||
pthread_t pid;
|
||||
if (pthread_create(&pid, nullptr, RegisterDeathCallback, arg) == 0) {
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
BundleDaemonClient *client = reinterpret_cast<BundleDaemonClient *>(arg);
|
||||
if (client != nullptr) {
|
||||
client->result_ = EC_CANCELED;
|
||||
int value;
|
||||
sem_getvalue(&client->sem_, &value);
|
||||
if (value <= 0) {
|
||||
sem_post(&client->sem_);
|
||||
}
|
||||
}
|
||||
return EC_INVALID;
|
||||
}
|
||||
|
||||
BundleDaemonClient::~BundleDaemonClient()
|
||||
{
|
||||
if (initialized_) {
|
||||
UnregisterIpcCallback(svcIdentity_);
|
||||
UnregisterDeathCallback(bdsSvcIdentity_, cbid_);
|
||||
bdsClient_->Release(reinterpret_cast<IUnknown *>(bdsClient_));
|
||||
bdsClient_ = nullptr;
|
||||
sem_destroy(&sem_);
|
||||
}
|
||||
}
|
||||
|
||||
bool BundleDaemonClient::Initialize()
|
||||
{
|
||||
if (initialized_) {
|
||||
PRINTI("BundleDaemonClient", "already initialized");
|
||||
return true;
|
||||
}
|
||||
if (sem_init(&sem_, 0, 0) != 0) {
|
||||
PRINTE("BundleDaemonClient", "sem_init fail");
|
||||
return false;
|
||||
}
|
||||
|
||||
while (bdsClient_ == nullptr) {
|
||||
IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(BDS_SERVICE);
|
||||
if (iUnknown == nullptr) {
|
||||
usleep(SLEEP_TIME);
|
||||
continue;
|
||||
}
|
||||
|
||||
(void)iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&bdsClient_);
|
||||
}
|
||||
|
||||
// register bundle_daemon callback
|
||||
#ifndef __LINUX__
|
||||
int32_t ret = RegisterIpcCallback(
|
||||
BundleDaemonClient::BundleDaemonCallback, 0, IPC_WAIT_FOREVER, &svcIdentity_, this);
|
||||
if (ret != EC_SUCCESS) {
|
||||
PRINTE("BundleDaemonClient", "register bundle_daemon RegisterIpcCallback fail");
|
||||
sem_destroy(&sem_);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
if (RegisterCallback() != LITEIPC_OK) {
|
||||
PRINTE("BundleDaemonClient", "register bundle_daemon callback fail");
|
||||
sem_destroy(&sem_);
|
||||
return false;
|
||||
}
|
||||
|
||||
// register bundle_daemon death callback
|
||||
bdsSvcIdentity_ = SAMGR_GetRemoteIdentity(BDS_SERVICE, nullptr);
|
||||
if (::RegisterDeathCallback(nullptr, bdsSvcIdentity_, &BundleDaemonClient::DeathCallback, this, &cbid_) !=
|
||||
LITEIPC_OK) {
|
||||
PRINTW("BundleDaemonClient", "register bundle_daemon death callback fail");
|
||||
// Keep running if register death callback fail
|
||||
}
|
||||
|
||||
initialized_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void *BundleDaemonClient::RegisterDeathCallback(void *arg)
|
||||
{
|
||||
BundleDaemonClient *client = reinterpret_cast<BundleDaemonClient *>(arg);
|
||||
if (client == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
client->result_ = EC_CANCELED;
|
||||
int value;
|
||||
sem_getvalue(&client->sem_, &value);
|
||||
if (value <= 0) {
|
||||
sem_post(&client->sem_);
|
||||
}
|
||||
// Register invoke callback and death callback again
|
||||
Lock<Mutex> lock(client->mutex_);
|
||||
client->RegisterCallback();
|
||||
|
||||
UnregisterDeathCallback(client->bdsSvcIdentity_, client->cbid_);
|
||||
client->cbid_ = INVALID_INDEX;
|
||||
client->bdsSvcIdentity_.handle = INVALID_INDEX;
|
||||
client->bdsSvcIdentity_.token = INVALID_INDEX;
|
||||
|
||||
client->bdsSvcIdentity_ = SAMGR_GetRemoteIdentity(BDS_SERVICE, nullptr);
|
||||
if (::RegisterDeathCallback(nullptr, client->bdsSvcIdentity_, &BundleDaemonClient::DeathCallback,
|
||||
client, &client->cbid_) != LITEIPC_OK) {
|
||||
PRINTW("BundleDeamonClient", "register death callback fail");
|
||||
// Keep running if register death callback fail
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32_t BundleDaemonClient::WaitResultSync(int32_t result)
|
||||
{
|
||||
if (result == EC_SUCCESS) {
|
||||
sem_wait(&sem_);
|
||||
result = result_;
|
||||
result_ = EC_FAILURE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t BundleDaemonClient::RegisterCallback()
|
||||
{
|
||||
IpcIo request;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&request, data, IPC_IO_DATA_MAX, 1);
|
||||
IpcIoPushSvc(&request, &svcIdentity_);
|
||||
#ifdef __LINUX__
|
||||
while (bdsClient_->Invoke(bdsClient_, REGISTER_CALLBACK, &request, this, Notify) != EC_SUCCESS) {
|
||||
#else
|
||||
while (bdsClient_->Invoke(bdsClient_, REGISTER_CALLBACK, &request, nullptr, nullptr) != EC_SUCCESS) {
|
||||
#endif
|
||||
PRINTI("BundleDaemonClient", "register bundle_daemon callback fail");
|
||||
usleep(SLEEP_TIME);
|
||||
}
|
||||
return WaitResultSync(EC_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t BundleDaemonClient::CallClientInvoke(int32_t funcId, const char *firstPath, const char *secondPath)
|
||||
{
|
||||
IpcIo request;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
#ifdef __LINUX__
|
||||
IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0);
|
||||
#else
|
||||
IpcIoInit(&request, data, IPC_IO_DATA_MAX, 1);
|
||||
#endif
|
||||
std::string innerStr = firstPath;
|
||||
innerStr += secondPath;
|
||||
#ifdef __LINUX__
|
||||
IpcIoPushString(&request, innerStr.c_str());
|
||||
#else
|
||||
BuffPtr dataBuff = {
|
||||
.buffSz = innerStr.length() + 1,
|
||||
.buff = const_cast<char *>(innerStr.c_str())
|
||||
};
|
||||
IpcIoPushDataBuff(&request, &dataBuff);
|
||||
#endif
|
||||
IpcIoPushUint16(&request, strlen(firstPath));
|
||||
if (!IpcIoAvailable(&request)) {
|
||||
PRINTE("BundleDaemonClient", "BundleDaemonClient GenerateRequest ipc failed");
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
Lock<Mutex> lock(mutex_);
|
||||
#ifdef __LINUX__
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, funcId, &request, this, Notify));
|
||||
#else
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, funcId, &request, nullptr, nullptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t BundleDaemonClient::ExtractHap(const char *hapFile, const char *codePath)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return EC_NOINIT;
|
||||
}
|
||||
if (hapFile == nullptr || codePath == nullptr) {
|
||||
PRINTE("BundleDaemonClient", "invalid params: hapFile or codePath is nullptr");
|
||||
return EC_INVALID;
|
||||
}
|
||||
|
||||
return CallClientInvoke(EXTRACT_HAP, hapFile, codePath);
|
||||
}
|
||||
|
||||
int32_t BundleDaemonClient::RenameFile(const char *oldFile, const char *newFile)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return EC_NOINIT;
|
||||
}
|
||||
if (oldFile == nullptr || newFile == nullptr) {
|
||||
PRINTE("BundleDaemonClient", "invalid params: oldDir or newDir is nullptr");
|
||||
return EC_INVALID;
|
||||
}
|
||||
|
||||
return CallClientInvoke(RENAME_DIR, oldFile, newFile);
|
||||
}
|
||||
|
||||
int32_t BundleDaemonClient::CreatePermissionDir()
|
||||
{
|
||||
if (!initialized_) {
|
||||
return EC_NOINIT;
|
||||
}
|
||||
Lock<Mutex> lock(mutex_);
|
||||
#ifdef __LINUX__
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, CREATE_PERMISSION_DIR, nullptr, this, Notify));
|
||||
#else
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, CREATE_PERMISSION_DIR, nullptr, nullptr, nullptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t BundleDaemonClient::CreateDataDirectory(const char *dataPath, int32_t uid, int32_t gid, bool isChown)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return EC_NOINIT;
|
||||
}
|
||||
if (dataPath == nullptr) {
|
||||
PRINTE("BundleDaemonClient", "invalid params: bundleName is nullptr");
|
||||
return EC_INVALID;
|
||||
}
|
||||
IpcIo request;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0);
|
||||
IpcIoPushString(&request, dataPath);
|
||||
IpcIoPushInt32(&request, uid);
|
||||
IpcIoPushInt32(&request, gid);
|
||||
IpcIoPushBool(&request, isChown);
|
||||
|
||||
Lock<Mutex> lock(mutex_);
|
||||
#ifdef __LINUX__
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, CREATE_DATA_DIRECTORY, &request, this, Notify));
|
||||
#else
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, CREATE_DATA_DIRECTORY, &request, nullptr, nullptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t BundleDaemonClient::StoreContentToFile(const char *file, const void *buffer, uint32_t size)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return EC_NOINIT;
|
||||
}
|
||||
if (file == nullptr || buffer == nullptr || size == 0) {
|
||||
PRINTE("BundleDaemonClient", "invalid params");
|
||||
return EC_INVALID;
|
||||
}
|
||||
IpcIo request;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
#ifdef __LINUX__
|
||||
IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0);
|
||||
#else
|
||||
IpcIoInit(&request, data, IPC_IO_DATA_MAX, 1);
|
||||
#endif
|
||||
IpcIoPushString(&request, file);
|
||||
#ifdef __LINUX__
|
||||
IpcIoPushString(&request, static_cast<const char *>(buffer));
|
||||
#else
|
||||
BuffPtr dataBuff = {
|
||||
.buffSz = size, // include \0
|
||||
.buff = const_cast<void *>(buffer)
|
||||
};
|
||||
IpcIoPushDataBuff(&request, &dataBuff);
|
||||
#endif
|
||||
Lock<Mutex> lock(mutex_);
|
||||
#ifdef __LINUX__
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, STORE_CONTENT_TO_FILE, &request, this, Notify));
|
||||
#else
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, STORE_CONTENT_TO_FILE, &request, nullptr, nullptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t BundleDaemonClient::MoveFile(const char *oldFile, const char *newFile)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return EC_NOINIT;
|
||||
}
|
||||
if ((oldFile == nullptr) || (newFile == nullptr)) {
|
||||
PRINTE("BundleDaemonClient", "invalid params");
|
||||
return EC_INVALID;
|
||||
}
|
||||
IpcIo request;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0);
|
||||
IpcIoPushString(&request, oldFile);
|
||||
IpcIoPushString(&request, newFile);
|
||||
|
||||
Lock<Mutex> lock(mutex_);
|
||||
#ifdef __LINUX__
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, MOVE_FILE, &request, this, Notify));
|
||||
#else
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, MOVE_FILE, &request, nullptr, nullptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t BundleDaemonClient::RemoveFile(const char *file)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return EC_NOINIT;
|
||||
}
|
||||
if (file == nullptr) {
|
||||
PRINTE("BundleDaemonClient", "invalid params");
|
||||
return EC_INVALID;
|
||||
}
|
||||
IpcIo request;
|
||||
char data[IPC_IO_DATA_MAX];
|
||||
IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0);
|
||||
IpcIoPushString(&request, file);
|
||||
|
||||
Lock<Mutex> lock(mutex_);
|
||||
#ifdef __LINUX__
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, REMOVE_FILE, &request, this, Notify));
|
||||
#else
|
||||
return WaitResultSync(bdsClient_->Invoke(bdsClient_, REMOVE_FILE, &request, nullptr, nullptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t BundleDaemonClient::RemoveInstallDirectory(const char *codePath, const char *dataPath, bool keepData)
|
||||
{
|
||||
if (!initialized_) {
|
||||
return EC_NOINIT;
|
||||
}
|
||||
if (codePath == nullptr || dataPath == nullptr) {
|
||||
PRINTE("BundleDaemonClient", "invalid params: bundleName is nullptr");
|
||||
return EC_INVALID;
|
||||
}
|
||||
|
||||
return CallClientInvoke(REMOVE_INSTALL_DIRECTORY, codePath, dataPath);
|
||||
}
|
||||
} // OHOS
|
||||
+41
@@ -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.
|
||||
*/
|
||||
|
||||
#include "bundle_extractor.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "bundle_common.h"
|
||||
#include "bundle_util.h"
|
||||
#include "extractor_util.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
uint8_t BundleExtractor::ExtractHapProfile(const std::string &hapFile, std::ostringstream &profileStream)
|
||||
{
|
||||
ExtractorUtil extractorUtil(hapFile);
|
||||
if (!extractorUtil.Init()) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "BundleExtractor ExtractHapProfile init fail");
|
||||
return ERR_APPEXECFWK_INSTALL_FAILED_EXTRACTOR_NOT_INIT;
|
||||
}
|
||||
|
||||
if (!extractorUtil.ExtractFileByName(PROFILE_NAME, profileStream)) {
|
||||
HILOG_ERROR(HILOG_MODULE_APP, "it can not find json file!");
|
||||
return ERR_APPEXECFWK_INSTALL_FAILED_PARSE_PROFILE_ERROR;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace OHOS
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user