diff --git a/BUILD.gn b/BUILD.gn index 49cbf58e8025f0caa3a8d60edceec109b34d6d92..ecb1acf06a69552d7da8c548460e20c7b7745a88 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -25,10 +25,7 @@ config("base_public_config") { } config("base_all_dependent_config") { - include_dirs = [ - "${ability_base_innerapi_path}/base/include", - "${ipc_native_path}/src/napi/include", - ] + include_dirs = [ "${ability_base_innerapi_path}/base/include" ] } ohos_shared_library("base") { @@ -70,7 +67,7 @@ config("configuration_sdk_config") { include_dirs = [ "interfaces/kits/native/configuration/include", "${ability_base_innerapi_path}/log/include", - "${base_global_innerapi_path}/include", + "//third_party/json/include", ] } @@ -93,7 +90,7 @@ ohos_shared_library("configuration") { "c_utils:utils", "hilog:libhilog", ] - + public_external_deps = [ "resource_management:global_resmgr" ] subsystem_name = "ability" innerapi_tags = [ "platformsdk" ] part_name = "ability_base" @@ -192,7 +189,6 @@ ohos_shared_library("want") { ":base", ":zuri", "//third_party/json:nlohmann_json_static", - "//third_party/jsoncpp:jsoncpp", ] all_dependent_configs = [ ":want_all_dependent_config", @@ -204,6 +200,7 @@ ohos_shared_library("want") { "hilog:libhilog", "ipc:ipc_core", "ipc:ipc_single", + "jsoncpp:jsoncpp", ] configs = [ ":want_config" ] @@ -227,6 +224,7 @@ config("view_data_config") { ohos_shared_library("view_data") { sources = [ "interfaces/kits/native/view_data/src/page_node_info.cpp", + "interfaces/kits/native/view_data/src/rect.cpp", "interfaces/kits/native/view_data/src/view_data.cpp", ] @@ -304,7 +302,6 @@ config("ability_extractor_config") { "${ability_base_innerapi_path}/log/include", "//third_party/json/include", "//third_party/zlib/contrib/minizip", - "//third_party/zlib", ] } @@ -330,18 +327,17 @@ ohos_shared_library("extractortool") { cflags += [ "-DBINDER_IPC_32BIT" ] } - deps = [ - ":string_utils", - "//third_party/zlib:shared_libz", - ] + deps = [ ":string_utils" ] public_configs = [ ":ability_extractor_config" ] external_deps = [ "c_utils:utils", "hilog:libhilog", + "hitrace:hitrace_meter", + "zlib:shared_libz", ] - + public_external_deps = [ "zlib:libz" ] subsystem_name = "ability" innerapi_tags = [ "chipsetsdk_indirect", @@ -380,7 +376,9 @@ group("base_innerkits_target") { ":configuration", ":extractortool", ":extractresourcemanager", + ":session_info", ":string_utils", + ":view_data", ":want", ] } diff --git a/bundle.json b/bundle.json index c5926f553de2df9ffafb73caec2ef8d55c093b77..bf34d11b1044d9f7c700a2c1fa45e67b08d95c7b 100644 --- a/bundle.json +++ b/bundle.json @@ -26,13 +26,14 @@ "ability_runtime", "c_utils", "hilog", + "hitrace", "ipc", - "resource_management" - ], - "third_party": [ - "json", + "resource_management", "jsoncpp", "zlib" + ], + "third_party": [ + "json" ] }, "build": { diff --git a/interfaces/kits/native/configuration/include/configuration.h b/interfaces/kits/native/configuration/include/configuration.h index 18437e32bf371cbbab2fb9a30ae2ca0c05007408..0cc11f5080239d2d91601274fdd9f339ed829e25 100644 --- a/interfaces/kits/native/configuration/include/configuration.h +++ b/interfaces/kits/native/configuration/include/configuration.h @@ -46,6 +46,10 @@ namespace ConfigurationInner { OHOS::AAFwk::GlobalConfigurationKey::THEME, OHOS::AAFwk::GlobalConfigurationKey::LANGUAGE_IS_SET_BY_APP, OHOS::AAFwk::GlobalConfigurationKey::COLORMODE_IS_SET_BY_APP, + OHOS::AAFwk::GlobalConfigurationKey::COLORMODE_NEED_REMOVE_SET_BY_SA, + OHOS::AAFwk::GlobalConfigurationKey::COLORMODE_IS_SET_BY_SA, + OHOS::AAFwk::GlobalConfigurationKey::SYSTEM_FONT_SIZE_SCALE, + OHOS::AAFwk::GlobalConfigurationKey::SYSTEM_FONT_WEIGHT_SCALE, OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DIRECTION, OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DENSITYDPI, OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DISPLAYID, @@ -58,6 +62,8 @@ namespace ConfigurationInner { constexpr const char* DIRECTION_VERTICAL = "vertical"; constexpr const char* DIRECTION_HORIZONTAL = "horizontal"; constexpr const char* IS_SET_BY_APP = "isSetByApp"; + constexpr const char* NEED_REMOVE_SET_BY_SA = "needRemoveSetBySa"; + constexpr const char* IS_SET_BY_SA = "isSetBySa"; }; class Configuration final: public Parcelable { diff --git a/interfaces/kits/native/configuration/include/global_configuration_key.h b/interfaces/kits/native/configuration/include/global_configuration_key.h index 774a80f14c2050bf61df1ed45abd8f089d460f67..ab3100a5e362926698050baaca6c1f23b6d7c326 100644 --- a/interfaces/kits/native/configuration/include/global_configuration_key.h +++ b/interfaces/kits/native/configuration/include/global_configuration_key.h @@ -30,7 +30,11 @@ namespace GlobalConfigurationKey { constexpr const char* DEVICE_TYPE = "const.build.characteristics"; constexpr const char* LANGUAGE_IS_SET_BY_APP = "ohos.system.language.isSetByApp"; constexpr const char* COLORMODE_IS_SET_BY_APP = "ohos.system.colorMode.isSetByApp"; + constexpr const char* COLORMODE_NEED_REMOVE_SET_BY_SA = "ohos.system.colorMode.needRemoveSetBySa"; + constexpr const char* COLORMODE_IS_SET_BY_SA = "ohos.system.colorMode.isSetBySa"; constexpr const char* THEME = "ohos.application.theme"; + constexpr const char* SYSTEM_FONT_SIZE_SCALE = "ohos.system.fontSizeScale"; + constexpr const char* SYSTEM_FONT_WEIGHT_SCALE = "ohos.system.fontWeightScale"; } // namespace GlobalConfigurationKey } // namespace AAFwk diff --git a/interfaces/kits/native/configuration/src/configuration_convertor.cpp b/interfaces/kits/native/configuration/src/configuration_convertor.cpp index b5c729fbd72388c684b519255825f41f297765bf..70c4baccca20ae743a9d9e126ee403cffd65665f 100644 --- a/interfaces/kits/native/configuration/src/configuration_convertor.cpp +++ b/interfaces/kits/native/configuration/src/configuration_convertor.cpp @@ -154,6 +154,7 @@ Global::Resource::DeviceType ConvertDeviceType(std::string deviceType) {"tv", Global::Resource::DeviceType::DEVICE_TV}, {"watch", Global::Resource::DeviceType::DEVICE_WEARABLE}, {"2in1", Global::Resource::DeviceType::DEVICE_TWOINONE}, + {"wearable", Global::Resource::DeviceType::DEVICE_WEARABLE} }; if (deviceTypes.find(deviceType) != deviceTypes.end()) { diff --git a/interfaces/kits/native/extractortool/include/extractor.h b/interfaces/kits/native/extractortool/include/extractor.h index b0441094d56b6fcf61babbccc4fddc7724132c6e..2820cc55e9b697adfcc3c28b2b40de7589d11e1e 100644 --- a/interfaces/kits/native/extractortool/include/extractor.h +++ b/interfaces/kits/native/extractortool/include/extractor.h @@ -55,13 +55,6 @@ public: * @return Returns true if the file extracted successfully; returns false otherwise. */ bool ExtractByName(const std::string &fileName, std::ostream &dest) const; - /** - * @brief Extract to dest path on filesystem. - * @param fileName Indicates the file name. - * @param targetPath Indicates the target Path. - * @return Returns true if the file extracted to filesystem successfully; returns false otherwise. - */ - bool ExtractFile(const std::string &fileName, const std::string &targetPath) const; /** * @brief Get specified type names in a zip file. * @param fileNames Indicates the obtained file names in zip. diff --git a/interfaces/kits/native/extractortool/src/extractor.cpp b/interfaces/kits/native/extractortool/src/extractor.cpp index 17b8ee0f2bd338cbda39050d6703dafbcf3288d7..d1528598301930ea53aba92163f165bc1fa59afc 100644 --- a/interfaces/kits/native/extractortool/src/extractor.cpp +++ b/interfaces/kits/native/extractortool/src/extractor.cpp @@ -20,6 +20,7 @@ #include "ability_base_log_wrapper.h" #include "constants.h" #include "file_path_utils.h" +#include "hitrace_meter.h" #include "securec.h" #include "string_ex.h" @@ -38,6 +39,7 @@ Extractor::~Extractor() bool Extractor::Init() { + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (!zipFile_.Open()) { ABILITYBASE_LOGD("open zip file failed"); return false; @@ -69,6 +71,7 @@ bool Extractor::GetFileBuffer(const std::string& srcPath, std::ostringstream& de bool Extractor::GetFileList(const std::string& srcPath, std::vector& assetList) { + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (!initial_) { ABILITYBASE_LOGE("extractor is not initial"); return false; @@ -122,28 +125,6 @@ bool Extractor::ExtractByName(const std::string &fileName, std::ostream &dest) c return true; } -bool Extractor::ExtractFile(const std::string &fileName, const std::string &targetPath) const -{ - std::ofstream fileStream; - fileStream.open(targetPath, std::ios_base::out | std::ios_base::binary); - if (!fileStream.is_open()) { - ABILITYBASE_LOGE("fail to open %{private}s file to write", targetPath.c_str()); - return false; - } - if ((!ExtractByName(fileName, fileStream)) || (!fileStream.good())) { - ABILITYBASE_LOGE("fail to extract %{public}s zip file into stream", fileName.c_str()); - fileStream.clear(); - fileStream.close(); - if (remove(targetPath.c_str()) != 0) { - ABILITYBASE_LOGE("fail to remove %{private}s file which writes stream error", targetPath.c_str()); - } - return false; - } - fileStream.clear(); - fileStream.close(); - return true; -} - void Extractor::GetSpecifiedTypeFiles(std::vector &fileNames, const std::string &suffix) { auto &entryMap = zipFile_.GetAllEntries(); @@ -228,6 +209,7 @@ bool Extractor::IsStageModel() bool Extractor::ExtractToBufByName(const std::string &fileName, std::unique_ptr &dataPtr, size_t &len) { + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); std::string relativePath = GetRelativePath(fileName); return zipFile_.ExtractToBufByName(relativePath, dataPtr, len); } @@ -308,6 +290,7 @@ std::shared_ptr ExtractorUtil::GetExtractor(const std::string &hapPat return nullptr; } { + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "GetExtractor_find_from_cache"); std::lock_guard mapMutex(mapMutex_); auto mapIter = extractorMap_.find(hapPath); if (mapIter != extractorMap_.end()) { @@ -322,6 +305,7 @@ std::shared_ptr ExtractorUtil::GetExtractor(const std::string &hapPat return nullptr; } if (cache) { + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "GetExtractor_store"); std::lock_guard mapMutex(mapMutex_); extractorMap_.emplace(hapPath, extractor); ABILITYBASE_LOGD("extractor cache size: %{public}zu.", extractorMap_.size()); @@ -332,6 +316,7 @@ std::shared_ptr ExtractorUtil::GetExtractor(const std::string &hapPat void ExtractorUtil::DeleteExtractor(const std::string &hapPath) { + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (hapPath.empty()) { ABILITYBASE_LOGE("DeleteExtractor hapPath is empty."); return; diff --git a/interfaces/kits/native/extractortool/src/zip_file.cpp b/interfaces/kits/native/extractortool/src/zip_file.cpp index b47c1b582ce1e365bca59c7a3c87750efb3a5ef5..fd3da52f6757ec6a12b7f7ebde530cde088d87b8 100644 --- a/interfaces/kits/native/extractortool/src/zip_file.cpp +++ b/interfaces/kits/native/extractortool/src/zip_file.cpp @@ -21,6 +21,7 @@ #include "constants.h" #include "file_mapper.h" #include "file_path_utils.h" +#include "hitrace_meter.h" #include "securec.h" #include "zip_file_reader.h" #include "zlib.h" @@ -199,6 +200,7 @@ std::shared_ptr ZipFile::GetDirRoot() return nullptr; } if (dirRoot_ == nullptr) { + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "make_dir_tree"); std::lock_guard guard(dirRootMutex_); if (dirRoot_ == nullptr) { dirRoot_ = MakeDirTree(); diff --git a/interfaces/kits/native/view_data/include/auto_fill_type.h b/interfaces/kits/native/view_data/include/auto_fill_type.h index dea1731bea3b305f3c5f1909185bf3eac8c8bc56..55297816ac3a45b6d5f9761b514883956a6cfb16 100644 --- a/interfaces/kits/native/view_data/include/auto_fill_type.h +++ b/interfaces/kits/native/view_data/include/auto_fill_type.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -22,7 +22,46 @@ enum class AutoFillType { UNSPECIFIED = 0, PASSWORD, USER_NAME, - NEW_PASSWORD + NEW_PASSWORD, + FULL_STREET_ADDRESS, + HOUSE_NUMBER, + DISTRICT_ADDRESS, + CITY_ADDRESS, + PROVINCE_ADDRESS, + COUNTRY_ADDRESS, + PERSON_FULL_NAME, + PERSON_LAST_NAME, + PERSON_FIRST_NAME, + PHONE_NUMBER, + PHONE_COUNTRY_CODE, + FULL_PHONE_NUMBER, + EMAIL_ADDRESS, + BANK_CARD_NUMBER, + ID_CARD_NUMBER, + PRECISE_TIME, + HOUR_AND_MINUTE, + DATE, + MONTH, + YEAR, + NICKNAME, + DETAIL_INFO_WITHOUT_STREET, + FORMAT_ADDRESS, +}; + +enum class PopupPlacement { + LEFT = 0, + RIGHT, + TOP, + BOTTOM, + TOP_LEFT, + TOP_RIGHT, + BOTTOM_LEFT, + BOTTOM_RIGHT, + LEFT_TOP, + LEFT_BOTTOM, + RIGHT_TOP, + RIGHT_BOTTOM, + NONE, }; } // namespace AbilityBase } // namespace OHOS diff --git a/interfaces/kits/native/view_data/include/page_node_info.h b/interfaces/kits/native/view_data/include/page_node_info.h index 3c87cc6e21dd7972356e24ab03ba6a39aec532ad..ccc4e53fa9133030ba03dc31bbc0acc2933ca8b8 100644 --- a/interfaces/kits/native/view_data/include/page_node_info.h +++ b/interfaces/kits/native/view_data/include/page_node_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -19,11 +19,14 @@ #include #include "auto_fill_type.h" +#include "nlohmann/json.hpp" +#include "rect.h" namespace OHOS { namespace AbilityBase { struct PageNodeInfo { void FromJsonString(const std::string& jsonStr); + void ParseJsonToPageNodeInfo(const nlohmann::json& jsonObject); std::string ToJsonString() const; int32_t id = -1; @@ -34,6 +37,8 @@ struct PageNodeInfo { std::string placeholder; std::string passwordRules; bool enableAutoFill = true; + Rect rect; + bool isFocus = false; }; } // namespace AbilityBase } // namespace OHOS diff --git a/interfaces/kits/native/view_data/include/rect.h b/interfaces/kits/native/view_data/include/rect.h new file mode 100644 index 0000000000000000000000000000000000000000..a589697fdf4d6ebab15fe81dc2c6c8634fd125b2 --- /dev/null +++ b/interfaces/kits/native/view_data/include/rect.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#ifndef OHOS_ABILITY_BASE_RECT_H +#define OHOS_ABILITY_BASE_RECT_H + +#include +#include + +namespace OHOS { +namespace AbilityBase { +struct Rect { + void FromJsonString(const std::string& jsonStr); + std::string ToJsonString() const; + + float left = 0.0f; + float top = 0.0f; + float width = 0.0f; + float height = 0.0f; +}; +} // namespace AbilityBase +} // namespace OHOS +#endif // OHOS_ABILITY_BASE_RECT_H diff --git a/interfaces/kits/native/view_data/include/view_data.h b/interfaces/kits/native/view_data/include/view_data.h index 7a3d02907953bcc411e0c2486ebec49d5eec7cc6..d1af662d28acf6d880e343dcd9c26a62370923cd 100644 --- a/interfaces/kits/native/view_data/include/view_data.h +++ b/interfaces/kits/native/view_data/include/view_data.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -34,6 +34,7 @@ struct ViewData { std::string abilityName; std::string pageUrl; std::vector nodes; + Rect pageRect; }; } // namespace AbilityBase } // namespace OHOS diff --git a/interfaces/kits/native/view_data/src/page_node_info.cpp b/interfaces/kits/native/view_data/src/page_node_info.cpp index 1d54065c1350bb3f7f51eb6299c1eb5ca76e1dce..7dcb107c23935256dd55c3ced2848d05d3892756 100644 --- a/interfaces/kits/native/view_data/src/page_node_info.cpp +++ b/interfaces/kits/native/view_data/src/page_node_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -16,7 +16,6 @@ #include "page_node_info.h" #include "ability_base_log_wrapper.h" -#include "nlohmann/json.hpp" namespace OHOS { namespace AbilityBase { @@ -28,6 +27,8 @@ constexpr const char* PAGE_NODE_INFO_VALUE = "value"; constexpr const char* PAGE_NODE_INFO_PLACEHOLDER = "placeholder"; constexpr const char* PAGE_NODE_INFO_PASSWORD_RULES = "passwordRules"; constexpr const char* PAGE_NODE_INFO_ENABLE_AUTO_FILL = "enableAutoFill"; +constexpr const char* PAGE_NODE_INFO_RECT = "rect"; +constexpr const char* PAGE_NODE_INFO_IS_FOCUS = "isFocus"; void PageNodeInfo::FromJsonString(const std::string& jsonStr) { @@ -61,6 +62,21 @@ void PageNodeInfo::FromJsonString(const std::string& jsonStr) jsonObject[PAGE_NODE_INFO_ENABLE_AUTO_FILL].is_boolean()) { enableAutoFill = jsonObject.at(PAGE_NODE_INFO_ENABLE_AUTO_FILL).get(); } + ParseJsonToPageNodeInfo(jsonObject); +} + +void PageNodeInfo::ParseJsonToPageNodeInfo(const nlohmann::json& jsonObject) +{ + if (jsonObject.is_discarded()) { + ABILITYBASE_LOGE("Failed to parse json string."); + return; + } + if (jsonObject.contains(PAGE_NODE_INFO_RECT)) { + rect.FromJsonString(jsonObject[PAGE_NODE_INFO_RECT]); + } + if (jsonObject.contains(PAGE_NODE_INFO_IS_FOCUS) && jsonObject[PAGE_NODE_INFO_IS_FOCUS].is_boolean()) { + isFocus = jsonObject.at(PAGE_NODE_INFO_IS_FOCUS).get(); + } } std::string PageNodeInfo::ToJsonString() const @@ -73,7 +89,9 @@ std::string PageNodeInfo::ToJsonString() const {PAGE_NODE_INFO_VALUE, value}, {PAGE_NODE_INFO_PLACEHOLDER, placeholder}, {PAGE_NODE_INFO_PASSWORD_RULES, passwordRules}, - {PAGE_NODE_INFO_ENABLE_AUTO_FILL, enableAutoFill} + {PAGE_NODE_INFO_ENABLE_AUTO_FILL, enableAutoFill}, + {PAGE_NODE_INFO_RECT, rect.ToJsonString()}, + {PAGE_NODE_INFO_IS_FOCUS, isFocus} }; return jsonObject.dump(); } diff --git a/interfaces/kits/native/view_data/src/rect.cpp b/interfaces/kits/native/view_data/src/rect.cpp new file mode 100644 index 0000000000000000000000000000000000000000..754a8b04f8ca422c8193b2bccd6018002d47ee82 --- /dev/null +++ b/interfaces/kits/native/view_data/src/rect.cpp @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#include "rect.h" + +#include "ability_base_log_wrapper.h" +#include "nlohmann/json.hpp" + +namespace OHOS { +namespace AbilityBase { +constexpr const char* VIEW_DATA_RECT_LEFT = "left"; +constexpr const char* VIEW_DATA_RECT_TOP = "top"; +constexpr const char* VIEW_DATA_RECT_WIDTH = "width"; +constexpr const char* VIEW_DATA_RECT_HEIGHT = "height"; + +void Rect::FromJsonString(const std::string& jsonStr) +{ + nlohmann::json jsonObject = nlohmann::json::parse(jsonStr, nullptr, false); + if (jsonObject.is_discarded()) { + ABILITYBASE_LOGE("Failed to parse json string."); + return; + } + if (jsonObject.contains(VIEW_DATA_RECT_LEFT) && jsonObject[VIEW_DATA_RECT_LEFT].is_number_float()) { + left = jsonObject.at(VIEW_DATA_RECT_LEFT).get(); + } + if (jsonObject.contains(VIEW_DATA_RECT_TOP) && jsonObject[VIEW_DATA_RECT_TOP].is_number_float()) { + top = jsonObject.at(VIEW_DATA_RECT_TOP).get(); + } + if (jsonObject.contains(VIEW_DATA_RECT_WIDTH) && jsonObject[VIEW_DATA_RECT_WIDTH].is_number_float()) { + width = jsonObject.at(VIEW_DATA_RECT_WIDTH).get(); + } + if (jsonObject.contains(VIEW_DATA_RECT_HEIGHT) && jsonObject[VIEW_DATA_RECT_HEIGHT].is_number_float()) { + height = jsonObject.at(VIEW_DATA_RECT_HEIGHT).get(); + } +} + +std::string Rect::ToJsonString() const +{ + nlohmann::json jsonObject { + {VIEW_DATA_RECT_LEFT, left}, + {VIEW_DATA_RECT_TOP, top}, + {VIEW_DATA_RECT_WIDTH, width}, + {VIEW_DATA_RECT_HEIGHT, height} + }; + return jsonObject.dump(); +} +} // namespace AbilityBase +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/native/view_data/src/view_data.cpp b/interfaces/kits/native/view_data/src/view_data.cpp index 770d42380c4d1ab66b458b918309191d69f4c3fe..47085726fdb144d0065466f4b32c3448f1870ac1 100644 --- a/interfaces/kits/native/view_data/src/view_data.cpp +++ b/interfaces/kits/native/view_data/src/view_data.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -26,6 +26,7 @@ constexpr const char* VIEW_DATA_MODULE_NAME = "moduleName"; constexpr const char* VIEW_DATA_ABILITY_NAME = "abilityName"; constexpr const char* VIEW_DATA_PAGE_URL = "pageUrl"; constexpr const char* VIEW_DATA_NODES = "nodes"; +constexpr const char* VIEW_DATA_PAGE_RECT = "pageRect"; void ViewData::FromJsonString(const std::string& jsonStr) { @@ -58,6 +59,9 @@ void ViewData::FromJsonString(const std::string& jsonStr) } } } + if (jsonObject.contains(VIEW_DATA_PAGE_RECT)) { + pageRect.FromJsonString(jsonObject[VIEW_DATA_PAGE_RECT]); + } } std::string ViewData::ToJsonString() const @@ -72,7 +76,8 @@ std::string ViewData::ToJsonString() const {VIEW_DATA_MODULE_NAME, moduleName}, {VIEW_DATA_ABILITY_NAME, abilityName}, {VIEW_DATA_PAGE_URL, pageUrl}, - {VIEW_DATA_NODES, jsonNodes} + {VIEW_DATA_NODES, jsonNodes}, + {VIEW_DATA_PAGE_RECT, pageRect.ToJsonString()} }; return jsonObject.dump(); } diff --git a/interfaces/kits/native/want/include/want.h b/interfaces/kits/native/want/include/want.h index 41aea88501b42f87a672d22e75f9ded29f5a321d..4b1a70fbda65fa2d8fe827cd8847e3db478cb5c9 100644 --- a/interfaces/kits/native/want/include/want.h +++ b/interfaces/kits/native/want/include/want.h @@ -823,6 +823,10 @@ public: void CloseAllFd(); + void RemoveAllFd(); + + void DupAllFd(); + void SetEntities(const std::vector &entities); public: // action definition @@ -850,6 +854,7 @@ public: static const std::string PARAM_RESV_WINDOW_MODE; static const std::string PARAM_RESV_DISPLAY_ID; static const std::string PARAM_RESV_WITH_ANIMATION; + static const std::string PARAM_RESV_WINDOW_FOCUSED; static const std::string PARAM_RESV_WINDOW_LEFT; static const std::string PARAM_RESV_WINDOW_TOP; static const std::string PARAM_RESV_WINDOW_WIDTH; diff --git a/interfaces/kits/native/want/include/want_params.h b/interfaces/kits/native/want/include/want_params.h index 553db5e696d1e832d7d0e1741cfdd26f31b530ad..caf0695fbe688d8fba86f87cd2e5c2f19d470c30 100644 --- a/interfaces/kits/native/want/include/want_params.h +++ b/interfaces/kits/native/want/include/want_params.h @@ -106,7 +106,11 @@ public: void DumpInfo(int level) const; void CloseAllFd(); - + + void RemoveAllFd(); + + void DupAllFd(); + void GetCachedUnsupportedData(std::vector &cachedUnsuppertedData) const; void SetCachedUnsupportedData(const std::vector &cachedUnsuppertedData); @@ -143,7 +147,8 @@ private: VALUE_TYPE_WANTPARAMS = 101, VALUE_TYPE_ARRAY = 102, VALUE_TYPE_FD = 103, - VALUE_TYPE_REMOTE_OBJECT = 104 + VALUE_TYPE_REMOTE_OBJECT = 104, + VALUE_TYPE_INVALID_FD = 105, }; bool WriteArrayToParcel(Parcel &parcel, IArray *ao, int depth) const; diff --git a/interfaces/kits/native/want/src/extra_params.cpp b/interfaces/kits/native/want/src/extra_params.cpp index 9a79b1e1be18820dc0d27c6dbe3a1c2c39d92d90..f54c1d116d64f94748c6d2c379fe784241aa337d 100644 --- a/interfaces/kits/native/want/src/extra_params.cpp +++ b/interfaces/kits/native/want/src/extra_params.cpp @@ -62,10 +62,9 @@ bool ExtraParams::operator==(const ExtraParams &other) const if (devType_.size() != other.devType_.size()) { return false; } else if (devType_.size() > 0 && other.devType_.size() > 0 && devType_.size() == other.devType_.size()) { - std::vector::const_iterator it1; - for (it1 = devType_.cbegin(); it1 != devType_.cend(); it1++) { - std::vector::const_iterator it2; - it2 = std::find(other.devType_.cbegin(), other.devType_.cend(), *it1); + for (std::vector::const_iterator it1 = devType_.cbegin(); it1 != devType_.cend(); it1++) { + std::vector::const_iterator it2 = + std::find(other.devType_.cbegin(), other.devType_.cend(), *it1); if (it2 == other.devType_.cend()) { return false; } diff --git a/interfaces/kits/native/want/src/want.cpp b/interfaces/kits/native/want/src/want.cpp index 6636ea74fb8850075ed03dcb255c4f7da246da56..daad918bbece4fe0bb16bed792ba287c936a8bdb 100644 --- a/interfaces/kits/native/want/src/want.cpp +++ b/interfaces/kits/native/want/src/want.cpp @@ -71,6 +71,7 @@ const std::string Want::WANT_END(";end"); const std::string Want::PARAM_RESV_WINDOW_MODE("ohos.aafwk.param.windowMode"); const std::string Want::PARAM_RESV_DISPLAY_ID("ohos.aafwk.param.displayId"); const std::string Want::PARAM_RESV_WITH_ANIMATION("ohos.aafwk.param.withAnimation"); +const std::string Want::PARAM_RESV_WINDOW_FOCUSED("ohos.aafwk.param.windowFocused"); const std::string Want::PARAM_RESV_WINDOW_LEFT("ohos.aafwk.param.windowLeft"); const std::string Want::PARAM_RESV_WINDOW_TOP("ohos.aafwk.param.windowTop"); const std::string Want::PARAM_RESV_WINDOW_WIDTH("ohos.aafwk.param.windowWidth"); @@ -2201,6 +2202,16 @@ void Want::CloseAllFd() parameters_.CloseAllFd(); } +void Want::RemoveAllFd() +{ + parameters_.RemoveAllFd(); +} + +void Want::DupAllFd() +{ + parameters_.DupAllFd(); +} + void Want::SetEntities(const std::vector &entities) { operation_.SetEntities(entities); diff --git a/interfaces/kits/native/want/src/want_params.cpp b/interfaces/kits/native/want/src/want_params.cpp index 30f677235dff5e6e1caafb382b6c0af48c0239f4..0257372e1f011d682f0bb3aadc168bbe7b061f8f 100644 --- a/interfaces/kits/native/want/src/want_params.cpp +++ b/interfaces/kits/native/want/src/want_params.cpp @@ -1287,6 +1287,11 @@ bool WantParams::ReadFromParcelWantParamWrapper(Parcel &parcel, const std::strin return ReadFromParcelFD(parcel, key); } + if (type == VALUE_TYPE_INVALID_FD) { + ABILITYBASE_LOGI("The fd in want is invalid"); + return true; + } + if (type == VALUE_TYPE_REMOTE_OBJECT) { return ReadFromParcelRemoteObject(parcel, key); } @@ -1547,6 +1552,32 @@ void WantParams::CloseAllFd() fds_.clear(); } +void WantParams::RemoveAllFd() +{ + for (auto it : fds_) { + params_.erase(it.first); + } + fds_.clear(); +} + +void WantParams::DupAllFd() +{ + for (auto it : fds_) { + if (it.second > 0) { + int dupFd = dup(it.second); + if (dupFd > 0) { + WantParams wp; + params_.erase(it.first); + wp.SetParam(TYPE_PROPERTY, String::Box(FD)); + wp.SetParam(VALUE_PROPERTY, Integer::Box(dupFd)); + sptr pWantParams = AAFwk::WantParamWrapper::Box(wp); + SetParam(it.first, pWantParams); + fds_[it.first] = dupFd; + } + } + } +} + void WantParams::GetCachedUnsupportedData(std::vector &cachedUnsupportedData) const { for (UnsupportedData item : cachedUnsupportedData_) { diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 2f114acd11ef6092446132e4ad387dedb115b94f..7641ffa1d0f196c9069b6ce76dd24b20fb4a59b9 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -441,12 +441,51 @@ ohos_unittest("extractor_test") { external_deps = [ "ability_base:extractortool", + "ability_base:extractresourcemanager", "ability_base:string_utils", "c_utils:utils", "hilog:libhilog", ] } +###################################################################### +viewdata_output_path = "ability_base/view_data_test" + +###################################################################### +config("viewdata_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "{ability_base_path}/interfaces/kits/native/view_data/include", + "//third_party/zlib/contrib/minizip", + "//third_party/zlib", + ] + + defines = [ "ABILITYBASE_LOG_TAG = \"ViewDataTest\"" ] +} + +ohos_unittest("view_data_test") { + module_out_path = viewdata_output_path + sources = [ "viewdata/view_data_test.cpp" ] + + configs = [ ":viewdata_private_config" ] + + deps = [ + "//third_party/googletest:gtest_main", + "//third_party/zlib:shared_libz", + ] + + external_deps = [ + "ability_base:base", + "ability_base:session_info", + "ability_base:string_utils", + "ability_base:view_data", + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hilog:libhilog", + ] +} + ###################################################################### group("unittest") { @@ -470,6 +509,7 @@ group("unittest") { ":string_wrapper_test", ":uri_test", ":user_object_wrapper_test", + ":view_data_test", ":want_params_test", ":want_params_wrapper_test", ":want_test", diff --git a/test/unittest/extractor/extractor_test.cpp b/test/unittest/extractor/extractor_test.cpp index e32093e31ad0767b0b68adadd2d85d8d9271e885..b8a173fb1a5f1fda33901dbf615645a95c2e48b5 100644 --- a/test/unittest/extractor/extractor_test.cpp +++ b/test/unittest/extractor/extractor_test.cpp @@ -16,6 +16,12 @@ #include #include #include +#define private public +#define protected public +#include "extract_resource_manager.h" +#include "zip_file.h" +#undef private +#undef protected #include "extractor.h" using namespace testing; @@ -141,6 +147,7 @@ HWTEST_F(ExtractorTest, GetLoadFilePath_001, TestSize.Level1) loadPath = TEST_THIRD_HAP_PATH; loadFilePath = ExtractorUtil::GetLoadFilePath(loadPath); + ExtractorUtil::DeleteExtractor(loadPath); EXPECT_TRUE(loadPath != loadFilePath); } @@ -246,29 +253,6 @@ HWTEST_F(ExtractorTest, ExtractByName_001, TestSize.Level1) EXPECT_TRUE(sizeof(outStream) > 0); } -/* - * Feature: Extractor - * Function: ExtractFile - * SubFunction: NA - * FunctionPoints:Extract file - * EnvConditions: NA - * CaseDescription: Create extractor, call extract file function. - */ -HWTEST_F(ExtractorTest, ExtractFile_001, TestSize.Level1) -{ - std::shared_ptr extractor = std::make_shared(testPath_); - std::string outPath = OUT_PATH; - std::string srcPath = MODULE_JSON_PATH; - EXPECT_FALSE(extractor->ExtractFile(srcPath, outPath)); - - extractor->Init(); - EXPECT_FALSE(extractor->ExtractFile("", outPath)); - EXPECT_FALSE(extractor->ExtractFile(srcPath, "")); - EXPECT_TRUE(extractor->ExtractFile(srcPath, outPath)); - std::ifstream f(outPath.c_str()); - EXPECT_TRUE(f.good()); -} - /* * Feature: Extractor * Function: GetSpecifiedTypeFiles @@ -342,5 +326,59 @@ HWTEST_F(ExtractorTest, ExtractToBufByName_001, TestSize.Level1) size_t len = 0; EXPECT_FALSE(extractor1->ExtractToBufByName("", data, len)); } + +/* + * Feature: Extractor + * Function: GetData + * SubFunction: NA + * EnvConditions: NA + * CaseDescription: Create extractor, call GetData function. + */ +HWTEST_F(ExtractorTest, GetData_001, TestSize.Level1) +{ + std::shared_ptr extractor1 = std::make_shared(testPath_); + std::string fileName = "www"; + extractor1->GetData(fileName, false); + extractor1->GetSafeData(fileName); + bool res = extractor1->IsHapCompress(fileName); + EXPECT_EQ(res, false); +} + +/* + * Feature: ExtractResourceManager + * Function: SetGlobalObject + * SubFunction: NA + * EnvConditions: NA + * CaseDescription: Create ExtractResourceManager, call SetGlobalObject function. + */ +HWTEST_F(ExtractorTest, SetGlobalObject_001, TestSize.Level1) +{ + std::shared_ptr resourceManager = nullptr; + std::shared_ptr ers = std::make_shared(); + ers->SetGlobalObject(resourceManager); + EXPECT_EQ(ers->GetGlobalObject(), nullptr); +} + +/* + * Feature: ZipFile + * Function: SetContentLocation + * SubFunction: NA + * EnvConditions: NA + * CaseDescription: Create ZipFile, call SetContentLocation function. + */ +HWTEST_F(ExtractorTest, SetContentLocation_001, TestSize.Level1) +{ + std::shared_ptr zipf = std::make_shared(TEST_HAP_PATH); + ZipPos start = 0; + size_t length = 1; + zipf->SetContentLocation(start, length); + std::string srcPath = "srcPath"; + std::set fileSet; + zipf->GetChildNames(srcPath, fileSet); + std::string fileName = "www"; + std::unique_ptr dataPtr = std::make_unique(length); + bool ret = zipf->ExtractFileFromMMap(fileName, nullptr, dataPtr, length); + EXPECT_EQ(ret, false); +} } // namespace AbilityBase } // namespace OHOS diff --git a/test/unittest/viewdata/view_data_test.cpp b/test/unittest/viewdata/view_data_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b45fcf8419db3ce9cb9b8c398e2564a062bba24 --- /dev/null +++ b/test/unittest/viewdata/view_data_test.cpp @@ -0,0 +1,82 @@ +/* + * 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. + */ + +#include +#include +#include +#include "view_data.h" +#include "session_info.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AbilityBase { +namespace { + static const std::string TJSON = + "{\"abilityName\":\"\",\"bundleName\":\"\",\"moduleName\":\"\"," + "\"nodes\":[],\"pageRect\":\"{\\\"height\\\":0.0,\\\"left\\\":0.0," + "\\\"top\\\":0.0,\\\"width\\\":0.0}\",\"pageUrl\":\"\"}"; +} // namespace +class ViewDataTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void ViewDataTest::SetUpTestCase() +{} + +void ViewDataTest::TearDownTestCase() +{} + +void ViewDataTest::SetUp() +{} + +void ViewDataTest::TearDown() +{} + +/** + * @tc.name: FromJsonString_100 + * @tc.desc: ViewData test for FromJsonString. + * @tc.type: FUNC + */ +HWTEST_F(ViewDataTest, FromJsonString_100, TestSize.Level1) +{ + std::string jsonStr = "jsonStr"; + std::shared_ptr viewdata = std::make_shared(); + EXPECT_TRUE(viewdata != nullptr); + viewdata->FromJsonString(jsonStr); + std::string ret = viewdata->ToJsonString(); + EXPECT_EQ(ret, TJSON); +} + +/** + * @tc.name: Unmarshalling_100 + * @tc.desc: SessionInfo test for Unmarshalling. + * @tc.type: FUNC + */ +HWTEST_F(ViewDataTest, Unmarshalling_100, TestSize.Level1) +{ + std::shared_ptr sessioninfo = std::make_shared(); + EXPECT_TRUE(sessioninfo != nullptr); + Parcel parcel; + auto ret = sessioninfo->Unmarshalling(parcel); + EXPECT_NE(ret, nullptr); +} +} // namespace AbilityBase +} // namespace OHOS diff --git a/test/unittest/want/skills_test.cpp b/test/unittest/want/skills_test.cpp index 64a0b2c0249ec58776ae8fbe0c27510c142823f5..4a3d7225593e9890f2fa824459f2752aafc5e494 100644 --- a/test/unittest/want/skills_test.cpp +++ b/test/unittest/want/skills_test.cpp @@ -387,7 +387,6 @@ HWTEST_F(SkillsBaseTest, AaFwk_Skills_ActionsIterator_0100, Function | MediumTes base_->actions_.push_back("a"); base_->actions_.push_back("b"); auto iter = base_->ActionsIterator(); - EXPECT_EQ(*iter, "a"); } diff --git a/test/unittest/want/want_params_test.cpp b/test/unittest/want/want_params_test.cpp index cbd973c8aaed0c8ba670d292020e8560f67c0176..2c6f73b732f3945f0faba70c953b07030342dc86 100644 --- a/test/unittest/want/want_params_test.cpp +++ b/test/unittest/want/want_params_test.cpp @@ -1235,5 +1235,19 @@ HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetCachedUnsupportedData_1000, Fun EXPECT_EQ(item.size, 1); } } + +/** + * @tc.number: AaFwk_WantParams_DupAllFd_1000 + * @tc.name: DupAllFd + * @tc.desc: Test DupAllFd. + */ +HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_DupAllFd_1000, Function | MediumTest | Level1) +{ + std::string keyStr = "FD"; + std::string valueStr = "sdasdfdsffdgfdg"; + WantParams wantParams; + wantParams.DupAllFd(); + EXPECT_EQ(valueStr, String::Unbox(IString::Query(wantParamsOut_->GetParam(keyStr)))); +} } } diff --git a/test/unittest/want/want_test.cpp b/test/unittest/want/want_test.cpp index c71944376e677d599d9c037b7bd2ba8d078d3fa0..0268edfd0ac654caa6f1879816960e2a04fe3328 100644 --- a/test/unittest/want/want_test.cpp +++ b/test/unittest/want/want_test.cpp @@ -4038,6 +4038,23 @@ HWTEST_F(WantBaseTest, DumpInfo_test_001, TestSize.Level1) GTEST_LOG_(INFO) << "AaFwk_Want_DumpInfo_0100 end"; } +/** + * @tc.number: DupAllFd_test_001 + * @tc.name: DupAllFd + * @tc.desc: Test the want function DupAllFd. + */ +HWTEST_F(WantBaseTest, DupAllFd_test_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DupAllFd_test_001 start"; + + Want want; + want.operation_.entities_.push_back("a"); + want.operation_.entities_.push_back("b"); + want.DupAllFd(); + EXPECT_EQ(true, want.operation_.GetEntities().size() == 2); + GTEST_LOG_(INFO) << "DupAllFd_test_001 end"; +} + /** * @tc.number: SetElementModuleName_test_001 * @tc.name: SetElementModuleName