增加应用市场跳转

Signed-off-by: zylworkhard1 <zhangyongliang21@huawei.com>
This commit is contained in:
zylworkhard1
2024-12-04 11:08:00 +08:00
parent dec5c344bc
commit 987c9a9d5a
52 changed files with 2156 additions and 7 deletions
+1
View File
@@ -23,6 +23,7 @@ group("app_domain_verify_packages") {
"frameworks/common:app_domain_verify_frameworks_common",
"frameworks/extension:app_domain_verify_extension_framework",
"frameworks/verifier:app_domain_verify_agent_verifier",
"frameworks/app_details_rdb:app_domain_verify_app_details_rdb",
"interfaces/inner_api/client:app_domain_verify_agent_client",
"interfaces/inner_api/client:app_domain_verify_mgr_client",
"interfaces/inner_api/common:app_domain_verify_common",
+3
View File
@@ -39,4 +39,7 @@ app_domain_verify_frameworks_common_path =
app_domain_verify_frameworks_verifier_path =
"${app_domain_verify_root_path}/frameworks/verifier"
app_domain_verify_frameworks_app_details_rdb_path =
"${app_domain_verify_root_path}/frameworks/app_details_rdb"
app_domain_verify_test_path = "${app_domain_verify_root_path}/test/unittest"
+11
View File
@@ -133,6 +133,17 @@
],
"header_base": "//foundation/bundlemanager/app_domain_verify/frameworks/verifier/include"
}
},
{
"name": "//foundation/bundlemanager/app_domain_verify/frameworks/app_details_rdb:app_domain_verify_app_details_rdb",
"header": {
"header_files": [
"app_details_rdb_data_define.h",
"app_details_rdb_data_manager.h",
"app_details_rdb_open_callback.h"
],
"header_base": "//foundation/bundlemanager/app_domain_verify/frameworks/app_details_rdb/include"
}
}
],
"test": [
+76
View File
@@ -0,0 +1,76 @@
# Copyright (C) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/bundlemanager/app_domain_verify/app_domain_verify.gni")
config("app_domain_verify_app_details_rdb_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
"${app_domain_verify_frameworks_common_path}/include"
]
configs = [ "//build/config/compiler:exceptions" ]
ldflags = [ "-Wl,--exclude-libs=ALL" ]
cflags = [
"-fdata-sections",
"-ffunction-sections",
"-fstack-protector-strong",
"-D_FORTIFY_SOURCE=2",
"-Os",
]
cflags_cc = [ "-Os" ]
}
ohos_shared_library("app_domain_verify_app_details_rdb") {
branch_protector_ret = "pac_ret"
sources = [
"src/app_details_rdb_data_manager.cpp",
"src/app_details_rdb_open_callback.cpp",
"src/app_details_meta_item.cpp",
"src/app_details_rdb_item.cpp"
]
public_configs = [ ":app_domain_verify_app_details_rdb_config" ]
external_deps = [
"ability_base:base",
"ability_base:want",
"ability_runtime:ability_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"curl:curl_shared",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"ipc:ipc_core",
"json:nlohmann_json_static",
"netstack:http_client",
"os_account:os_account_innerkits",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = []
if (build_variant == "user") {
defines += [ "IS_RELEASE_VERSION" ]
}
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
subsystem_name = "bundlemanager"
part_name = "app_domain_verify"
}
@@ -0,0 +1,19 @@
# Copyright (c) 2024 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.
1.0 {
global:
*;
local:
*;
};
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APP_DOMAIN_VERIFY_SERVICE_APP_DETAILS_BASE_ITEM_H
#define APP_DOMAIN_VERIFY_SERVICE_APP_DETAILS_BASE_ITEM_H
#include <filesystem>
#include <string>
#include "rdb_store.h"
namespace OHOS {
namespace AppDomainVerify {
using namespace NativeRdb;
class AppDetailsBaseItem {
public:
virtual ~AppDetailsBaseItem() = default;
virtual bool GetRdbItem(std::shared_ptr<AbsSharedResultSet>& retSet) = 0;
virtual void AddRdbItemToBucket(NativeRdb::ValuesBucket& bucket) = 0;
};
}
}
#endif
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APP_DOMAIN_VERIFY_SERVICE_APP_DETAILS_META_ITEM_H
#define APP_DOMAIN_VERIFY_SERVICE_APP_DETAILS_META_ITEM_H
#include "app_details_base_item.h"
namespace OHOS {
namespace AppDomainVerify {
class MetaItem : public AppDetailsBaseItem {
public:
bool GetRdbItem(std::shared_ptr<AbsSharedResultSet>& retSet) override;
void AddRdbItemToBucket(NativeRdb::ValuesBucket& bucket) override;
public:
std::string tableName;
std::string tableVersion;
std::string tableExtInfo;
std::string updateTime;
};
}
}
#endif
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APP_DOMAIN_VERIFY_SERVICE_APP_DETAILS_CONST_DEFINE_H
#define APP_DOMAIN_VERIFY_SERVICE_APP_DETAILS_CONST_DEFINE_H
#include <stdint.h>
#include <string>
namespace OHOS {
namespace AppDomainVerify {
const std::string DETAILS_ID = "ID";
const std::string DETAILS_SCHEME = "SCHEME";
const std::string DETAILS_DOMAIN = "DOMAIN";
const std::string DETAILS_PATH_TYPE = "PATH_TYPE";
const std::string DETAILS_PATH = "PATH";
const std::string DETAILS_BUNDLE_NAME = "BUNDLE_NAME";
const int32_t DETAILS_ID_INDEX = 0;
const int32_t DETAILS_SCHEME_INDEX = 1;
const int32_t DETAILS_DOMAIN_INDEX = 2;
const int32_t DETAILS_PATH_TYPE_INDEX = 3;
const int32_t DETAILS_PATH_INDEX = 4;
const int32_t DETAILS_BUNDLE_NAME_INDEX = 5;
const std::string META_TABLE_NAME = "TABLE_NAME";
const std::string META_TABLE_VERSION = "TABLE_VERSION";
const std::string META_TABLE_EXT_INFO = "TABLE_EXT_INFO";
const std::string META_UPDATE_TIME = "UPDATE_TIME";
const int32_t META_TABLE_NAME_INDEX = 0;
const int32_t META_TABLE_VERSION_INDEX = 1;
const int32_t META_TABLE_EXT_INFO_INDEX = 2;
const int32_t META_UPDATE_TIME_INDEX = 3;
constexpr int32_t CLOSE_DELAY_TIME_S = 20000; // 20s
const std::string CLOSE_TASK_ID = "closeRdb";
const std::string APP_DETAILS_TABLE = "APP_DETAILS";
const std::string META_DATA = "META_DATA";
const std::string APP_DETAILS_RDB_PATH = "/data/service/el1/public/app_domain_verify_agent_service/";
const std::string APP_DETAILS_RDB_NAME = "appDetails.db";
const int APP_DETAILS_RDB_VERSION = 1;
}
}
#endif
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APP_DOMAIN_VERIFY_SERVICE_INCLUDE_RDB_DATA_DEFINE_H
#define APP_DOMAIN_VERIFY_SERVICE_INCLUDE_RDB_DATA_DEFINE_H
#include <filesystem>
#include <string>
#include "app_details_base_item.h"
#include "app_details_meta_item.h"
#include "app_details_rdb_item.h"
namespace OHOS {
namespace AppDomainVerify {
using TransCallback = std::function<bool()>;
const static std::string PATH = "path";
const static std::string PATH_START_WITH = "pathStartWith";
const static std::string PATH_REGEX = "pathRegex";
struct RdbConfigInfo {
std::string rdbPath;
std::string rdbName;
int version = 0;
bool fileCreated = true;
};
}
}
#endif // APP_DOMAIN_VERIFY_SERVICE_INCLUDE_RDB_DATA_MANAGER_H
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APP_DOMAIN_VERIFY_SERVICE_INCLUDE_APP_DETAILS_RDB_DATA_MANAGER_H
#define APP_DOMAIN_VERIFY_SERVICE_INCLUDE_APP_DETAILS_RDB_DATA_MANAGER_H
#include <mutex>
#include "cpp/mutex.h"
#include "event_handler.h"
#include "rdb_store.h"
#include "values_bucket.h"
#include "app_details_rdb_data_define.h"
#include "ffrt.h"
namespace OHOS {
namespace AppDomainVerify {
using RdbForEachRetCb = std::function<bool(std::shared_ptr<AbsSharedResultSet> retSet)>;
class AppDetailsRdbDataMgr : public std::enable_shared_from_this<AppDetailsRdbDataMgr> {
public:
AppDetailsRdbDataMgr(bool createFile);
AppDetailsRdbDataMgr(const RdbConfigInfo& info);
virtual ~AppDetailsRdbDataMgr();
bool ExecWithTrans(TransCallback cb);
bool InsertDataBatch(const std::string& tableName, std::vector<AppDetailsRdbItem>& itemVec);
bool QueryDataByDomain(const std::string& tableName,
const std::string& domain, std::vector<AppDetailsRdbItem>& itemVec);
bool UpdateMetaData(std::vector<MetaItem>& item);
bool QueryMetaData(const std::string& tableName, MetaItem& info);
bool CreateMetaData();
bool CreateTable(const std::string& tableName);
bool DeleteTable(const std::string& tableName);
bool RenameTable(const std::string& oldName, const std::string& newName);
std::string GetDbVersion();
private:
void PostDelayCloseTask(int32_t delayTime);
bool Query(const NativeRdb::AbsRdbPredicates& predicates,
const std::vector<std::string>& columns, RdbForEachRetCb cb);
bool CheckRdbReturnIfOk(int errcode);
std::shared_ptr<NativeRdb::RdbStore> GetRdbStore();
private:
ffrt::mutex mtx_;
std::shared_ptr<NativeRdb::RdbStore> rdbStore_;
RdbConfigInfo conf_;
std::shared_ptr<AppExecFwk::EventHandler> closeHandler_;
std::shared_ptr<AppExecFwk::EventRunner> runner_;
};
} // namespace AppDomainVerify
} // namespace OHOS
#endif
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APP_DOMAIN_VERIFY_SERVICE_APP_DETAILS_RDB_ITEM_H
#define APP_DOMAIN_VERIFY_SERVICE_APP_DETAILS_RDB_ITEM_H
#include <string>
#include "app_details_base_item.h"
namespace OHOS {
namespace AppDomainVerify {
class AppDetailsRdbItem :public AppDetailsBaseItem {
public:
bool GetRdbItem(std::shared_ptr<AbsSharedResultSet>& retSet) override;
void AddRdbItemToBucket(NativeRdb::ValuesBucket& bucket) override;
public:
std::string id;
std::string scheme;
std::string domain;
std::string pathType;
std::string path;
std::string bundleName;
};
}
}
#endif
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APP_DOMAIN_VERIFY_SERVICE_INCLUDE_APP_DETAILS_RDB_OPEN_CALLBACK_H
#define APP_DOMAIN_VERIFY_SERVICE_INCLUDE_APP_DETAILS_RDB_OPEN_CALLBACK_H
#include "app_details_rdb_data_define.h"
#include "rdb_errno.h"
#include "rdb_open_callback.h"
namespace OHOS {
namespace AppDomainVerify {
class AppDetailsRdbOpenCallback : public NativeRdb::RdbOpenCallback {
public:
AppDetailsRdbOpenCallback(const RdbConfigInfo &rdbConfig);
int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override;
int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion) override;
int32_t OnDowngrade(NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion) override;
int32_t OnOpen(NativeRdb::RdbStore &rdbStore) override;
int32_t onCorruption(std::string databaseFile) override;
private:
RdbConfigInfo m_conf;
};
} // namespace AppDomainVerify
} // namespace OHOS
#endif // APP_DOMAIN_VERIFY_SERVICE_INCLUDE_APP_DETAILS_RDB_OPEN_CALLBACK_H
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_details_meta_item.h"
#include "app_details_rdb_const_define.h"
namespace OHOS {
namespace AppDomainVerify {
bool MetaItem::GetRdbItem(std::shared_ptr<AbsSharedResultSet> &retSet)
{
int errCode = NativeRdb::E_OK;
errCode = retSet->GetString(META_TABLE_NAME_INDEX, tableName);
if (errCode != NativeRdb::E_OK) {
return false;
}
errCode = retSet->GetString(META_TABLE_VERSION_INDEX, tableVersion);
if (errCode != NativeRdb::E_OK) {
return false;
}
errCode = retSet->GetString(META_TABLE_EXT_INFO_INDEX, tableExtInfo);
if (errCode != NativeRdb::E_OK) {
return false;
}
errCode = retSet->GetString(META_UPDATE_TIME_INDEX, updateTime);
if (errCode != NativeRdb::E_OK) {
return false;
}
return true;
};
void MetaItem::AddRdbItemToBucket(NativeRdb::ValuesBucket &bucket)
{
bucket.PutString(META_TABLE_NAME, tableName);
bucket.PutString(META_TABLE_VERSION, tableVersion);
bucket.PutString(META_TABLE_EXT_INFO, tableExtInfo);
bucket.PutString(META_UPDATE_TIME, updateTime);
};
}
}
@@ -0,0 +1,352 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_details_rdb_data_manager.h"
#include "app_details_base_item.h"
#include "app_details_meta_item.h"
#include "app_details_rdb_data_define.h"
#include "app_details_rdb_item.h"
#include "app_details_rdb_open_callback.h"
#include "app_domain_verify_hilog.h"
#include "cpp/mutex.h"
#include "rdb_errno.h"
#include "rdb_store.h"
#include "values_bucket.h"
#include "rdb_helper.h"
#include <functional>
#include <string>
#include <variant>
#include <vector>
#include "app_details_rdb_const_define.h"
namespace OHOS {
namespace AppDomainVerify {
AppDetailsRdbDataMgr::AppDetailsRdbDataMgr(bool isCreated)
{
conf_.rdbName = APP_DETAILS_RDB_NAME;
conf_.rdbPath = APP_DETAILS_RDB_PATH;
conf_.version = APP_DETAILS_RDB_VERSION;
conf_.fileCreated = isCreated;
};
AppDetailsRdbDataMgr::AppDetailsRdbDataMgr(const RdbConfigInfo& info)
{
conf_ = info;
};
AppDetailsRdbDataMgr::~AppDetailsRdbDataMgr()
{
closeHandler_->RemoveTask(CLOSE_TASK_ID);
};
bool AppDetailsRdbDataMgr::ExecWithTrans(TransCallback cb)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call");
auto rdbStore = GetRdbStore();
auto ret = rdbStore->BeginTransaction();
if (ret != NativeRdb::E_OK) {
return false;
}
if (cb()) {
ret = rdbStore->Commit();
if (ret != NativeRdb::E_OK) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "commit err:%{public}d", ret);
return false;
}
return true;
}
ret = rdbStore->RollBack();
if (ret != NativeRdb::E_OK) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "roll err:%{public}d.", ret);
}
return false;
}
bool AppDetailsRdbDataMgr::QueryDataByDomain(const std::string& tableName, const std::string &domain, std::vector<AppDetailsRdbItem> &itemVec)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call.");
NativeRdb::AbsRdbPredicates absRdbPred(tableName);
absRdbPred.EqualTo(DETAILS_DOMAIN, domain);
std::vector<std::string> columns = {};
RdbForEachRetCb eachCb = [&itemVec](std::shared_ptr<AbsSharedResultSet> retSet)->bool {
AppDetailsRdbItem item;
if (!item.GetRdbItem(retSet)) {
return false;
}
itemVec.emplace_back(item);
return true;
};
return Query(absRdbPred, columns, eachCb);
}
void AppDetailsRdbDataMgr::PostDelayCloseTask(int32_t delayTime)
{
if (runner_ == nullptr) {
runner_ = AppExecFwk::EventRunner::Create("closeRdb", AppExecFwk::ThreadMode::FFRT);
}
if (closeHandler_ == nullptr) {
closeHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner_);
}
if (closeHandler_ == nullptr) {
return;
}
std::weak_ptr<AppDetailsRdbDataMgr> weakPtr = shared_from_this();
auto task = [weakPtr]() {
auto appDetailsRdbMgr = weakPtr.lock();
if (appDetailsRdbMgr != nullptr) {
std::lock_guard<ffrt::mutex> lock(appDetailsRdbMgr->mtx_);
appDetailsRdbMgr->rdbStore_ = nullptr;
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "rdb close");
}
return;
};
closeHandler_->RemoveTask(CLOSE_TASK_ID);
closeHandler_->PostTask(task, CLOSE_TASK_ID, delayTime);
return;
}
bool AppDetailsRdbDataMgr::InsertDataBatch(const std::string& tableName, std::vector<AppDetailsRdbItem>& infoVec)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
auto rdbStore = GetRdbStore();
if (!rdbStore) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get rdbStore fail.");
return false;
}
std::vector<NativeRdb::ValuesBucket> rows;
for (auto& info : infoVec) {
NativeRdb::ValuesBucket valuesBucket;
info.AddRdbItemToBucket(valuesBucket);
rows.emplace_back(valuesBucket);
}
int64_t num = 0;
return CheckRdbReturnIfOk(rdbStore_->BatchInsert(num, tableName, rows));
};
bool AppDetailsRdbDataMgr::CreateMetaData()
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
auto rdbStore = GetRdbStore();
if (!rdbStore) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get rdbStore fail.");
return false;
}
std::string sql = "CREATE TABLE IF NOT EXISTS " + META_DATA +
"("
"TABLE_NAME TEXT NOT NULL PRIMARY KEY,"
"TABLE_VERSION TEXT,"
"TABLE_EXT_INFO TEXT,"
"UPDATE_TIME TEXT"
");";
auto ret = rdbStore->ExecuteSql(sql);
if (ret != NativeRdb::E_OK) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "exec sql fail. ret:%{public}d", ret);
return false;
}
return true;
};
bool AppDetailsRdbDataMgr::UpdateMetaData(std::vector<MetaItem> &itemVec)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
auto rdbStore = GetRdbStore();
if (!rdbStore) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get rdbStore fail.");
return false;
}
for (auto&item : itemVec) {
NativeRdb::ValuesBucket valuesBucket;
item.AddRdbItemToBucket(valuesBucket);
int64_t rowId = 0;
auto ret = rdbStore->InsertWithConflictResolution(
rowId, META_DATA, valuesBucket,
NativeRdb::ConflictResolution::ON_CONFLICT_REPLACE);
if (ret != NativeRdb::E_OK) {
return CheckRdbReturnIfOk(ret);
}
}
return true;
};
bool AppDetailsRdbDataMgr::QueryMetaData(const std::string &tableName, MetaItem &info)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call.");
NativeRdb::AbsRdbPredicates absRdbPred(META_DATA);
absRdbPred.EqualTo(META_TABLE_NAME, tableName);
std::vector<std::string> columns = {};
auto rdbStore = GetRdbStore();
if (!rdbStore) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get rdbStore fail.");
return false;
}
std::vector<MetaItem> itemVec;
RdbForEachRetCb eachCb = [&itemVec](std::shared_ptr<AbsSharedResultSet> retSet)->bool {
MetaItem item;
if (!item.GetRdbItem(retSet)) {
return false;
}
itemVec.emplace_back(item);
return true;
};
if(Query(absRdbPred, columns, eachCb)) {
info = itemVec.front();
return true;
};
return false;
};
bool AppDetailsRdbDataMgr::CreateTable(const std::string &tableName)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
std::string sql = "CREATE TABLE IF NOT EXISTS " + tableName
+ " ("
"ID TEXT NOT NULL PRIMARY KEY,"
"SCHEME TEXT,"
"DOMAIN TEXT,"
"PATH_TYPE TEXT,"
"PATH TEXT,"
"BUNDLE_NAME TEXT"
+ " );";
auto rdbStore = GetRdbStore();
if (!rdbStore) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get rdbStore fail.");
return false;
}
auto ret = rdbStore->ExecuteSql(sql);
if (ret != NativeRdb::E_OK) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "exec sql fail. ret:%{public}d", ret);
return false;
}
return true;
};
bool AppDetailsRdbDataMgr::DeleteTable(const std::string &tableName)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "Called");
std::string sql = "DROP TABLE IF EXISTS " + tableName + ";";
auto rdbStore = GetRdbStore();
if (!rdbStore) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "Get rdbStore fail.");
return false;
}
auto ret = rdbStore->ExecuteSql(sql);
if (ret != NativeRdb::E_OK) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "Exec sql fail. ret:%{public}d", ret);
return false;
}
return true;
};
std::string AppDetailsRdbDataMgr::GetDbVersion()
{
auto rdbStore = GetRdbStore();
if (!rdbStore) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get rdbStore fail.");
return "";
}
int version = -1;
rdbStore->GetVersion(version);
if (version != -1) {
return std::to_string(version);
}
return "";
};
bool AppDetailsRdbDataMgr::RenameTable(const std::string &oldName, const std::string &newName)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
std::string sql = "ALTER TABLE " + oldName + " RENAME TO " + newName + ";";
auto rdbStore = GetRdbStore();
if (!rdbStore) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get rdbStore fail.");
return false;
}
auto ret = rdbStore->ExecuteSql(sql);
if (ret != NativeRdb::E_OK) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "exec sql fail. ret:%{public}d", ret);
return false;
}
return true;
};
std::shared_ptr<NativeRdb::RdbStore> AppDetailsRdbDataMgr::GetRdbStore()
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
std::lock_guard<ffrt::mutex> lock(mtx_);
if (rdbStore_ != nullptr) {
return rdbStore_;
}
NativeRdb::RdbStoreConfig rdbStoreConfig(conf_.rdbPath + conf_.rdbName);
rdbStoreConfig.SetCreateNecessary(conf_.fileCreated);
rdbStoreConfig.SetSecurityLevel(NativeRdb::SecurityLevel::S1);
int32_t errCode = NativeRdb::E_OK;
AppDetailsRdbOpenCallback appDomainVerifyRdbOpenCallback(conf_);
rdbStore_ = NativeRdb::RdbHelper::GetRdbStore(
rdbStoreConfig, conf_.version, appDomainVerifyRdbOpenCallback, errCode);
if (errCode == NativeRdb::E_OK) {
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get rdbStore success.");
PostDelayCloseTask(CLOSE_DELAY_TIME_S);
}
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "end, errCode:%{public}d", errCode);
return rdbStore_;
};
bool AppDetailsRdbDataMgr::CheckRdbReturnIfOk(int errcode)
{
if (errcode != NativeRdb::E_OK) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "rdb failed, ret: %{public}d", errcode);
return false;
}
return true;
}
bool AppDetailsRdbDataMgr::Query(const NativeRdb::AbsRdbPredicates& predicates,
const std::vector<std::string>& columns, RdbForEachRetCb cb)
{
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
auto rdbStore = GetRdbStore();
if (!rdbStore) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "rdb store is null");
return false;
}
auto absSharedResultSet = rdbStore->Query(predicates, columns);
if (absSharedResultSet == nullptr) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "rdbStore query absSharedResultSet failed");
return false;
}
auto guard = std::unique_ptr<void, std::function<void(void*)>>(
nullptr, [&](void*){ absSharedResultSet->Close(); }
);
if (!absSharedResultSet->HasBlock()) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "absSharedResultSet has no block");
return false;
}
if (CheckRdbReturnIfOk(absSharedResultSet->GoToFirstRow())) {
do {
if(!cb(absSharedResultSet)) {
return false;
}
} while (absSharedResultSet->GoToNextRow() == NativeRdb::E_OK);
} else {
APP_DOMAIN_VERIFY_HILOGW(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "GoToFirstRow fail, seems rdb table empty");
return false;
}
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call end");
return true;
};
}
}
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_details_rdb_item.h"
#include "app_details_rdb_const_define.h"
#include "rdb_errno.h"
namespace OHOS {
namespace AppDomainVerify {
bool AppDetailsRdbItem::GetRdbItem(std::shared_ptr<AbsSharedResultSet> &retSet)
{
int errCode = NativeRdb::E_OK;
errCode = retSet->GetString(DETAILS_ID_INDEX, id);
if (errCode != NativeRdb::E_OK) {
return false;
}
errCode = retSet->GetString(DETAILS_SCHEME_INDEX, scheme);
if (errCode != NativeRdb::E_OK) {
return false;
}
errCode = retSet->GetString(DETAILS_DOMAIN_INDEX, domain);
if (errCode != NativeRdb::E_OK) {
return false;
}
errCode = retSet->GetString(DETAILS_PATH_TYPE_INDEX, pathType);
if (errCode != NativeRdb::E_OK) {
return false;
}
errCode = retSet->GetString(DETAILS_PATH_INDEX, path);
if (errCode != NativeRdb::E_OK) {
return false;
}
errCode = retSet->GetString(DETAILS_BUNDLE_NAME_INDEX, bundleName);
if (errCode != NativeRdb::E_OK) {
return false;
}
return true;
};
void AppDetailsRdbItem::AddRdbItemToBucket(NativeRdb::ValuesBucket &bucket)
{
bucket.PutString(DETAILS_ID, id);
bucket.PutString(DETAILS_SCHEME, scheme);
bucket.PutString(DETAILS_DOMAIN, domain);
bucket.PutString(DETAILS_PATH_TYPE, pathType);
bucket.PutString(DETAILS_PATH, path);
bucket.PutString(DETAILS_BUNDLE_NAME, bundleName);
}
}
}
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_details_rdb_open_callback.h"
#include "app_details_rdb_data_define.h"
#include "app_domain_verify_hilog.h"
#include "rdb_errno.h"
namespace OHOS {
namespace AppDomainVerify {
AppDetailsRdbOpenCallback::AppDetailsRdbOpenCallback(const RdbConfigInfo& conf)
: m_conf(conf)
{
}
int32_t AppDetailsRdbOpenCallback::OnCreate(NativeRdb::RdbStore& rdbStore)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "RdbStore OnCreate");
return NativeRdb::E_OK;
}
int32_t AppDetailsRdbOpenCallback::OnUpgrade(NativeRdb::RdbStore& rdbStore, int currentVersion, int targetVersion)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE,
"OnUpgrade currentVersion: %{public}d, targetVersion: %{public}d", currentVersion, targetVersion);
return NativeRdb::E_OK;
}
int32_t AppDetailsRdbOpenCallback::OnDowngrade(
NativeRdb::RdbStore& rdbStore, int currentVersion, int targetVersion)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE,
"OnDowngrade currentVersion: %{plubic}d, targetVersion: %{plubic}d", currentVersion, targetVersion);
return NativeRdb::E_OK;
}
int32_t AppDetailsRdbOpenCallback::OnOpen(NativeRdb::RdbStore& rdbStore)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "RdbStore OnOpen");
return NativeRdb::E_OK;
}
int32_t AppDetailsRdbOpenCallback::onCorruption(std::string databaseFile)
{
return NativeRdb::E_OK;
}
} // namespace AppDomainVerify
} // namespace OHOS
@@ -18,7 +18,7 @@
#include "app_domain_verify_hilog.h"
#include "comm_define.h"
#include "string_ex.h"
namespace OHOS::AppDomainVerify {
#define WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(type, parcel, data) \
do { \
if (!(parcel).Write##type(data)) { \
@@ -58,7 +58,7 @@
return false; \
} \
} while (0)
}
#define MAX_PARCEL_ARRAY_SIZE (99)
namespace OHOS::AppDomainVerify {
template <typename T>
@@ -0,0 +1,93 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APP_DOMAIN_VERIFY_APP_DETAILS_LRU_H
#define APP_DOMAIN_VERIFY_APP_DETAILS_LRU_H
#include <string>
#include <unordered_map>
#include <list>
#include <mutex>
#include <memory>
namespace OHOS {
namespace AppDomainVerify {
template <typename K, typename V>
class LruCacheUtil {
public:
LruCacheUtil<K, V>() = default;
LruCacheUtil<K, V>(int maxCap):maxCap_(maxCap){};
bool SetMaxCap(int cap);
bool Get(const K& key, V& value);
void Put(const K& key, const V& value);
void Clear();
bool IsEmpty();
private:
std::atomic<size_t> maxCap_ = 10;
std::list<std::pair<K, V>> m_cache;
std::unordered_map<K, typename std::list<std::pair<K, V>>::iterator> lruMap_;
};
template<typename K, typename V>
bool LruCacheUtil<K, V>::SetMaxCap(int cap) {
maxCap_ = cap;
};
template<typename K, typename V>
bool LruCacheUtil<K, V>::Get(const K& key, V& value) {
if (lruMap_.find(key) == lruMap_.end()) {
return false;
}
value = lruMap_[key]->second;
m_cache.erase(lruMap_[key]);
m_cache.push_front({key, value});
lruMap_[key] = m_cache.begin();
return true;
};
template<typename K, typename V>
void LruCacheUtil<K, V>::Put(const K& key, const V& value) {
auto iter = lruMap_.find(key);
if (iter != lruMap_.end()) {
V val = lruMap_[key]->second;
m_cache.erase(iter->second);
m_cache.push_front({key, val});
lruMap_[key] = m_cache.begin();
return;
}
if (lruMap_.size() == maxCap_) {
lruMap_.erase(m_cache.back().first);
m_cache.pop_back();
}
m_cache.push_front({key, value});
lruMap_[key] = m_cache.begin();
return;
};
template<typename K, typename V>
void LruCacheUtil<K, V>::Clear() {
m_cache.clear();
lruMap_.clear();
};
template<typename K, typename V>
bool LruCacheUtil<K, V>::IsEmpty() {
return lruMap_.empty();
};
}
}
#endif
@@ -38,6 +38,7 @@ public:
const AppVerifyBaseInfo& appVerifyBaseInfo, const VerifyResultInfo& verifyResultInfo);
virtual ErrorCode ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr<IConvertCallback>& callback);
virtual ErrorCode UpdateWhiteList();
virtual ErrorCode UpdateAppDetails();
};
}
}
@@ -38,6 +38,7 @@ public:
ErrorCode SingleVerify(const AppVerifyBaseInfo& appVerifyBaseInfo, const VerifyResultInfo& verifyResultInfo);
ErrorCode ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr<IConvertCallback>& callback);
ErrorCode UpdateWhiteList();
ErrorCode UpdateAppDetails();
protected:
virtual bool Init();
@@ -14,6 +14,7 @@
*/
#include "app_domain_verify_agent_ext.h"
#include "app_domain_verify_error.h"
namespace OHOS {
namespace AppDomainVerify {
@@ -35,5 +36,9 @@ ErrorCode AppDomainVerifyAgentExt::UpdateWhiteList()
{
return ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND;
}
ErrorCode AppDomainVerifyAgentExt::UpdateAppDetails()
{
return ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND;
}
}
}
@@ -16,6 +16,7 @@
#include <dlfcn.h>
#include <string>
#include <typeinfo>
#include "app_domain_verify_error.h"
#include "app_domain_verify_extension_mgr.h"
#include "app_domain_verify_hilog.h"
#include "app_domain_verify_extension_register.h"
@@ -140,5 +141,21 @@ ErrorCode AppDomainVerifyExtensionMgr::UpdateWhiteList()
UNIVERSAL_ERROR_EVENT(GET_EXT_FAULT);
return ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND;
}
ErrorCode AppDomainVerifyExtensionMgr::UpdateAppDetails()
{
if (Init()) {
std::string verifierExtName = APP_DOMAIN_VERIFY_AGENT_EXT_NAME;
auto appDomainVerifierExt = GetAppDomainVerifyExt(verifierExtName);
if (appDomainVerifierExt != nullptr) {
return std::static_pointer_cast<AppDomainVerifyAgentExt>(appDomainVerifierExt)
->UpdateAppDetails();
}
APP_DOMAIN_VERIFY_HILOGE(
APP_DOMAIN_VERIFY_MODULE_EXTENSION, "get verifierExt: %{public}s failed.", verifierExtName.c_str());
return ErrorCode::E_EXTENSIONS_INTERNAL_ERROR;
}
return ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND;
}
}
}
@@ -24,6 +24,7 @@
#include "i_app_domain_verify_mgr_service.h"
#include "skill_uri.h"
#include "domain_verify_status.h"
#include "want.h"
namespace OHOS {
namespace AppDomainVerify {
@@ -130,6 +131,15 @@ public:
*/
int QueryAssociatedBundleNames(const std::string& domain, std::vector<std::string>& bundleNames);
/**
* QueryAppDetailsWant
* @descrition query app details as want.
* @param link uri.
* @param want appdetails want.
* @return int result of query.
*/
int QueryAppDetailsWant(const std::string& link, AAFwk::Want& want);
/**
* GetDeferredLink
* @descrition get deferred link for app.
@@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_domain_verify_hilog.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
@@ -13,6 +13,7 @@
* limitations under the License.
*/
#include "app_domain_verify_hilog.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "app_domain_verify_mgr_client.h"
@@ -290,6 +291,17 @@ void AppDomainVerifyMgrClient::UpdateWhiteListUrls(const std::vector<std::string
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "call end");
#endif
}
int AppDomainVerifyMgrClient::QueryAppDetailsWant(const std::string &link, AAFwk::Want &want)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "called");
std::lock_guard<std::mutex> autoLock(proxyLock_);
if (IsServiceAvailable()) {
return appDomainVerifyMgrServiceProxy_->QueryAppDetailsWant(link, want);
}
return CommonErrorCode::E_INTERNAL_ERR;
}
int AppDomainVerifyMgrClient::QueryAssociatedDomains(const std::string& bundleName, std::vector<std::string>& domains)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "called");
+2 -1
View File
@@ -19,7 +19,7 @@ config("app_domain_verify_mgr_napi_config") {
"include",
"${app_domain_verify_client_path}/include",
"${app_domain_verify_common_path}/include",
"${app_domain_verify_common_path}/include/zidl",
"${app_domain_verify_common_path}/include/zidl"
]
configs = [ "//build/config/compiler:exceptions" ]
ldflags = [ "-Wl,--exclude-libs=ALL" ]
@@ -53,6 +53,7 @@ ohos_shared_library("appdomainverify_napi") {
]
external_deps = [
"ability_base:want",
"ability_runtime:napi_common",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hiappevent:hiappevent_innerapi",
+8
View File
@@ -23,6 +23,7 @@ config("app_domain_verify_service_config") {
"include/manager/rdb",
"include/manager/zidl",
"include/manager/permission",
"include/manager/filter",
"include/manager/deferred_link",
"include/agent/core",
"${app_domain_verify_common_path}/include",
@@ -32,6 +33,7 @@ config("app_domain_verify_service_config") {
"${app_domain_verify_frameworks_common_path}/include/bms",
"${app_domain_verify_frameworks_common_path}/include/config",
"${app_domain_verify_frameworks_common_path}/include/dfx",
"//foundation/bundlemanager/app_domain_verify/frameworks/app_details_rdb/include"
]
configs = [ "//build/config/compiler:exceptions" ]
ldflags = [ "-Wl,--exclude-libs=ALL" ]
@@ -56,7 +58,9 @@ ohos_shared_library("app_domain_verify_mgr_service") {
"${app_domain_verify_frameworks_common_path}/src/bms/bundle_info_query.cpp",
"${app_domain_verify_frameworks_common_path}/src/config/white_list_config_mgr.cpp",
"${app_domain_verify_frameworks_common_path}/src/utils/domain_url_util.cpp",
"src/manager/core/app_details_data_mgr.cpp",
"src/manager/core/app_domain_verify_data_mgr.cpp",
"src/manager/filter/app_details_filter.cpp",
"src/manager/core/app_domain_verify_mgr_service.cpp",
"src/manager/deferred_link/ability_filter.cpp",
"src/manager/deferred_link/deferred_link_mgr.cpp",
@@ -71,6 +75,7 @@ ohos_shared_library("app_domain_verify_mgr_service") {
deps = [
"${app_domain_verify_client_path}:app_domain_verify_agent_client",
"${app_domain_verify_common_path}:app_domain_verify_common",
"${app_domain_verify_frameworks_app_details_rdb_path}:app_domain_verify_app_details_rdb"
]
defines = [ "API_EXPORT=__attribute__((visibility (\"default\")))" ]
if (build_variant == "user") {
@@ -117,6 +122,7 @@ config("app_domain_verify_agent_service_config") {
"include/manager/core",
"include/manager/zidl",
"include/manager/rdb",
"include/manager/filter",
"${app_domain_verify_common_path}/include",
"${app_domain_verify_common_path}/include/zidl",
"${app_domain_verify_frameworks_common_path}/include",
@@ -125,6 +131,7 @@ config("app_domain_verify_agent_service_config") {
"${app_domain_verify_frameworks_common_path}/include/config",
"${app_domain_verify_frameworks_extension_path}/include",
"${app_domain_verify_frameworks_verifier_path}/include",
"${app_domain_verify_frameworks_app_details_rdb_path}/include",
"${app_domain_verify_frameworks_common_path}/include/dfx",
]
configs = [ "//build/config/compiler:exceptions" ]
@@ -162,6 +169,7 @@ ohos_shared_library("app_domain_verify_agent_service") {
"${app_domain_verify_frameworks_common_path}:app_domain_verify_frameworks_common",
"${app_domain_verify_frameworks_extension_path}:app_domain_verify_extension_framework",
"${app_domain_verify_frameworks_verifier_path}:app_domain_verify_agent_verifier",
"${app_domain_verify_frameworks_app_details_rdb_path}:app_domain_verify_app_details_rdb"
]
external_deps = [
@@ -18,7 +18,7 @@ namespace OHOS {
namespace AppDomainVerify {
enum AgentInterfaceCode {
SINGLE_VERIFY = 0,
CONVERT_TO_EXPLICIT_WANT = 1,
CONVERT_TO_EXPLICIT_WANT = 1
};
}
} // namespace OHOS
@@ -42,7 +42,6 @@ public:
API_EXPORT void SingleVerify(
const AppVerifyBaseInfo& appVerifyBaseInfo, const VerifyResultInfo &verifyResultInfo) override;
API_EXPORT void ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr<IConvertCallback>& callback) override;
protected:
void OnStart(const SystemAbilityOnDemandReason& startReason) override;
void OnStop() override;
@@ -55,6 +54,7 @@ private:
void ExecuteVerifyTask(
const AppVerifyBaseInfo& appVerifyBaseInfo, const VerifyResultInfo &verifyResultInfo, TaskType type);
void UpdateWhiteList();
void UpdateAppDetails();
void OnDelayUnloadSA();
void PostDelayUnloadTask();
void DoSync(const TaskType& type);
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APP_DOMAIN_VERIFY_APP_DETAILS_DATA_MGR_H
#define APP_DOMAIN_VERIFY_APP_DETAILS_DATA_MGR_H
#include "cpp/mutex.h"
#include "lru_cache_util.h"
#include "filter_define.h"
#include "app_details_filter.h"
#include "app_details_rdb_data_manager.h"
#include "want.h"
#include <stdint.h>
#include <string>
#include <unordered_map>
namespace OHOS {
namespace AppDomainVerify {
enum AppDetailsCode {
QUERY_SUCC,
QUERY_FAIL
};
class AppDetailsDataMgr {
public:
AppDetailsDataMgr();
virtual ~AppDetailsDataMgr();
int QueryAppDetailsWant(const std::string& url, AAFwk::Want& want);
private:
bool QueryAppDetailsWantByCache(const std::string& url, AAFwk::Want& want);
bool QueryAppDetailsWantByRdb(const std::string& url, AAFwk::Want& want);
void AddInfoToWant(AAFwk::Want& want, const std::string& bundleName);
std::shared_ptr<LruCacheUtil<std::string, std::string>> lruCache_;
std::shared_ptr<AppDetailsRdbDataMgr> rdbMgr_;
std::shared_ptr<AppDetailsFilter> detailsFilter_;
int64_t cacheBeginTime_ = 0;
std::string agWantUrl_;
};
} // namespace AppDomainVerify
} // namespace OHOS
#endif // APP_DETAILS_DATA_MGR_H
@@ -28,7 +28,8 @@ enum AppDomainVerifyMgrInterfaceCode {
UPDATE_WHITE_LIST_URLS = 8,
QUERY_ASSOCIATED_DOMAINS = 9,
QUERY_ASSOCIATED_BUNDLE_NAMES = 10,
GET_DEFERRED_LINK = 11
GET_DEFERRED_LINK = 11,
QUERY_APP_DETAILS_WANT = 12
};
}
} // namespace OHOS
@@ -16,6 +16,7 @@
#ifndef APP_DOMAIN_VERIFY_MGR_SERVICE_H
#define APP_DOMAIN_VERIFY_MGR_SERVICE_H
#include "app_details_data_mgr.h"
#include "app_domain_verify_mgr_service_stub.h"
#include "inner_verify_status.h"
#include "skill_uri.h"
@@ -53,6 +54,7 @@ public:
API_EXPORT int QueryAssociatedBundleNames(
const std::string& domain, std::vector<std::string>& bundleNames) override;
API_EXPORT int GetDeferredLink(std::string& link) override;
API_EXPORT int QueryAppDetailsWant(const std::string& link, AAFwk::Want& want) override;
protected:
void OnDump() override;
@@ -71,6 +73,7 @@ private:
private:
std::shared_ptr<AppDomainVerifyDataMgr> dataManager_ = nullptr;
std::shared_ptr<AppDetailsDataMgr> appDetailsDataMgr_ = nullptr;
bool InitConfigMgr();
std::shared_ptr<WhiteListConfigMgr> whiteListConfigMgr_;
std::mutex initConfigMutex_;
@@ -44,6 +44,7 @@ public:
virtual int QueryAssociatedDomains(const std::string& bundleName, std::vector<std::string>& domains) = 0;
virtual int QueryAssociatedBundleNames(const std::string& domain, std::vector<std::string>& bundleNames) = 0;
virtual int GetDeferredLink(std::string& link) = 0;
virtual int QueryAppDetailsWant(const std::string& link, AAFwk::Want& want) = 0;
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appDomainVerify.IAppDomainVerifyMgrService");
};
} // namespace AppDomainVerify
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APP_DOMAIN_VERIFY_APP_DETAILS_FILTER_H
#define APP_DOMAIN_VERIFY_APP_DETAILS_FILTER_H
#include "filter_define.h"
#include "want.h"
#include <string>
namespace OHOS {
namespace AppDomainVerify {
class AppDetailsFilter {
public:
bool Filter(const std::vector<AppDetailInfo>& input, std::vector<AppDetailInfo>& dest, const std::string& url);
};
}
}
#endif
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APP_DOMAIN_VERIFY_FILTER_DEFINE_H
#define APP_DOMAIN_VERIFY_FILTER_DEFINE_H
#include "skill.h"
#include "want.h"
#include <string>
namespace OHOS {
namespace AppDomainVerify {
struct AppDetailInfo {
std::string m_bundleName;
AppExecFwk::SkillUri m_skillUri;
};
}
}
#endif
@@ -18,6 +18,7 @@
#include "i_app_domain_verify_mgr_service.h"
#include "iremote_proxy.h"
#include "want.h"
namespace OHOS {
namespace AppDomainVerify {
@@ -42,6 +43,7 @@ public:
int QueryAssociatedDomains(const std::string& bundleName, std::vector<std::string>& domains) override;
int QueryAssociatedBundleNames(const std::string& domain, std::vector<std::string>& bundleNames) override;
int GetDeferredLink(std::string& link) override;
int QueryAppDetailsWant(const std::string& link, AAFwk::Want& want) override;
private:
static inline BrokerDelegator<AppDomainVerifyMgrServiceProxy> delegator_;
};
@@ -21,6 +21,7 @@
#include "iremote_stub.h"
#include "event_handler.h"
#include "event_runner.h"
#include "message_parcel.h"
namespace OHOS {
namespace AppDomainVerify {
@@ -44,6 +45,7 @@ private:
int32_t OnQueryAssociatedDomains(MessageParcel& data, MessageParcel& reply);
int32_t OnQueryAssociatedBundleNames(MessageParcel& data, MessageParcel& reply);
int32_t OnGetDeferredLink(MessageParcel& data, MessageParcel& reply);
int32_t OnQueryAppDetailsWant(MessageParcel& data, MessageParcel& reply);
};
} // namespace AppDomainVerify
} // namespace OHOS
@@ -149,6 +149,16 @@ void AppDomainVerifyAgentService::UpdateWhiteList()
return;
}
}
void AppDomainVerifyAgentService::UpdateAppDetails()
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "called");
if (ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND != appDomainVerifyExtMgr_->UpdateAppDetails()) {
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "extension call end");
return;
}
}
// sa_main进程统一调用
void AppDomainVerifyAgentService::OnStart(const SystemAbilityOnDemandReason& startReason)
{
@@ -194,6 +204,7 @@ void AppDomainVerifyAgentService::DoSync(const TaskType& type)
{
QueryAndCompleteRefresh(type);
UpdateWhiteList();
UpdateAppDetails();
}
bool AppDomainVerifyAgentService::IsNetAvailable()
@@ -288,6 +299,5 @@ int AppDomainVerifyAgentService::Dump(int fd, const std::vector<std::u16string>&
(void)write(fd, dumpString.c_str(), dumpString.size());
return 0;
}
} // namespace AppDomainVerify
} // namespace OHOS
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_details_data_mgr.h"
#include "app_details_filter.h"
#include "app_details_meta_item.h"
#include "app_details_rdb_data_define.h"
#include "app_details_rdb_const_define.h"
#include "app_details_rdb_data_manager.h"
#include "comm_define.h"
#include "domain_url_util.h"
#include "app_domain_verify_hilog.h"
#include "filter_define.h"
#include "lru_cache_util.h"
#include "skill.h"
#include "want.h"
#include <memory>
#include <new>
#include <stdint.h>
namespace OHOS {
namespace AppDomainVerify {
const static std::string OHOS_WANT_ACTION_APPDETAILS = "ohos.want.action.appdetails";
const static int64_t CACHE_TIME_S = 3000;
const static int MAX_CACHE_CNT = 10;
AppDetailsDataMgr::AppDetailsDataMgr()
{
lruCache_ = std::make_shared<LruCacheUtil<std::string, std::string>>(MAX_CACHE_CNT);
rdbMgr_ = std::make_shared<AppDetailsRdbDataMgr>(false);
};
AppDetailsDataMgr::~AppDetailsDataMgr()
{};
int AppDetailsDataMgr::QueryAppDetailsWant(const std::string &url, AAFwk::Want& want)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call, url:%{public}s", url.c_str());
if (QueryAppDetailsWantByCache(url, want)) {
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "query success from cache");
return QUERY_SUCC;
}
if (QueryAppDetailsWantByRdb(url, want)) {
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "query success from rdb");
return QUERY_SUCC;
}
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "query fail.");
return QUERY_FAIL;
};
bool AppDetailsDataMgr::QueryAppDetailsWantByCache(const std::string& url, AAFwk::Want& want)
{
int64_t currTime = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now())
.time_since_epoch()
.count();
if (currTime - cacheBeginTime_ > CACHE_TIME_S) {
cacheBeginTime_ = currTime;
lruCache_->Clear();
return false;
}
std::string value;
if (lruCache_->Get(url, value)) {
AddInfoToWant(want, value);
return true;
}
return false;
};
bool AppDetailsDataMgr::QueryAppDetailsWantByRdb(const std::string& url, AAFwk::Want& want)
{
std::vector<AppDetailsRdbItem> rdbDetails;
std::string domain = UrlUtil::GetHost(url);
if (!rdbMgr_->QueryDataByDomain(APP_DETAILS_TABLE, domain, rdbDetails)) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_EXTENSION, "query fail.");
return false;
}
std::vector<AppDetailInfo> appDetails;
std::vector<AppDetailInfo> appDetailsRet;
for (auto& detail : rdbDetails) {
AppDetailInfo info;
info.m_bundleName = detail.bundleName;
info.m_skillUri.host = detail.domain;
info.m_skillUri.scheme = detail.scheme;
if (detail.pathType == PATH) {
info.m_skillUri.path = detail.path;
}
if (detail.pathType == PATH_START_WITH) {
info.m_skillUri.pathStartWith = detail.path;
}
if (detail.pathType == PATH_REGEX) {
info.m_skillUri.pathRegex = detail.path;
}
appDetails.emplace_back(info);
}
if (!detailsFilter_->Filter(appDetails, appDetailsRet, url)) {
return false;
}
AddInfoToWant(want, appDetailsRet.front().m_bundleName);
lruCache_->Put(url, appDetailsRet.front().m_bundleName);
return true;
};
void AppDetailsDataMgr::AddInfoToWant(AAFwk::Want& want, const std::string& bundleName)
{
MetaItem info;
if (agWantUrl_.empty()) {
rdbMgr_->QueryMetaData(APP_DETAILS_TABLE, info);
agWantUrl_ = info.tableExtInfo;
}
want.SetAction(OHOS_WANT_ACTION_APPDETAILS);
want.SetUri(agWantUrl_ + bundleName);
return;
};
}
}
@@ -17,6 +17,7 @@
#include <string>
#include <tuple>
#include <vector>
#include "app_details_data_mgr.h"
#include "ipc_skeleton.h"
#include "app_domain_verify_mgr_service.h"
#include "system_ability_definition.h"
@@ -36,7 +37,9 @@ AppDomainVerifyMgrService::AppDomainVerifyMgrService() : SystemAbility(APP_DOMAI
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "new instance create.");
dataManager_ = std::make_shared<AppDomainVerifyDataMgr>();
appDetailsDataMgr_ = std::make_shared<AppDetailsDataMgr>();
}
AppDomainVerifyMgrService::~AppDomainVerifyMgrService()
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "instance dead.");
@@ -225,6 +228,12 @@ int AppDomainVerifyMgrService::QueryAssociatedBundleNames(
return dataManager_->QueryAssociatedBundleNames(domain, bundleNames) ? E_OK : E_INTERNAL_ERR;
}
int AppDomainVerifyMgrService::QueryAppDetailsWant(const std::string& url, AAFwk::Want& want)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
return appDetailsDataMgr_->QueryAppDetailsWant(url, want);
}
bool AppDomainVerifyMgrService::IsWantImplicit(const OHOS::AAFwk::Want& want)
{
auto element = want.GetElement();
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_details_filter.h"
#include "skill.h"
#include "want.h"
#include "app_domain_verify_hilog.h"
namespace OHOS {
namespace AppDomainVerify {
constexpr const static char *ENTITY_SYSTEM_BROWSABLE = "entity.system.browsable";
constexpr const static char *WANT_ACTION_VIEWDATA = "ohos.want.action.viewData";
bool AppDetailsFilter::Filter(const std::vector<AppDetailInfo>& input, std::vector<AppDetailInfo>& dest, const std::string& url)
{
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "start filer");
AAFwk::Want want;
want.SetAction(WANT_ACTION_VIEWDATA);
want.SetEntities({ENTITY_SYSTEM_BROWSABLE});
want.SetUri(url);
AppExecFwk::Skill skill;
skill.actions.push_back(WANT_ACTION_VIEWDATA);
skill.entities.push_back(ENTITY_SYSTEM_BROWSABLE);
for (auto&info : input) {
skill.uris.push_back(info.m_skillUri);
}
size_t index = 0;
bool ret = skill.Match(want, index);
if (!ret) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "skill match fail.");
return false;
}
dest.clear();
dest.push_back(input[index]);
return true;
}
}
}
@@ -16,6 +16,7 @@
#include "app_domain_verify_mgr_interface_code.h"
#include "system_ability_definition.h"
#include "app_domain_verify_parcel_util.h"
#include "want.h"
namespace OHOS {
namespace AppDomainVerify {
@@ -345,5 +346,35 @@ int AppDomainVerifyMgrServiceProxy::GetDeferredLink(std::string& link)
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "call end");
return result;
}
int AppDomainVerifyMgrServiceProxy::QueryAppDetailsWant(const std::string &url, AAFwk::Want& want)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "called");
MessageParcel data;
MessageParcel reply;
MessageOption option;
WRITE_PARCEL_AND_RETURN_INT_IF_FAIL(InterfaceToken, data, GetDescriptor());
WRITE_PARCEL_AND_RETURN_INT_IF_FAIL(String, data, url);
WRITE_PARCEL_AND_RETURN_INT_IF_FAIL(Parcelable, data, &want);
int32_t error = Remote()->SendRequest(
AppDomainVerifyMgrInterfaceCode::QUERY_APP_DETAILS_WANT, data, reply, option);
if (error != ERR_NONE) {
APP_DOMAIN_VERIFY_HILOGE(
APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "QueryAppDetailsWant failed, error: %d", error);
}
int32_t result = reply.ReadInt32();
if (result != 0) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "result failed, result: %d", result);
return result;
}
AppExecFwk::Want* wantPtr = reply.ReadParcelable<AppExecFwk::Want>();
if (wantPtr == nullptr) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "recv want fail");
return result;
}
want = *wantPtr;
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "call end");
return result;
}
} // namespace AppDomainVerify
} // namespace OHOS
@@ -20,6 +20,7 @@
#include "app_domain_verify_parcel_util.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "want.h"
namespace OHOS {
namespace AppDomainVerify {
@@ -68,6 +69,8 @@ int32_t AppDomainVerifyMgrServiceStub::OnRemoteRequest(
return OnQueryAssociatedBundleNames(data, reply);
case static_cast<uint32_t>(AppDomainVerifyMgrInterfaceCode::GET_DEFERRED_LINK):
return OnGetDeferredLink(data, reply);
case static_cast<uint32_t>(AppDomainVerifyMgrInterfaceCode::QUERY_APP_DETAILS_WANT):
return OnQueryAppDetailsWant(data, reply);
default:
APP_DOMAIN_VERIFY_HILOGW(
APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "receive unknown code, code = %{public}d", code);
@@ -276,5 +279,23 @@ int32_t AppDomainVerifyMgrServiceStub::OnGetDeferredLink(MessageParcel& data, Me
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call end");
return ERR_OK;
}
int32_t AppDomainVerifyMgrServiceStub::OnQueryAppDetailsWant(MessageParcel& data, MessageParcel& reply)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
AAFwk::Want want;
std::string url;
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, data, url);
AAFwk::Want* wantPtr = data.ReadParcelable<OHOS::AAFwk::Want>();
if (!wantPtr) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "read parcelable want failed.");
return ERR_INVALID_VALUE;
}
int ret = QueryAppDetailsWant(url, *wantPtr);
WRITE_PARCEL_AND_RETURN_INT_IF_FAIL(Int32, reply, ret);
WRITE_PARCEL_AND_RETURN_INT_IF_FAIL(Parcelable, reply, wantPtr);
return ERR_OK;
}
} // namespace AppDomainVerify
} // namespace OHOS
+3
View File
@@ -29,6 +29,7 @@ group("app_domain_verify_unit_test") {
"frameworks_common/bms_test:app_domain_verify_bms_test",
"frameworks_common/config_test:app_domain_verify_config_test",
"frameworks_common/httpsession_test:app_domain_verify_httpsession_test",
"frameworks_common/utils_test:lru_cache_util_test",
"moduletest:app_domain_verify_module_test",
"services/ability_filter_test:ability_filter_test",
"services/app_domain_verify_agent_service_test:app_domain_verify_agent_service_test",
@@ -36,6 +37,8 @@ group("app_domain_verify_unit_test") {
"services/app_domain_verify_mgr_service_test:app_domain_verify_mgr_service_test",
"services/app_domain_verify_rdb_test:app_domain_verify_rdb_test",
"services/deferred_link_test:deferred_link_test",
"services/app_domain_verify_filter_test:app_domain_verify_filter_test",
"app_details_rdb:app_details_rdb_data_manager_test",
"verifier:app_domain_verify_agent_verifier_test",
]
}
+72
View File
@@ -0,0 +1,72 @@
# Copyright (C) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("//foundation/bundlemanager/app_domain_verify/app_domain_verify.gni")
config("module_private_config") {
visibility = [ ":*" ]
configs = [ "//build/config/compiler:exceptions" ]
include_dirs = [
"${app_domain_verify_frameworks_app_details_rdb_path}/include/",
"${app_domain_verify_service_path}/include/manager/core/",
"${app_domain_verify_service_path}/include/manager/filter"
]
}
module_output_path = "app_domain_verify/app_domain_verify"
ohos_unittest("app_details_rdb_data_manager_test") {
module_out_path = module_output_path
sources = [
"${app_domain_verify_frameworks_app_details_rdb_path}/src/app_details_meta_item.cpp",
"${app_domain_verify_frameworks_app_details_rdb_path}/src/app_details_rdb_item.cpp",
"${app_domain_verify_frameworks_app_details_rdb_path}/src/app_details_rdb_data_manager.cpp",
"${app_domain_verify_frameworks_app_details_rdb_path}/src/app_details_rdb_open_callback.cpp",
"${app_domain_verify_service_path}/src/manager/core/app_details_data_mgr.cpp",
"${app_domain_verify_service_path}/src/manager/filter/app_details_filter.cpp",
"app_details_rdb_data_manager_test.cpp",
]
configs = [ ":module_private_config" ]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hisysevent:libhisysevent",
"image_framework:image_native",
"init:libbegetutil",
"ipc:ipc_core",
"netstack:http_client",
"os_account:os_account_innerkits",
"relational_store:native_rdb",
"samgr:samgr_proxy",
"ffrt:libffrt",
]
defines = [ "API_EXPORT=__attribute__((visibility (\"default\")))" ]
deps = [
"${app_domain_verify_client_path}:app_domain_verify_agent_client",
"${app_domain_verify_client_path}:app_domain_verify_mgr_client",
"${app_domain_verify_common_path}:app_domain_verify_common",
"${app_domain_verify_frameworks_common_path}:app_domain_verify_frameworks_common",
"${app_domain_verify_frameworks_common_path}:app_domain_verify_frameworks_common",
"${app_domain_verify_frameworks_extension_path}:app_domain_verify_extension_framework",
"${app_domain_verify_frameworks_verifier_path}:app_domain_verify_agent_verifier",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
}
@@ -0,0 +1,289 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "app_details_meta_item.h"
#include "app_details_rdb_item.h"
#include "cpp/condition_variable.h"
#include "cpp/mutex.h"
#include "cpp/task.h"
#include "skill.h"
#include "gtest/gtest.h"
#include <chrono>
#include <memory>
#include <mutex>
#include <semaphore>
#include <string>
#include <thread>
#include <vector>
#include "app_domain_verify_hilog.h"
#define private public
#define protected public
#include "app_details_rdb_data_manager.h"
#undef private
#undef protected
namespace OHOS::AppDomainVerify {
using namespace testing;
using namespace testing::ext;
class AppDetailsRdbMgrTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
static std::string rdbName;
static std::string rdbPath;
static int rdbVersion;
};
std::string AppDetailsRdbMgrTest::rdbName = "test.db";
std::string AppDetailsRdbMgrTest::rdbPath = "/data/test/";
int AppDetailsRdbMgrTest::rdbVersion = 1;
void AppDetailsRdbMgrTest::SetUpTestCase(void)
{
}
void AppDetailsRdbMgrTest::TearDownTestCase(void)
{
}
void AppDetailsRdbMgrTest::SetUp(void)
{
}
void AppDetailsRdbMgrTest::TearDown(void)
{
std::vector<std::string> tmpFileVec = {
rdbPath + rdbName,
rdbPath + rdbName + "-shm",
rdbPath + rdbName + "-wal"
};
for (auto& filePath : tmpFileVec) {
(void)remove(filePath.c_str());
}
}
/**
* @tc.name: AppDetailsRdbMgrTest001
* @tc.desc: test table op
* @tc.type: FUNC
*/
HWTEST_F(AppDetailsRdbMgrTest, AppDetailsRdbMgrTest001, TestSize.Level0)
{
RdbConfigInfo info;
info.rdbName = AppDetailsRdbMgrTest::rdbName;
info.rdbPath = AppDetailsRdbMgrTest::rdbPath;
info.version = AppDetailsRdbMgrTest::rdbVersion;
auto rdbMgr = std::make_shared<AppDetailsRdbDataMgr>(info);
bool ret = rdbMgr->DeleteTable("app_details");
ASSERT_TRUE(ret);
ret = rdbMgr->CreateTable("app_details");
ASSERT_TRUE(ret);
ret = rdbMgr->CreateTable("app_details_tmp");
ASSERT_TRUE(ret);
ret = rdbMgr->DeleteTable("app_details_del");
ASSERT_TRUE(ret);
ret = rdbMgr->RenameTable("app_details", "app_details_del");
ASSERT_TRUE(ret);
ret = rdbMgr->DeleteTable("app_details_del");
ASSERT_TRUE(ret);
ret = rdbMgr->DeleteTable("app_details_tmp");
ASSERT_TRUE(ret);
}
/**
* @tc.name: AppDetailsRdbMgrTest002
* @tc.desc: test insert del query op
* @tc.type: FUNC
*/
HWTEST_F(AppDetailsRdbMgrTest, AppDetailsRdbMgrTest002, TestSize.Level0)
{
RdbConfigInfo info;
info.rdbName = AppDetailsRdbMgrTest::rdbName;
info.rdbPath = AppDetailsRdbMgrTest::rdbPath;
info.version = AppDetailsRdbMgrTest::rdbVersion;
auto rdbMgr = std::make_shared<AppDetailsRdbDataMgr>(info);
bool ret = rdbMgr->DeleteTable("app_details");
ASSERT_TRUE(ret);
ret = rdbMgr->CreateTable("app_details");
ASSERT_TRUE(ret);
std::vector<AppDetailsRdbItem> itemVec;
AppDetailsRdbItem item;
item.id = "111";
item.scheme = "https";
item.domain = "www.test.com";
item.pathType = "path";
item.path = "test";
item.bundleName = "com.huawei.bundleNameTest";
itemVec.push_back(item);
ret = rdbMgr->InsertDataBatch("app_details", itemVec);
ASSERT_TRUE(ret);
std::vector<AppDetailsRdbItem> itemRetVec;
ret = rdbMgr->QueryDataByDomain("app_details", item.domain, itemRetVec);
ASSERT_TRUE(ret);
ASSERT_TRUE(itemRetVec.size() != 0);
auto rdbitem = itemRetVec[0];
ASSERT_EQ(rdbitem.bundleName, item.bundleName);
ret = rdbMgr->DeleteTable("app_details");
ASSERT_TRUE(ret);
}
/**
* @tc.name: AppDetailsRdbMgrTest003
* @tc.desc: test meta data
* @tc.type: FUNC
*/
HWTEST_F(AppDetailsRdbMgrTest, AppDetailsRdbMgrTest003, TestSize.Level0)
{
RdbConfigInfo info;
info.rdbName = AppDetailsRdbMgrTest::rdbName;
info.rdbPath = AppDetailsRdbMgrTest::rdbPath;
info.version = AppDetailsRdbMgrTest::rdbVersion;
auto rdbMgr = std::make_shared<AppDetailsRdbDataMgr>(info);
bool ret = rdbMgr->CreateMetaData();
ASSERT_TRUE(ret);
ret = rdbMgr->CreateMetaData();
ASSERT_TRUE(ret);
MetaItem item;
item.tableExtInfo = "tableExtInfo";
item.tableName = "app_details";
item.tableVersion = "1.0";
item.updateTime = "111111";
std::vector<MetaItem> itemVec;
itemVec.push_back(item);
ret = rdbMgr->UpdateMetaData(itemVec);
ASSERT_TRUE(ret);
ret = rdbMgr->DeleteTable("META_DATA");
ASSERT_TRUE(ret);
}
/**
* @tc.name: AppDetailsRdbMgrTest004
* @tc.desc: test transaction
* @tc.type: FUNC
*/
HWTEST_F(AppDetailsRdbMgrTest, AppDetailsRdbMgrTest004, TestSize.Level0)
{
RdbConfigInfo info;
info.rdbName = AppDetailsRdbMgrTest::rdbName;
info.rdbPath = AppDetailsRdbMgrTest::rdbPath;
info.version = AppDetailsRdbMgrTest::rdbVersion;
auto rdbMgr = std::make_shared<AppDetailsRdbDataMgr>(info);
auto ret = rdbMgr->CreateTable("app_details");
std::vector<AppDetailsRdbItem> itemVec;
AppDetailsRdbItem item;
item.id = "111";
item.scheme = "https";
item.domain = "www.test.com";
item.pathType = "path";
item.path = "test";
item.bundleName = "com.huawei.bundleNameTest";
itemVec.push_back(item);
ret = rdbMgr->InsertDataBatch("app_details", itemVec);
ASSERT_TRUE(ret);
bool retFlag = rdbMgr->ExecWithTrans([&]()->bool {
auto ret = rdbMgr->DeleteTable("app_details");
return false;
});
ASSERT_FALSE(retFlag);
std::vector<AppDetailsRdbItem> result;
ret = rdbMgr->QueryDataByDomain("app_details", item.domain, result);
ASSERT_TRUE(ret);
retFlag = rdbMgr->ExecWithTrans([&]()->bool {
auto ret = rdbMgr->DeleteTable("app_details");
return true;
});
ASSERT_TRUE(retFlag);
result.clear();
ret = rdbMgr->QueryDataByDomain("app_details", item.domain, result);
ASSERT_FALSE(ret);
}
/**
* @tc.name: AppDetailsRdbMgrTest005
* @tc.desc: test delayClose
* @tc.type: FUNC
*/
HWTEST_F(AppDetailsRdbMgrTest, AppDetailsRdbMgrTest005, TestSize.Level0)
{
RdbConfigInfo info;
info.rdbName = AppDetailsRdbMgrTest::rdbName;
info.rdbPath = AppDetailsRdbMgrTest::rdbPath;
info.version = AppDetailsRdbMgrTest::rdbVersion;
auto rdbMgr = std::make_shared<AppDetailsRdbDataMgr>(info);
auto rdbStore = rdbMgr->GetRdbStore();
ASSERT_TRUE(rdbStore != nullptr);
rdbMgr->PostDelayCloseTask(100);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
ASSERT_TRUE(rdbMgr->rdbStore_ == nullptr);
}
/**
* @tc.name: AppDetailsRdbMgrTest006
* @tc.desc: test trans for muti table
* @tc.type: FUNC
*/
HWTEST_F(AppDetailsRdbMgrTest, AppDetailsRdbMgrTest006, TestSize.Level0)
{
RdbConfigInfo info;
info.rdbName = AppDetailsRdbMgrTest::rdbName;
info.rdbPath = AppDetailsRdbMgrTest::rdbPath;
info.version = AppDetailsRdbMgrTest::rdbVersion;
auto rdbMgr = std::make_shared<AppDetailsRdbDataMgr>(info);
auto ret = rdbMgr->CreateTable("app_details");
rdbMgr->closeHandler_->RemoveTask("closeRdb");
std::vector<AppDetailsRdbItem> itemVec;
AppDetailsRdbItem item;
item.id = "111";
item.scheme = "https";
item.domain = "www.test.com";
item.pathType = "path";
item.path = "test";
item.bundleName = "com.huawei.bundleNameTest";
itemVec.push_back(item);
ret = rdbMgr->InsertDataBatch("app_details", itemVec);
std::vector<AppDetailsRdbItem> result;
std::atomic_bool checkFlag = false;
std::binary_semaphore sem(0);
ffrt::mutex mtx;
ret = rdbMgr->QueryDataByDomain("app_details", item.domain, result);
ASSERT_TRUE(ret);
ASSERT_TRUE(result.size() != 0);
auto task = [&](){
rdbMgr->ExecWithTrans([&]()->bool {
sem.acquire();
checkFlag = true;
return true;
});
return;
};
rdbMgr->closeHandler_->PostTask(task, "closeRdb", 0);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
bool flag = rdbMgr->rdbStore_->IsInTransaction();
ASSERT_TRUE(flag);
ASSERT_FALSE(checkFlag);
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "sart query test");
result.clear();
ASSERT_TRUE(result.size() == 0);
ret = rdbMgr->QueryDataByDomain("app_details", "www.baidu.com", result);
ASSERT_TRUE(result.size() != 0);
sem.release();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
ASSERT_TRUE(checkFlag);
}
}
@@ -0,0 +1,40 @@
# Copyright (C) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("//foundation/bundlemanager/app_domain_verify/app_domain_verify.gni")
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [
"${app_domain_verify_frameworks_common_path}/include/utils"
]
}
module_output_path = "app_domain_verify/app_domain_verify"
ohos_unittest("lru_cache_util_test") {
module_out_path = module_output_path
sources = [
"lru_cache_util_test.cpp",
]
configs = [ ":module_private_config" ]
defines = [ "API_EXPORT=__attribute__((visibility (\"default\")))" ]
deps = [
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
}
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include <memory>
#include <thread>
#define private public
#define protected public
#include "lru_cache_util.h"
#undef private
#undef protected
namespace OHOS::AppDomainVerify {
using namespace testing;
using namespace testing::ext;
class LruCacheUtilTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void LruCacheUtilTest::SetUpTestCase(void)
{
}
void LruCacheUtilTest::TearDownTestCase(void)
{
}
void LruCacheUtilTest::SetUp(void)
{
}
void LruCacheUtilTest::TearDown(void)
{
}
/**
* @tc.name: LruCacheUtilTest001
* @tc.desc: fundation function test example string
* @tc.type: FUNC
*/
HWTEST_F(LruCacheUtilTest, LruCacheUtilTest001, TestSize.Level0)
{
auto lruCache = LruCacheUtil<std::string, std::string>();
for (int i = 0; i < 11; i ++) {
lruCache.Put(std::to_string(i), std::to_string(i));
}
std::string value;
ASSERT_FALSE(lruCache.Get("0", value));
ASSERT_TRUE(lruCache.Get("1", value));
ASSERT_EQ(value.compare("1"), 0);
for (int i = 0; i < 3; i++) {
lruCache.Put(std::to_string(i + 11), std::to_string(i + 11));
}
ASSERT_TRUE(lruCache.Get("1", value));
ASSERT_EQ(value.compare("1"), 0);
lruCache.Clear();
ASSERT_FALSE(lruCache.Get("1", value));
}
}
@@ -77,6 +77,10 @@ public:
{
return true;
}
virtual int QueryAppDetailsWant(const std::string& link, AAFwk::Want& want) override
{
return true;
}
MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel&, MessageParcel&, MessageOption&));
MOCK_METHOD(sptr<IRemoteObject>, AsObject, (), (override));
};
@@ -138,6 +142,11 @@ public:
{
return true;
}
virtual int QueryAppDetailsWant(const std::string& link, AAFwk::Want& want) override
{
return true;
}
};
} // namespace AppDomainVerify
} // namespace OHOS
@@ -0,0 +1,64 @@
# Copyright (C) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("//foundation/bundlemanager/app_domain_verify/app_domain_verify.gni")
config("module_private_config") {
visibility = [ ":*" ]
configs = [ "//build/config/compiler:exceptions" ]
include_dirs = [
"${app_domain_verify_service_path}/include/manager/filter",
"${app_domain_verify_service_path}/include/manager/constant",
]
}
module_output_path = "app_domain_verify/app_domain_verify"
ohos_unittest("app_domain_verify_filter_test") {
module_out_path = module_output_path
sources = [
"${app_domain_verify_service_path}/src/manager/filter/app_details_filter.cpp",
"app_domain_verify_app_details_filter_test.cpp",
]
configs = [ ":module_private_config" ]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hisysevent:libhisysevent",
"image_framework:image_native",
"init:libbegetutil",
"ipc:ipc_core",
"netstack:http_client",
"os_account:os_account_innerkits",
"relational_store:native_rdb",
"samgr:samgr_proxy",
]
defines = [ "API_EXPORT=__attribute__((visibility (\"default\")))" ]
deps = [
"${app_domain_verify_client_path}:app_domain_verify_agent_client",
"${app_domain_verify_client_path}:app_domain_verify_mgr_client",
"${app_domain_verify_common_path}:app_domain_verify_common",
"${app_domain_verify_frameworks_common_path}:app_domain_verify_frameworks_common",
"${app_domain_verify_frameworks_common_path}:app_domain_verify_frameworks_common",
"${app_domain_verify_frameworks_extension_path}:app_domain_verify_extension_framework",
"${app_domain_verify_frameworks_verifier_path}:app_domain_verify_agent_verifier",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
}
@@ -0,0 +1,131 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "filter_define.h"
#include "app_details_filter.h"
#include "skill.h"
#include "gtest/gtest.h"
#include <memory>
#include <thread>
#define private public
#define protected public
#include "lru_cache_util.h"
#undef private
#undef protected
namespace OHOS::AppDomainVerify {
using namespace testing;
using namespace testing::ext;
class AppDetailsFilterTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void AppDetailsFilterTest::SetUpTestCase(void)
{
}
void AppDetailsFilterTest::TearDownTestCase(void)
{
}
void AppDetailsFilterTest::SetUp(void)
{
}
void AppDetailsFilterTest::TearDown(void)
{
}
/**
* @tc.name: AppDetailsFilterTest001
* @tc.desc: test path match
* @tc.type: FUNC
*/
HWTEST_F(AppDetailsFilterTest, AppDetailsFilterTest001, TestSize.Level0)
{
AppDetailsFilter filter;
std::vector<AppDetailInfo> filterVec;
AppDetailInfo info;
info.m_skillUri.scheme = "https";
info.m_skillUri.host = "www.example.com";
info.m_skillUri.path = "test";
info.m_bundleName = "com.example.bundleName";
filterVec.emplace_back(std::move(info));
std::vector<AppDetailInfo> resultVec;
auto ret = filter.Filter(filterVec, resultVec, "https://www.example.com/test");
ASSERT_TRUE(ret);
ASSERT_TRUE(resultVec.size() == 1);
ASSERT_TRUE(resultVec[0].m_bundleName.compare("com.example.bundleName") == 0);
resultVec.clear();
filterVec[0].m_skillUri.path = "111";
ret = filter.Filter(filterVec, resultVec, "https://www.example.com/test");
ASSERT_FALSE(ret);
}
/**
* @tc.name: AppDetailsFilterTest002
* @tc.desc: test path match
* @tc.type: FUNC
*/
HWTEST_F(AppDetailsFilterTest, AppDetailsFilterTest002, TestSize.Level0)
{
AppDetailsFilter filter;
std::vector<AppDetailInfo> filterVec;
AppDetailInfo info;
info.m_skillUri.scheme = "https";
info.m_skillUri.host = "www.example.com";
info.m_skillUri.pathStartWith = "test";
info.m_bundleName = "com.example.bundleName";
filterVec.emplace_back(std::move(info));
std::vector<AppDetailInfo> resultVec;
auto ret = filter.Filter(filterVec, resultVec, "https://www.example.com/testhappy");
ASSERT_TRUE(ret);
ASSERT_TRUE(resultVec.size() == 1);
ASSERT_EQ(resultVec[0].m_bundleName.compare("com.example.bundleName"), 0);
resultVec.clear();
filterVec[0].m_skillUri.path = "111";
ret = filter.Filter(filterVec, resultVec, "https://www.example.com/tes");
ASSERT_FALSE(ret);
}
/**
* @tc.name: AppDetailsFilterTest003
* @tc.desc: test regex match
* @tc.type: FUNC
*/
HWTEST_F(AppDetailsFilterTest, AppDetailsFilterTest003, TestSize.Level0)
{
AppDetailsFilter filter;
std::vector<AppDetailInfo> filterVec;
AppDetailInfo info;
info.m_skillUri.scheme = "https";
info.m_skillUri.host = "www.example.com";
info.m_skillUri.pathRegex = "[0-9]*";
info.m_bundleName = "com.example.bundleName";
filterVec.emplace_back(std::move(info));
std::vector<AppDetailInfo> resultVec;
auto ret = filter.Filter(filterVec, resultVec, "https://www.example.com/1223");
ASSERT_TRUE(ret);
ASSERT_TRUE(resultVec.size() == 1);
ASSERT_EQ(resultVec[0].m_bundleName.compare("com.example.bundleName"), 0);
ret = filter.Filter(filterVec, resultVec, "https://www.example.com/xxx");
ASSERT_FALSE(ret);
}
}
@@ -29,12 +29,14 @@ config("module_private_config") {
"${app_domain_verify_service_path}/include/manager/zidl",
"${app_domain_verify_service_path}/include/manager/permission",
"${app_domain_verify_service_path}/include/manager/deferred_link",
"${app_domain_verify_service_path}/include/manager/filter",
"${app_domain_verify_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include/utils",
"${app_domain_verify_frameworks_extension_path}/include",
"${app_domain_verify_test_path}/mock/include",
"${app_domain_verify_frameworks_common_path}/include/dfx",
"${app_domain_verify_frameworks_app_details_rdb_path}/include"
]
}
@@ -45,12 +47,18 @@ ohos_unittest("app_domain_verify_mgr_service_test") {
sources = [
"${app_domain_verify_service_path}/src/manager/core/app_domain_verify_data_mgr.cpp",
"${app_domain_verify_service_path}/src/manager/core/app_domain_verify_mgr_service.cpp",
"${app_domain_verify_service_path}/src/manager/core/app_details_data_mgr.cpp",
"${app_domain_verify_service_path}/src/manager/filter/app_details_filter.cpp",
"${app_domain_verify_service_path}/src/manager/deferred_link/ability_filter.cpp",
"${app_domain_verify_service_path}/src/manager/deferred_link/deferred_link_mgr.cpp",
"${app_domain_verify_service_path}/src/manager/permission/permission_manager.cpp",
"${app_domain_verify_service_path}/src/manager/rdb/app_domain_verify_rdb_data_manager.cpp",
"${app_domain_verify_service_path}/src/manager/rdb/app_domain_verify_rdb_open_callback.cpp",
"${app_domain_verify_service_path}/src/manager/rdb/rdb_migrate_mgr.cpp",
"${app_domain_verify_frameworks_app_details_rdb_path}/src/app_details_meta_item.cpp",
"${app_domain_verify_frameworks_app_details_rdb_path}/src/app_details_rdb_item.cpp",
"${app_domain_verify_frameworks_app_details_rdb_path}/src/app_details_rdb_data_manager.cpp",
"${app_domain_verify_frameworks_app_details_rdb_path}/src/app_details_rdb_open_callback.cpp",
"${app_domain_verify_service_path}/src/manager/zidl/app_domain_verify_mgr_service_proxy.cpp",
"${app_domain_verify_service_path}/src/manager/zidl/app_domain_verify_mgr_service_stub.cpp",
"${app_domain_verify_test_path}/mock/src/mock_access_token.cpp",