mirror of
https://gitee.com/openharmony/bundlemanager_bundle_framework
synced 2024-11-23 07:09:53 +00:00
add bundle features
Signed-off-by: changzheng6 <hanfeng6@huawei.com>
This commit is contained in:
parent
de77bdc9b8
commit
43b244ac82
@ -27,6 +27,8 @@ declare_args() {
|
||||
bundle_framework_graphics = true
|
||||
bundle_framework_free_install = true
|
||||
bundle_framework_default_app = true
|
||||
bundle_framework_launcher = true
|
||||
bundle_framework_sandbox_app = true
|
||||
|
||||
ability_runtime_enable = true
|
||||
account_enable = true
|
||||
@ -90,6 +92,8 @@ declare_args() {
|
||||
print("bundle_framework_graphics = " + "$bundle_framework_graphics")
|
||||
print("bundle_framework_free_install = " + "$bundle_framework_free_install")
|
||||
print("bundle_framework_default_app = " + "$bundle_framework_default_app")
|
||||
print("bundle_framework_launcher = " + "$bundle_framework_launcher")
|
||||
print("bundle_framework_sandbox_app = " + "$bundle_framework_sandbox_app")
|
||||
print("ability_runtime_enable = " + "$ability_runtime_enable")
|
||||
print("account_enable = " + "$account_enable")
|
||||
print("configpolicy_enable = " + "$configpolicy_enable")
|
||||
|
@ -16,7 +16,9 @@
|
||||
"features": [
|
||||
"bundle_framework_graphics",
|
||||
"bundle_framework_free_install",
|
||||
"bundle_framework_default_app"
|
||||
"bundle_framework_default_app",
|
||||
"bundle_framework_launcher",
|
||||
"bundle_framework_sandbox_app"
|
||||
],
|
||||
"hisysevent_config": [
|
||||
"//foundation/bundlemanager/bundle_framework/hisysevent.yaml"
|
||||
|
@ -130,6 +130,7 @@ enum {
|
||||
ERR_APPEXECFWK_SANDBOX_INSTALL_NO_SANDBOX_APP_INFO,
|
||||
ERR_APPEXECFWK_SANDBOX_INSTALL_UNKNOWN_INSTALL_TYPE,
|
||||
ERR_APPEXECFWK_SANDBOX_INSTALL_DELETE_APP_INDEX_FAILED,
|
||||
ERR_APPEXECFWK_SANDBOX_APP_NOT_SUPPORTED,
|
||||
|
||||
// sandbox app query
|
||||
ERR_APPEXECFWK_SANDBOX_QUERY_PARAM_ERROR,
|
||||
|
@ -19,12 +19,15 @@ group("napi_packages") {
|
||||
if (support_jsapi) {
|
||||
deps += [
|
||||
"bundlemgr:bundle",
|
||||
"launchermgr:innerbundlemanager",
|
||||
"package:package",
|
||||
]
|
||||
|
||||
if (bundle_framework_default_app) {
|
||||
deps += [ "default_app:defaultappmanager" ]
|
||||
}
|
||||
|
||||
if (bundle_framework_launcher) {
|
||||
deps += [ "launchermgr:innerbundlemanager" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -198,6 +198,11 @@ ohos_shared_library("libbms") {
|
||||
"syscap_codec:syscap_interface_shared",
|
||||
]
|
||||
|
||||
if (bundle_framework_sandbox_app) {
|
||||
sources += sandbox_app
|
||||
defines += [ "BUNDLE_FRAMEWORK_SANDBOX_APP" ]
|
||||
}
|
||||
|
||||
if (ability_runtime_enable) {
|
||||
external_deps += [ "ability_runtime:ability_manager" ]
|
||||
defines += [ "ABILITY_RUNTIME_ENABLE" ]
|
||||
|
@ -42,9 +42,7 @@ bundle_install_sources = [
|
||||
"${services_path}/bundlemgr/src/ipc/installd_host.cpp",
|
||||
"${services_path}/bundlemgr/src/ipc/installd_proxy.cpp",
|
||||
"${services_path}/bundlemgr/src/pre_install_bundle_info.cpp",
|
||||
"${services_path}/bundlemgr/src/sandbox_app/bundle_sandbox_data_mgr.cpp",
|
||||
"${services_path}/bundlemgr/src/sandbox_app/bundle_sandbox_exception_handler.cpp",
|
||||
"${services_path}/bundlemgr/src/sandbox_app/bundle_sandbox_installer.cpp",
|
||||
"${services_path}/bundlemgr/src/sandbox_app/bundle_sandbox_app_helper.cpp",
|
||||
"${services_path}/bundlemgr/src/status_receiver_proxy.cpp",
|
||||
"${services_path}/bundlemgr/src/system_bundle_installer.cpp",
|
||||
"${services_path}/bundlemgr/src/xcollie_helper.cpp",
|
||||
@ -83,6 +81,12 @@ default_app = [
|
||||
"${services_path}/bundlemgr/src/default_app/default_app_mgr.cpp",
|
||||
]
|
||||
|
||||
sandbox_app = [
|
||||
"${services_path}/bundlemgr/src/sandbox_app/bundle_sandbox_data_mgr.cpp",
|
||||
"${services_path}/bundlemgr/src/sandbox_app/bundle_sandbox_exception_handler.cpp",
|
||||
"${services_path}/bundlemgr/src/sandbox_app/bundle_sandbox_installer.cpp",
|
||||
]
|
||||
|
||||
if (bms_rdb_enable) {
|
||||
default_app +=
|
||||
[ "${services_path}/bundlemgr/src/default_app/default_app_rdb.cpp" ]
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "application_info.h"
|
||||
#include "bundle_data_storage_interface.h"
|
||||
#include "bundle_promise.h"
|
||||
#include "bundle_sandbox_data_mgr.h"
|
||||
#include "bundle_sandbox_app_helper.h"
|
||||
#include "bundle_state_storage.h"
|
||||
#include "bundle_status_callback_interface.h"
|
||||
#include "common_event_manager.h"
|
||||
@ -701,7 +701,7 @@ public:
|
||||
bool GetInnerBundleInfoWithFlags(const std::string &bundleName, const int32_t flags,
|
||||
InnerBundleInfo &info, int32_t userId = Constants::UNSPECIFIED_USERID) const;
|
||||
|
||||
std::shared_ptr<BundleSandboxDataMgr> GetSandboxDataMgr() const;
|
||||
std::shared_ptr<BundleSandboxAppHelper> GetSandboxAppHelper() const;
|
||||
void StoreSandboxPersistentInfo(const std::string &bundleName, const SandboxAppPersistentInfo &info);
|
||||
void DeleteSandboxPersistentInfo(const std::string &bundleName, const SandboxAppPersistentInfo &info);
|
||||
|
||||
@ -833,7 +833,7 @@ private:
|
||||
std::shared_ptr<BundleStateStorage> bundleStateStorage_;
|
||||
std::vector<PreInstallBundleInfo> preInstallBundleInfos_;
|
||||
std::shared_ptr<BundlePromise> bundlePromise_ = nullptr;
|
||||
std::shared_ptr<BundleSandboxDataMgr> sandboxDataMgr_;
|
||||
std::shared_ptr<BundleSandboxAppHelper> sandboxAppHelper_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_APP_HELPER_H
|
||||
#define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_APP_HELPER_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "bundle_data_storage_interface.h"
|
||||
#include "bundle_constants.h"
|
||||
#include "inner_bundle_info.h"
|
||||
#include "singleton.h"
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
#include "bundle_sandbox_data_mgr.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class BundleSandboxAppHelper : public DelayedSingleton<BundleSandboxAppHelper> {
|
||||
public:
|
||||
// BundleSandboxDataMgr interface
|
||||
void SaveSandboxAppInfo(const InnerBundleInfo &info, const int32_t &appIndex);
|
||||
void DeleteSandboxAppInfo(const std::string &bundleName, const int32_t &appIndex);
|
||||
ErrCode GetSandboxAppBundleInfo(
|
||||
const std::string &bundleName, const int32_t &appIndex, const int32_t &userId, BundleInfo &info) const;
|
||||
int32_t GenerateSandboxAppIndex(const std::string &bundleName);
|
||||
bool DeleteSandboxAppIndex(const std::string &bundleName, int32_t appIndex);
|
||||
std::unordered_map<std::string, InnerBundleInfo> GetSandboxAppInfoMap() const;
|
||||
ErrCode GetSandboxAppInfo(
|
||||
const std::string &bundleName, const int32_t &appIndex, int32_t &userId, InnerBundleInfo &info) const;
|
||||
ErrCode GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId,
|
||||
HapModuleInfo &hapModuleInfo) const;
|
||||
ErrCode GetInnerBundleInfoByUid(const int32_t &uid, InnerBundleInfo &innerBundleInfo) const;
|
||||
|
||||
// BundleSandboxExceptionHandler interface
|
||||
void RemoveSandboxApp(const std::shared_ptr<IBundleDataStorage> &dataStorage, InnerBundleInfo &info);
|
||||
|
||||
// BundleSandboxInstaller interface
|
||||
ErrCode InstallSandboxApp(const std::string &bundleName, const int32_t &dlpType, const int32_t &userId,
|
||||
int32_t &appIndex);
|
||||
|
||||
ErrCode UninstallSandboxApp(const std::string &bundleName, const int32_t &appIndex, const int32_t &userId);
|
||||
|
||||
ErrCode UninstallAllSandboxApps(const std::string &bundleName, int32_t userId = Constants::INVALID_USERID);
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
std::shared_ptr<BundleSandboxDataMgr> GetSandboxDataMgr() const
|
||||
{
|
||||
return sandboxDataMgr_;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
private:
|
||||
std::shared_ptr<BundleSandboxDataMgr> sandboxDataMgr_ = std::make_shared<BundleSandboxDataMgr>();
|
||||
#endif
|
||||
};
|
||||
} // AppExecFwk
|
||||
} // OHOS
|
||||
|
||||
#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_APP_HELPER_H
|
@ -28,7 +28,7 @@
|
||||
#include "bundle_constants.h"
|
||||
#include "bundle_extractor.h"
|
||||
#include "bundle_mgr_service.h"
|
||||
#include "bundle_sandbox_installer.h"
|
||||
#include "bundle_sandbox_app_helper.h"
|
||||
#include "bundle_permission_mgr.h"
|
||||
#include "bundle_util.h"
|
||||
#include "hitrace_meter.h"
|
||||
@ -1714,12 +1714,12 @@ ErrCode BaseBundleInstaller::UninstallAllSandboxApps(const std::string &bundleNa
|
||||
APP_LOGE("UninstallAllSandboxApps failed due to empty bundle name");
|
||||
return ERR_APPEXECFWK_INSTALL_PARAM_ERROR;
|
||||
}
|
||||
std::shared_ptr<BundleSandboxInstaller> installer = std::make_shared<BundleSandboxInstaller>();
|
||||
if (installer == nullptr) {
|
||||
APP_LOGE("UninstallAllSandboxApps failed due to installer nullptr");
|
||||
auto helper = DelayedSingleton<BundleSandboxAppHelper>::GetInstance();
|
||||
if (helper == nullptr) {
|
||||
APP_LOGE("UninstallAllSandboxApps failed due to helper nullptr");
|
||||
return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
if (installer->UninstallAllSandboxApps(bundleName, userId) != ERR_OK) {
|
||||
if (helper->UninstallAllSandboxApps(bundleName, userId) != ERR_OK) {
|
||||
APP_LOGE("UninstallAllSandboxApps failed");
|
||||
return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ BundleDataMgr::BundleDataMgr()
|
||||
preInstallDataStorage_ = std::make_shared<PreInstallDataStorage>();
|
||||
#endif
|
||||
distributedDataStorage_ = DistributedDataStorage::GetInstance();
|
||||
sandboxDataMgr_ = std::make_shared<BundleSandboxDataMgr>();
|
||||
sandboxAppHelper_ = DelayedSingleton<BundleSandboxAppHelper>::GetInstance();
|
||||
bundleStateStorage_ = std::make_shared<BundleStateStorage>();
|
||||
APP_LOGI("BundleDataMgr instance is created");
|
||||
}
|
||||
@ -488,11 +488,11 @@ bool BundleDataMgr::ExplicitQueryAbilityInfo(const Want &want, int32_t flags, in
|
||||
}
|
||||
// explict query from sandbox manager
|
||||
if (appIndex > 0) {
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
if (sandboxAppHelper_ == nullptr) {
|
||||
APP_LOGE("sandboxAppHelper_ is nullptr");
|
||||
return false;
|
||||
}
|
||||
auto ret = sandboxDataMgr_->GetSandboxAppInfo(bundleName, appIndex, requestUserId, innerBundleInfo);
|
||||
auto ret = sandboxAppHelper_->GetSandboxAppInfo(bundleName, appIndex, requestUserId, innerBundleInfo);
|
||||
if (ret != ERR_OK) {
|
||||
APP_LOGE("obtain innerBundleInfo of sandbox app failed due to errCode %{public}d", ret);
|
||||
return false;
|
||||
@ -605,11 +605,11 @@ bool BundleDataMgr::ImplicitQueryCurAbilityInfos(const Want &want, int32_t flags
|
||||
return false;
|
||||
}
|
||||
if (appIndex > 0) {
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
if (sandboxAppHelper_ == nullptr) {
|
||||
APP_LOGE("sandboxAppHelper_ is nullptr");
|
||||
return false;
|
||||
}
|
||||
auto ret = sandboxDataMgr_->GetSandboxAppInfo(bundleName, appIndex, userId, innerBundleInfo);
|
||||
auto ret = sandboxAppHelper_->GetSandboxAppInfo(bundleName, appIndex, userId, innerBundleInfo);
|
||||
if (ret != ERR_OK) {
|
||||
APP_LOGE("obtain innerBundleInfo of sandbox app failed due to errCode %{public}d", ret);
|
||||
return false;
|
||||
@ -640,11 +640,11 @@ void BundleDataMgr::ImplicitQueryAllAbilityInfos(const Want &want, int32_t flags
|
||||
}
|
||||
} else {
|
||||
// query from sandbox manager for sandbox bundle
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
if (sandboxAppHelper_ == nullptr) {
|
||||
APP_LOGE("sandboxAppHelper_ is nullptr");
|
||||
return;
|
||||
}
|
||||
auto sandboxMap = sandboxDataMgr_->GetSandboxAppInfoMap();
|
||||
auto sandboxMap = sandboxAppHelper_->GetSandboxAppInfoMap();
|
||||
for (const auto &item : sandboxMap) {
|
||||
InnerBundleInfo info;
|
||||
size_t pos = item.first.rfind(Constants::FILE_UNDERLINE);
|
||||
@ -653,7 +653,7 @@ void BundleDataMgr::ImplicitQueryAllAbilityInfos(const Want &want, int32_t flags
|
||||
continue;
|
||||
}
|
||||
std::string innerBundleName = item.first.substr(0, pos);
|
||||
if (sandboxDataMgr_->GetSandboxAppInfo(innerBundleName, appIndex, userId, info) != ERR_OK) {
|
||||
if (sandboxAppHelper_->GetSandboxAppInfo(innerBundleName, appIndex, userId, info) != ERR_OK) {
|
||||
APP_LOGW("obtain innerBundleInfo of sandbox app failed");
|
||||
continue;
|
||||
}
|
||||
@ -1128,12 +1128,12 @@ bool BundleDataMgr::GetBundleNameForUid(const int uid, std::string &bundleName)
|
||||
InnerBundleInfo innerBundleInfo;
|
||||
if (!GetInnerBundleInfoByUid(uid, innerBundleInfo)) {
|
||||
APP_LOGW("get innerBundleInfo from bundleInfo_ by uid failed.");
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
if (sandboxAppHelper_ == nullptr) {
|
||||
APP_LOGE("sandboxAppHelper_ is nullptr");
|
||||
return false;
|
||||
}
|
||||
if (sandboxDataMgr_->GetInnerBundleInfoByUid(uid, innerBundleInfo) != ERR_OK) {
|
||||
APP_LOGE("get innerBundleInfo from sandboxDataMgr by uid failed.");
|
||||
if (sandboxAppHelper_->GetInnerBundleInfoByUid(uid, innerBundleInfo) != ERR_OK) {
|
||||
APP_LOGE("get innerBundleInfo by uid failed.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1812,9 +1812,9 @@ std::shared_ptr<Media::PixelMap> BundleDataMgr::GetAbilityPixelMapIcon(const std
|
||||
}
|
||||
#endif
|
||||
|
||||
std::shared_ptr<BundleSandboxDataMgr> BundleDataMgr::GetSandboxDataMgr() const
|
||||
std::shared_ptr<BundleSandboxAppHelper> BundleDataMgr::GetSandboxAppHelper() const
|
||||
{
|
||||
return sandboxDataMgr_;
|
||||
return sandboxAppHelper_;
|
||||
}
|
||||
bool BundleDataMgr::RegisterBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback)
|
||||
{
|
||||
@ -2577,11 +2577,11 @@ bool BundleDataMgr::ExplicitQueryExtensionInfo(const Want &want, int32_t flags,
|
||||
return false;
|
||||
}
|
||||
if (appIndex > 0) {
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
if (sandboxAppHelper_ == nullptr) {
|
||||
APP_LOGE("sandboxAppHelper_ is nullptr");
|
||||
return false;
|
||||
}
|
||||
auto ret = sandboxDataMgr_->GetSandboxAppInfo(bundleName, appIndex, requestUserId, innerBundleInfo);
|
||||
auto ret = sandboxAppHelper_->GetSandboxAppInfo(bundleName, appIndex, requestUserId, innerBundleInfo);
|
||||
if (ret != ERR_OK) {
|
||||
APP_LOGE("obtain innerBundleInfo of sandbox app failed due to errCode %{public}d", ret);
|
||||
return false;
|
||||
@ -2670,11 +2670,11 @@ bool BundleDataMgr::ImplicitQueryCurExtensionInfos(const Want &want, int32_t fla
|
||||
return false;
|
||||
}
|
||||
if (appIndex > 0) {
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
if (sandboxAppHelper_ == nullptr) {
|
||||
APP_LOGE("sandboxAppHelper_ is nullptr");
|
||||
return false;
|
||||
}
|
||||
auto ret = sandboxDataMgr_->GetSandboxAppInfo(bundleName, appIndex, userId, innerBundleInfo);
|
||||
auto ret = sandboxAppHelper_->GetSandboxAppInfo(bundleName, appIndex, userId, innerBundleInfo);
|
||||
if (ret != ERR_OK) {
|
||||
APP_LOGE("obtain innerBundleInfo of sandbox app failed due to errCode %{public}d", ret);
|
||||
return false;
|
||||
@ -2704,11 +2704,11 @@ void BundleDataMgr::ImplicitQueryAllExtensionInfos(const Want &want, int32_t fla
|
||||
}
|
||||
} else {
|
||||
// query from sandbox manager for sandbox bundle
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
if (sandboxAppHelper_ == nullptr) {
|
||||
APP_LOGE("sandboxAppHelper_ is nullptr");
|
||||
return;
|
||||
}
|
||||
auto sandboxMap = sandboxDataMgr_->GetSandboxAppInfoMap();
|
||||
auto sandboxMap = sandboxAppHelper_->GetSandboxAppInfoMap();
|
||||
for (const auto &item : sandboxMap) {
|
||||
InnerBundleInfo info;
|
||||
size_t pos = item.first.rfind(Constants::FILE_UNDERLINE);
|
||||
@ -2717,7 +2717,7 @@ void BundleDataMgr::ImplicitQueryAllExtensionInfos(const Want &want, int32_t fla
|
||||
continue;
|
||||
}
|
||||
std::string innerBundleName = item.first.substr(0, pos);
|
||||
if (sandboxDataMgr_->GetSandboxAppInfo(innerBundleName, appIndex, userId, info) != ERR_OK) {
|
||||
if (sandboxAppHelper_->GetSandboxAppInfo(innerBundleName, appIndex, userId, info) != ERR_OK) {
|
||||
APP_LOGW("obtain innerBundleInfo of sandbox app failed");
|
||||
continue;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "bundle_exception_handler.h"
|
||||
#include "bundle_sandbox_exception_handler.h"
|
||||
#include "bundle_sandbox_app_helper.h"
|
||||
|
||||
#include "kvstore_death_recipient_callback.h"
|
||||
|
||||
@ -74,8 +74,7 @@ void BundleDataStorageDatabase::SaveEntries(
|
||||
bool isBundleValid = true;
|
||||
auto handler = std::make_shared<BundleExceptionHandler>(shared_from_this());
|
||||
handler->HandleInvalidBundle(innerBundleInfo, isBundleValid);
|
||||
auto sandboxHandler = std::make_shared<BundleSandboxExceptionHandler>(shared_from_this());
|
||||
sandboxHandler->RemoveSandboxApp(innerBundleInfo);
|
||||
DelayedSingleton<BundleSandboxAppHelper>::GetInstance()->RemoveSandboxApp(shared_from_this(), innerBundleInfo);
|
||||
if (!isBundleValid) {
|
||||
continue;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
#include "bundle_exception_handler.h"
|
||||
#include "bundle_sandbox_exception_handler.h"
|
||||
#include "bundle_sandbox_app_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@ -83,8 +83,7 @@ void BundleDataStorageRdb::TransformStrToInfo(
|
||||
bool isBundleValid = true;
|
||||
auto handler = std::make_shared<BundleExceptionHandler>(shared_from_this());
|
||||
handler->HandleInvalidBundle(innerBundleInfo, isBundleValid);
|
||||
auto sandboxHandler = std::make_shared<BundleSandboxExceptionHandler>(shared_from_this());
|
||||
sandboxHandler->RemoveSandboxApp(innerBundleInfo);
|
||||
DelayedSingleton<BundleSandboxAppHelper>::GetInstance()->RemoveSandboxApp(shared_from_this(), innerBundleInfo);
|
||||
if (!isBundleValid) {
|
||||
continue;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "bundle_constants.h"
|
||||
#include "bundle_permission_mgr.h"
|
||||
#include "bundle_sandbox_installer.h"
|
||||
#include "bundle_sandbox_app_helper.h"
|
||||
#include "bundle_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -406,11 +406,11 @@ ErrCode BundleInstallerHost::InstallSandboxApp(const std::string &bundleName, in
|
||||
APP_LOGE("install sandbox failed due to error parameters");
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
|
||||
}
|
||||
std::shared_ptr<BundleSandboxInstaller> installer = std::make_shared<BundleSandboxInstaller>();
|
||||
if (installer == nullptr) {
|
||||
auto helper = DelayedSingleton<BundleSandboxAppHelper>::GetInstance();
|
||||
if (helper == nullptr) {
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
auto res = installer->InstallSandboxApp(bundleName, dplType, userId, appIndex);
|
||||
auto res = helper->InstallSandboxApp(bundleName, dplType, userId, appIndex);
|
||||
if (res != ERR_OK) {
|
||||
APP_LOGE("install sandbox failed due to error code : %{public}d", res);
|
||||
}
|
||||
@ -429,11 +429,11 @@ ErrCode BundleInstallerHost::UninstallSandboxApp(const std::string &bundleName,
|
||||
APP_LOGE("the appIndex %{public}d is invalid", appIndex);
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
|
||||
}
|
||||
std::shared_ptr<BundleSandboxInstaller> installer = std::make_shared<BundleSandboxInstaller>();
|
||||
if (installer == nullptr) {
|
||||
auto helper = DelayedSingleton<BundleSandboxAppHelper>::GetInstance();
|
||||
if (helper == nullptr) {
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
auto res = installer->UninstallSandboxApp(bundleName, appIndex, userId);
|
||||
auto res = helper->UninstallSandboxApp(bundleName, appIndex, userId);
|
||||
if (res != ERR_OK) {
|
||||
APP_LOGE("uninstall sandbox failed due to error code : %{public}d", res);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "bundle_mgr_service.h"
|
||||
#include "bundle_parser.h"
|
||||
#include "bundle_permission_mgr.h"
|
||||
#include "bundle_sandbox_app_helper.h"
|
||||
#include "bundle_util.h"
|
||||
#include "directory_ex.h"
|
||||
#include "element_name.h"
|
||||
@ -1526,16 +1527,16 @@ ErrCode BundleMgrHostImpl::GetSandboxBundleInfo(
|
||||
APP_LOGE("DataMgr is nullptr");
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
auto sandboxDataMgr = dataMgr->GetSandboxDataMgr();
|
||||
if (sandboxDataMgr == nullptr) {
|
||||
APP_LOGE("sandDataMgr is nullptr");
|
||||
auto sandboxAppHelper = dataMgr->GetSandboxAppHelper();
|
||||
if (sandboxAppHelper == nullptr) {
|
||||
APP_LOGE("sandboxAppHelper is nullptr");
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
int32_t requestUserId = dataMgr->GetUserId(userId);
|
||||
if (requestUserId == Constants::INVALID_USERID) {
|
||||
return ERR_APPEXECFWK_SANDBOX_QUERY_INVALID_USER_ID;
|
||||
}
|
||||
return sandboxDataMgr->GetSandboxAppBundleInfo(bundleName, appIndex, requestUserId, info);
|
||||
return sandboxAppHelper->GetSandboxAppBundleInfo(bundleName, appIndex, requestUserId, info);
|
||||
}
|
||||
|
||||
bool BundleMgrHostImpl::SetDisposedStatus(const std::string &bundleName, int32_t status)
|
||||
@ -1641,16 +1642,16 @@ ErrCode BundleMgrHostImpl::GetSandboxHapModuleInfo(const AbilityInfo &abilityInf
|
||||
APP_LOGE("DataMgr is nullptr");
|
||||
return ERR_APPEXECFWK_SANDBOX_QUERY_INTERNAL_ERROR;
|
||||
}
|
||||
auto sandboxDataMgr = dataMgr->GetSandboxDataMgr();
|
||||
if (sandboxDataMgr == nullptr) {
|
||||
APP_LOGE("sandDataMgr is nullptr");
|
||||
auto sandboxAppHelper = dataMgr->GetSandboxAppHelper();
|
||||
if (sandboxAppHelper == nullptr) {
|
||||
APP_LOGE("sandboxAppHelper is nullptr");
|
||||
return ERR_APPEXECFWK_SANDBOX_QUERY_INTERNAL_ERROR;
|
||||
}
|
||||
int32_t requestUserId = dataMgr->GetUserId(userId);
|
||||
if (requestUserId == Constants::INVALID_USERID) {
|
||||
return ERR_APPEXECFWK_SANDBOX_QUERY_INVALID_USER_ID;
|
||||
}
|
||||
return sandboxDataMgr->GetSandboxHapModuleInfo(abilityInfo, appIndex, requestUserId, info);
|
||||
return sandboxAppHelper->GetSandboxHapModuleInfo(abilityInfo, appIndex, requestUserId, info);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
231
services/bundlemgr/src/sandbox_app/bundle_sandbox_app_helper.cpp
Normal file
231
services/bundlemgr/src/sandbox_app/bundle_sandbox_app_helper.cpp
Normal file
@ -0,0 +1,231 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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_sandbox_app_helper.h"
|
||||
|
||||
#include "app_log_wrapper.h"
|
||||
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
#include "bundle_sandbox_installer.h"
|
||||
#include "bundle_sandbox_exception_handler.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
void BundleSandboxAppHelper::SaveSandboxAppInfo(const InnerBundleInfo &info, const int32_t &appIndex)
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
return;
|
||||
}
|
||||
sandboxDataMgr_->SaveSandboxAppInfo(info, appIndex);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
#endif
|
||||
}
|
||||
|
||||
void BundleSandboxAppHelper::DeleteSandboxAppInfo(const std::string &bundleName, const int32_t &appIndex)
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
return;
|
||||
}
|
||||
sandboxDataMgr_->DeleteSandboxAppInfo(bundleName, appIndex);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
#endif
|
||||
}
|
||||
|
||||
ErrCode BundleSandboxAppHelper::GetSandboxAppBundleInfo(
|
||||
const std::string &bundleName, const int32_t &appIndex, const int32_t &userId, BundleInfo &info) const
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
return sandboxDataMgr_->GetSandboxAppBundleInfo(bundleName, appIndex, userId, info);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
return ERR_APPEXECFWK_SANDBOX_APP_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t BundleSandboxAppHelper::GenerateSandboxAppIndex(const std::string &bundleName)
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
return Constants::INITIAL_APP_INDEX;
|
||||
}
|
||||
return sandboxDataMgr_->GenerateSandboxAppIndex(bundleName);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
return Constants::INITIAL_APP_INDEX;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool BundleSandboxAppHelper::DeleteSandboxAppIndex(const std::string &bundleName, int32_t appIndex)
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
return false;
|
||||
}
|
||||
return sandboxDataMgr_->DeleteSandboxAppIndex(bundleName, appIndex);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, InnerBundleInfo> BundleSandboxAppHelper::GetSandboxAppInfoMap() const
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
std::unordered_map<std::string, InnerBundleInfo> innerBundleInfoMap;
|
||||
return innerBundleInfoMap;
|
||||
}
|
||||
return sandboxDataMgr_->GetSandboxAppInfoMap();
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
std::unordered_map<std::string, InnerBundleInfo> innerBundleInfoMap;
|
||||
return innerBundleInfoMap;
|
||||
#endif
|
||||
}
|
||||
|
||||
ErrCode BundleSandboxAppHelper::GetSandboxAppInfo(
|
||||
const std::string &bundleName, const int32_t &appIndex, int32_t &userId, InnerBundleInfo &info) const
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
return sandboxDataMgr_->GetSandboxAppInfo(bundleName, appIndex, userId, info);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
return ERR_APPEXECFWK_SANDBOX_APP_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
ErrCode BundleSandboxAppHelper::GetSandboxHapModuleInfo(
|
||||
const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId, HapModuleInfo &hapModuleInfo) const
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
return sandboxDataMgr_->GetSandboxHapModuleInfo(abilityInfo, appIndex, userId, hapModuleInfo);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
return ERR_APPEXECFWK_SANDBOX_APP_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
ErrCode BundleSandboxAppHelper::GetInnerBundleInfoByUid(const int32_t &uid, InnerBundleInfo &innerBundleInfo) const
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("sandboxDataMgr_ is nullptr");
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
return sandboxDataMgr_->GetInnerBundleInfoByUid(uid, innerBundleInfo);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
return ERR_APPEXECFWK_SANDBOX_APP_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
void BundleSandboxAppHelper::RemoveSandboxApp(
|
||||
const std::shared_ptr<IBundleDataStorage> &dataStorage, InnerBundleInfo &info)
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
auto sandboxHandler = std::make_shared<BundleSandboxExceptionHandler>(dataStorage);
|
||||
if (sandboxHandler == nullptr) {
|
||||
APP_LOGE("sandboxHandler is nullptr");
|
||||
return;
|
||||
}
|
||||
sandboxHandler->RemoveSandboxApp(info);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
#endif
|
||||
}
|
||||
|
||||
ErrCode BundleSandboxAppHelper::InstallSandboxApp(const std::string &bundleName, const int32_t &dlpType,
|
||||
const int32_t &userId, int32_t &appIndex)
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
std::shared_ptr<BundleSandboxInstaller> installer = std::make_shared<BundleSandboxInstaller>();
|
||||
if (installer == nullptr) {
|
||||
APP_LOGE("installer is nullptr");
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
return installer->InstallSandboxApp(bundleName, dlpType, userId, appIndex);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
return ERR_APPEXECFWK_SANDBOX_APP_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
ErrCode BundleSandboxAppHelper::UninstallSandboxApp(
|
||||
const std::string &bundleName, const int32_t &appIndex, const int32_t &userId)
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
std::shared_ptr<BundleSandboxInstaller> installer = std::make_shared<BundleSandboxInstaller>();
|
||||
if (installer == nullptr) {
|
||||
APP_LOGE("installer is nullptr");
|
||||
return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
return installer->UninstallSandboxApp(bundleName, appIndex, userId);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
return ERR_APPEXECFWK_SANDBOX_APP_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
ErrCode BundleSandboxAppHelper::UninstallAllSandboxApps(const std::string &bundleName, int32_t userId)
|
||||
{
|
||||
#ifdef BUNDLE_FRAMEWORK_SANDBOX_APP
|
||||
APP_LOGI("enter");
|
||||
std::shared_ptr<BundleSandboxInstaller> installer = std::make_shared<BundleSandboxInstaller>();
|
||||
if (installer == nullptr) {
|
||||
APP_LOGE("installer is nullptr");
|
||||
return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
return installer->UninstallAllSandboxApps(bundleName, userId);
|
||||
#else
|
||||
APP_LOGI("sandbox app not supported");
|
||||
return ERR_APPEXECFWK_SANDBOX_APP_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
} // AppExecFwk
|
||||
} // OHOS
|
@ -362,7 +362,7 @@ ErrCode BundleSandboxInstaller::GetSandboxDataMgr()
|
||||
return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
sandboxDataMgr_ = dataMgr_->GetSandboxDataMgr();
|
||||
sandboxDataMgr_ = dataMgr_->GetSandboxAppHelper()->GetSandboxDataMgr();
|
||||
if (sandboxDataMgr_ == nullptr) {
|
||||
APP_LOGE("Get sandbox dataMgr shared_ptr nullptr");
|
||||
return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR;
|
||||
|
@ -49,6 +49,8 @@ ohos_unittest("BmsSandboxAppTest") {
|
||||
|
||||
sources += bundle_install_sources
|
||||
|
||||
sources += sandbox_app
|
||||
|
||||
sources += [ "bms_bundle_sandbox_app_test.cpp" ]
|
||||
|
||||
configs = [
|
||||
@ -88,6 +90,11 @@ ohos_unittest("BmsSandboxAppTest") {
|
||||
]
|
||||
|
||||
defines = []
|
||||
|
||||
if (bundle_framework_sandbox_app) {
|
||||
defines += [ "BUNDLE_FRAMEWORK_SANDBOX_APP" ]
|
||||
}
|
||||
|
||||
if (configpolicy_enable) {
|
||||
external_deps += [ "config_policy:configpolicy_util" ]
|
||||
defines += [ "CONFIG_POLOCY_ENABLE" ]
|
||||
@ -135,7 +142,7 @@ ohos_unittest("BmsSandboxAppTest") {
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
if (ability_runtime_enable) {
|
||||
if (ability_runtime_enable && bundle_framework_sandbox_app) {
|
||||
deps = [ ":BmsSandboxAppTest" ]
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ bool BmsSandboxAppTest::GetSandboxDataMgr()
|
||||
return false;
|
||||
}
|
||||
|
||||
sandboxDataMgr_ = dataMgr_->GetSandboxDataMgr();
|
||||
sandboxDataMgr_ = dataMgr_->GetSandboxAppHelper()->GetSandboxDataMgr();
|
||||
if (!sandboxDataMgr_) {
|
||||
APP_LOGE("Get sandbox dataMgr shared_ptr nullptr");
|
||||
return false;
|
||||
|
@ -31,6 +31,10 @@ ohos_systemtest("BundleMgrSandboxAppSystemTest") {
|
||||
|
||||
defines = [ "APP_LOG_TAG = \"BundleMgrTool\"" ]
|
||||
|
||||
if (bundle_framework_sandbox_app) {
|
||||
defines += [ "BUNDLE_FRAMEWORK_SANDBOX_APP" ]
|
||||
}
|
||||
|
||||
if (bundle_framework_graphics) {
|
||||
public_deps = [
|
||||
"//third_party/icu/icu4c:shared_icuuc",
|
||||
@ -54,5 +58,7 @@ ohos_systemtest("BundleMgrSandboxAppSystemTest") {
|
||||
group("systemtest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":BundleMgrSandboxAppSystemTest" ]
|
||||
if (bundle_framework_sandbox_app) {
|
||||
deps = [ ":BundleMgrSandboxAppSystemTest" ]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user