diff --git a/adapter/data_share/datashare_delegate.cpp b/adapter/data_share/datashare_delegate.cpp index fa524604..5cc686f8 100644 --- a/adapter/data_share/datashare_delegate.cpp +++ b/adapter/data_share/datashare_delegate.cpp @@ -13,29 +13,30 @@ * limitations under the License. */ +#include +#include + #include "datashare_delegate.h" -#include "pasteboard_hilog.h" -#include "pasteboard_error.h" #include "datashare_predicates.h" #include "datashare_result_set.h" #include "datashare_values_bucket.h" #include "iservice_registry.h" +#include "pasteboard_error.h" +#include "pasteboard_hilog.h" #include "third_party/vixl/src/utils-vixl.h" -#include -#include namespace OHOS::MiscServices { -const constexpr char* SETTING_COLUMN_KEYWORD = "KEYWORD"; -const constexpr char* SETTING_COLUMN_VALUE = "VALUE"; -const constexpr char* SETTING_URI_PROXY = - "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true"; -constexpr const char* SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility"; +const constexpr char *SETTING_COLUMN_KEYWORD = "KEYWORD"; +const constexpr char *SETTING_COLUMN_VALUE = "VALUE"; +const constexpr char *SETTING_URI_PROXY = "datashare:///com.ohos.settingsdata/entry/settingsdata/" + "SETTINGSDATA?Proxy=true"; +constexpr const char *SETTINGS_DATA_EXT_URI = "datashare:///com.ohos.settingsdata.DataAbility"; constexpr const int32_t PASTEBOARD_SA_ID = 3701; std::mutex DataShareDelegate::mutex_; sptr DataShareDelegate::remoteObj_ = nullptr; -DataShareDelegate* DataShareDelegate::instance_ = nullptr; -DataShareDelegate& DataShareDelegate::GetInstance() +DataShareDelegate *DataShareDelegate::instance_ = nullptr; +DataShareDelegate &DataShareDelegate::GetInstance() { if (instance_ == nullptr) { std::lock_guard lock(mutex_); @@ -81,20 +82,20 @@ bool DataShareDelegate::ReleaseDataShareHelper(std::shared_ptr(PasteboardError::CREATE_DATASHARE_SERVICE_ERROR); } - std::vector columns = {SETTING_COLUMN_VALUE}; + std::vector columns = { SETTING_COLUMN_VALUE }; DataShare::DataSharePredicates predicates; predicates.EqualTo(SETTING_COLUMN_KEYWORD, key); Uri uri = MakeUri(key); auto resultSet = helper->Query(uri, predicates, columns); ReleaseDataShareHelper(helper); if (resultSet == nullptr) { - PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "Query failed key=%{public}s", key.c_str()); + PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "Query failed key=%{public}s", key.c_str()); return static_cast(PasteboardError::INVALID_RETURN_VALUE_ERROR); } int32_t count; @@ -116,13 +117,13 @@ int32_t DataShareDelegate::GetValue(const std::string& key, std::string& value) return static_cast(PasteboardError::E_OK); } -Uri DataShareDelegate::MakeUri(const std::string& key) +Uri DataShareDelegate::MakeUri(const std::string &key) { Uri uri(std::string(SETTING_URI_PROXY) + "&key=" + key); return uri; } -int32_t DataShareDelegate::RegisterObserver(const std::string& key, sptr observer) +int32_t DataShareDelegate::RegisterObserver(const std::string &key, sptr observer) { auto uri = MakeUri(key); auto helper = CreateDataShareHelper(); @@ -135,7 +136,7 @@ int32_t DataShareDelegate::RegisterObserver(const std::string& key, sptr observer) +int32_t DataShareDelegate::UnregisterObserver(const std::string &key, sptr observer) { auto uri = MakeUri(key); auto helper = CreateDataShareHelper(); diff --git a/adapter/data_share/datashare_delegate.h b/adapter/data_share/datashare_delegate.h index 49b2312c..38ac6afe 100644 --- a/adapter/data_share/datashare_delegate.h +++ b/adapter/data_share/datashare_delegate.h @@ -19,16 +19,17 @@ #include #include #include + #include "datashare_helper.h" namespace OHOS::MiscServices { using ChangeInfo = DataShare::DataShareObserver::ChangeInfo; class DataShareDelegate { public: - static DataShareDelegate& GetInstance(); - int32_t RegisterObserver(const std::string& key, sptr observer); - int32_t UnregisterObserver(const std::string& key, sptr observer); - int32_t GetValue(const std::string& key, std::string& value); + static DataShareDelegate &GetInstance(); + int32_t RegisterObserver(const std::string &key, sptr observer); + int32_t UnregisterObserver(const std::string &key, sptr observer); + int32_t GetValue(const std::string &key, std::string &value); private: DataShareDelegate() = default; @@ -38,10 +39,10 @@ private: static void Initialize(); bool ReleaseDataShareHelper(std::shared_ptr helper); std::shared_ptr CreateDataShareHelper(); - Uri MakeUri(const std::string& key); + Uri MakeUri(const std::string &key); static std::mutex mutex_; - static DataShareDelegate* instance_; + static DataShareDelegate *instance_; static sptr remoteObj_; }; } // namespace OHOS::MiscServices diff --git a/adapter/security_level/security_level.cpp b/adapter/security_level/security_level.cpp index cce0961d..858a0fc4 100644 --- a/adapter/security_level/security_level.cpp +++ b/adapter/security_level/security_level.cpp @@ -12,12 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "device/dm_adapter.h" -#include "security_level.h" -#include "pasteboard_hilog.h" - #include +#include "device/dm_adapter.h" +#include "pasteboard_hilog.h" +#include "security_level.h" + namespace OHOS::MiscServices { uint32_t SecurityLevel::GetDeviceSecurityLevel() { @@ -53,13 +53,12 @@ uint32_t SecurityLevel::GetSensitiveLevel() int32_t result = DATASL_GetHighestSecLevel(&query, &level); if (result != DEVSL_SUCCESS) { PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, - "get highest level failed(%{public}.6s)! level:%{public}u, error:%{public}d", - udid.c_str(), level, result); + "get highest level failed(%{public}.6s)! level:%{public}u, error:%{public}d", udid.c_str(), level, result); return DATA_SEC_LEVEL0; } securityLevel_ = level; - PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "get highest level success(%{public}.6s)! level: %{public}u", - udid.c_str(), level); + PASTEBOARD_HILOGI( + PASTEBOARD_MODULE_SERVICE, "get highest level success(%{public}.6s)! level: %{public}u", udid.c_str(), level); return level; } } // namespace OHOS::MiscServices \ No newline at end of file diff --git a/adapter/security_level/security_level.h b/adapter/security_level/security_level.h index 1e6ba81c..84f0254c 100644 --- a/adapter/security_level/security_level.h +++ b/adapter/security_level/security_level.h @@ -23,6 +23,7 @@ namespace OHOS::MiscServices { class SecurityLevel { public: uint32_t GetDeviceSecurityLevel(); + private: bool InitDEVSLQueryParams(DEVSLQueryParams *params, const std::string &udid); uint32_t GetSensitiveLevel(); diff --git a/framework/framework/clip/clip_plugin.cpp b/framework/framework/clip/clip_plugin.cpp index 8c78b04d..251c1819 100644 --- a/framework/framework/clip/clip_plugin.cpp +++ b/framework/framework/clip/clip_plugin.cpp @@ -14,7 +14,6 @@ */ #include "clip/clip_plugin.h" - #include "default_clip.h" #include "pasteboard_event_dfx.h" namespace OHOS::MiscServices { @@ -36,8 +35,8 @@ ClipPlugin *ClipPlugin::CreatePlugin(const std::string &name) if (it == factories_.end() || it->second == nullptr) { return &g_defaultClip; } - RADAR_REPORT(RadarReporter::DFX_PLUGIN_CREATE_DESTROY, RadarReporter::DFX_PLUGIN_CREATE, - RadarReporter::DFX_SUCCESS); + RADAR_REPORT( + RadarReporter::DFX_PLUGIN_CREATE_DESTROY, RadarReporter::DFX_PLUGIN_CREATE, RadarReporter::DFX_SUCCESS); return it->second->Create(); } @@ -51,14 +50,12 @@ bool ClipPlugin::DestroyPlugin(const std::string &name, ClipPlugin *plugin) if (it == factories_.end() || it->second == nullptr) { return false; } - RADAR_REPORT(RadarReporter::DFX_PLUGIN_CREATE_DESTROY, RadarReporter::DFX_PLUGIN_DESTROY, - RadarReporter::DFX_SUCCESS); + RADAR_REPORT( + RadarReporter::DFX_PLUGIN_CREATE_DESTROY, RadarReporter::DFX_PLUGIN_DESTROY, RadarReporter::DFX_SUCCESS); return it->second->Destroy(plugin); } -ClipPlugin::~ClipPlugin() -{ -} +ClipPlugin::~ClipPlugin() {} std::vector ClipPlugin::GetTopEvents(uint32_t topN) { @@ -73,9 +70,7 @@ std::vector ClipPlugin::GetTopEvents(uint32_t topN, int return std::vector(); } -void ClipPlugin::Clear() -{ -} +void ClipPlugin::Clear() {} int32_t ClipPlugin::PublishServiceState(const std::string &networkId, ServiceStatus status) { diff --git a/framework/framework/clip/default_clip.cpp b/framework/framework/clip/default_clip.cpp index 9a4cbb34..e6a6b0d6 100644 --- a/framework/framework/clip/default_clip.cpp +++ b/framework/framework/clip/default_clip.cpp @@ -29,9 +29,7 @@ std::vector DefaultClip::GetTopEvents(uint32_t topN, i return std::vector(); } -void DefaultClip::Clear(int32_t user) -{ -} +void DefaultClip::Clear(int32_t user) {} int32_t DefaultClip::PublishServiceState(const std::string &networkId, ServiceStatus status) { diff --git a/framework/framework/device/dev_profile.cpp b/framework/framework/device/dev_profile.cpp index 5ce60229..662006da 100644 --- a/framework/framework/device/dev_profile.cpp +++ b/framework/framework/device/dev_profile.cpp @@ -12,12 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "dev_profile.h" - #include #include #include "cJSON.h" +#include "dev_profile.h" #include "distributed_module_config.h" #include "dm_adapter.h" #include "pasteboard_error.h" @@ -40,13 +39,9 @@ constexpr const char *SUPPORT_STATUS = "1"; constexpr const char *SWITCH_ID = "SwitchStatus_Key_Distributed_Pasteboard"; constexpr const char *CHARACTER_ID = "SwitchStatus"; -DevProfile::SubscribeDPChangeListener::SubscribeDPChangeListener() -{ -} +DevProfile::SubscribeDPChangeListener::SubscribeDPChangeListener() {} -DevProfile::SubscribeDPChangeListener::~SubscribeDPChangeListener() -{ -} +DevProfile::SubscribeDPChangeListener::~SubscribeDPChangeListener() {} int32_t DevProfile::SubscribeDPChangeListener::OnTrustDeviceProfileAdd(const TrustDeviceProfile &profile) { @@ -126,9 +121,7 @@ int32_t DevProfile::SubscribeDPChangeListener::OnCharacteristicProfileUpdate( } #endif -DevProfile::DevProfile() -{ -} +DevProfile::DevProfile() {} DevProfile &DevProfile::GetInstance() { @@ -136,9 +129,7 @@ DevProfile &DevProfile::GetInstance() return instance; } -void DevProfile::OnReady() -{ -} +void DevProfile::OnReady() {} void DevProfile::PutEnabledStatus(const std::string &enabledStatus) { @@ -147,19 +138,18 @@ void DevProfile::PutEnabledStatus(const std::string &enabledStatus) PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "PutEnabledStatus, start"); std::string networkId = DMAdapter::GetInstance().GetLocalNetworkId(); auto ret = GetEnabledStatus(networkId); - if (ret.first == static_cast(PasteboardError::E_OK) && - (enabledStatus == ret.second)) { + if (ret.first == static_cast(PasteboardError::E_OK) && (enabledStatus == ret.second)) { return; } std::string udid = DMAdapter::GetInstance().GetUdidByNetworkId(networkId); if (udid.empty()) { - PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "GetUdidByNetworkId failed, networkId is %{public}.5s", - networkId.c_str()); + PASTEBOARD_HILOGE( + PASTEBOARD_MODULE_SERVICE, "GetUdidByNetworkId failed, networkId is %{public}.5s", networkId.c_str()); return; } UE_SWITCH(UeReporter::UE_SWITCH_OPERATION, UeReporter::UE_OPERATION_TYPE, - (enabledStatus == SUPPORT_STATUS) ? - UeReporter::SwitchStatus::SWITCH_OPEN : UeReporter::SwitchStatus::SWITCH_CLOSE); + (enabledStatus == SUPPORT_STATUS) ? UeReporter::SwitchStatus::SWITCH_OPEN + : UeReporter::SwitchStatus::SWITCH_CLOSE); DistributedDeviceProfile::CharacteristicProfile profile; profile.SetDeviceId(udid); profile.SetServiceName(SWITCH_ID); @@ -185,8 +175,8 @@ std::pair DevProfile::GetEnabledStatus(const std::string & return std::make_pair(static_cast(PasteboardError::GET_LOCAL_DEVICE_ID_ERROR), ""); } DistributedDeviceProfile::CharacteristicProfile profile; - int32_t ret = DistributedDeviceProfileClient::GetInstance().GetCharacteristicProfile(udid, SWITCH_ID, - CHARACTER_ID, profile); + int32_t ret = + DistributedDeviceProfileClient::GetInstance().GetCharacteristicProfile(udid, SWITCH_ID, CHARACTER_ID, profile); if (ret == HANDLE_OK && profile.GetCharacteristicValue() == SUPPORT_STATUS) { return std::make_pair(static_cast(PasteboardError::E_OK), SUPPORT_STATUS); } @@ -210,9 +200,8 @@ void DevProfile::GetRemoteDeviceVersion(const std::string &networkId, uint32_t & return; } DistributedDeviceProfile::CharacteristicProfile profile; - int32_t ret = - DistributedDeviceProfileClient::GetInstance().GetCharacteristicProfile( - udid, SERVICE_ID, STATIC_CHARACTER_ID, profile); + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetCharacteristicProfile( + udid, SERVICE_ID, STATIC_CHARACTER_ID, profile); if (ret != HANDLE_OK) { PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "GetCharacteristicProfile failed, %{public}.5s.", udid.c_str()); return; @@ -255,7 +244,7 @@ void DevProfile::SubscribeProfileEvent(const std::string &networkId) subscribeInfo.AddProfileChangeType(ProfileChangeType::CHAR_PROFILE_ADD); subscribeInfo.AddProfileChangeType(ProfileChangeType::CHAR_PROFILE_UPDATE); subscribeInfo.AddProfileChangeType(ProfileChangeType::CHAR_PROFILE_DELETE); - sptr subscribeDPChangeListener = new(std::nothrow) SubscribeDPChangeListener; + sptr subscribeDPChangeListener = new (std::nothrow) SubscribeDPChangeListener; subscribeInfo.SetListener(subscribeDPChangeListener); subscribeInfoCache_[udid] = subscribeInfo; int32_t errCode = DistributedDeviceProfileClient::GetInstance().SubscribeDeviceProfile(subscribeInfo); @@ -280,7 +269,7 @@ void DevProfile::UnSubscribeProfileEvent(const std::string &networkId) if (it == subscribeInfoCache_.end()) { return; } - int32_t errCode = DistributedDeviceProfileClient::GetInstance().UnSubscribeDeviceProfile(it->second); + int32_t errCode = DistributedDeviceProfileClient::GetInstance().UnSubscribeDeviceProfile(it->second); subscribeInfoCache_.erase(it); PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "UnsubscribeProfileEvent result, errCode = %{public}d.", errCode); #else diff --git a/framework/framework/device/distributed_module_config.cpp b/framework/framework/device/distributed_module_config.cpp index ab27da94..e59215a4 100644 --- a/framework/framework/device/distributed_module_config.cpp +++ b/framework/framework/device/distributed_module_config.cpp @@ -12,11 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "distributed_module_config.h" +#include + #include "dev_profile.h" +#include "distributed_module_config.h" #include "pasteboard_error.h" #include "pasteboard_hilog.h" -#include namespace OHOS { namespace MiscServices { @@ -61,15 +62,19 @@ void DistributedModuleConfig::GetRetryTask() ++retry; status = GetEnabledStatus(); if (status == static_cast(PasteboardError::DP_LOAD_SERVICE_ERROR)) { - PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "dp load err, retry:%{public}d, status_:%{public}d" - "newStatus:%{public}d", retry, status_, status); + PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, + "dp load err, retry:%{public}d, status_:%{public}d" + "newStatus:%{public}d", + retry, status_, status); std::this_thread::sleep_for(std::chrono::milliseconds(RETRY_INTERVAL)); continue; } break; } - PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "Retry end. count:%{public}d, status_:%{public}d" - "newStatus:%{public}d", retry, status_, status); + PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, + "Retry end. count:%{public}d, status_:%{public}d" + "newStatus:%{public}d", + retry, status_, status); bool newStatus = (status == static_cast(PasteboardError::E_OK)); if (newStatus != status_) { status_ = newStatus; @@ -131,7 +136,7 @@ void DistributedModuleConfig::OnReady(const std::string &device) void DistributedModuleConfig::Init() { DMAdapter::GetInstance().Register(this); - DevProfile::GetInstance().Watch([this](bool isEnable)-> void { + DevProfile::GetInstance().Watch([this](bool isEnable) -> void { Notify(); }); } diff --git a/framework/framework/ffrt/ffrt_utils.cpp b/framework/framework/ffrt/ffrt_utils.cpp index b1a58001..f74a6f4f 100644 --- a/framework/framework/ffrt/ffrt_utils.cpp +++ b/framework/framework/ffrt/ffrt_utils.cpp @@ -18,12 +18,12 @@ namespace OHOS { namespace MiscServices { -void FFRTUtils::SubmitTask(const FFRTTask& task) +void FFRTUtils::SubmitTask(const FFRTTask &task) { ffrt::submit(task); } -void FFRTUtils::SubmitQueueTasks(const std::vector& tasks, FFRTQueue& queue) +void FFRTUtils::SubmitQueueTasks(const std::vector &tasks, FFRTQueue &queue) { if (tasks.empty()) { return; @@ -33,7 +33,7 @@ void FFRTUtils::SubmitQueueTasks(const std::vector& tasks, FFRTQueue& } } -FFRTHandle FFRTUtils::SubmitDelayTask(FFRTTask& task, uint32_t delayMs, FFRTQueue& queue) +FFRTHandle FFRTUtils::SubmitDelayTask(FFRTTask &task, uint32_t delayMs, FFRTQueue &queue) { using namespace std::chrono; milliseconds ms(delayMs); @@ -41,7 +41,7 @@ FFRTHandle FFRTUtils::SubmitDelayTask(FFRTTask& task, uint32_t delayMs, FFRTQueu return queue.submit_h(task, ffrt::task_attr().delay(us.count())); } -FFRTHandle FFRTUtils::SubmitDelayTask(FFRTTask& task, uint32_t delayMs, std::shared_ptr queue) +FFRTHandle FFRTUtils::SubmitDelayTask(FFRTTask &task, uint32_t delayMs, std::shared_ptr queue) { using namespace std::chrono; milliseconds ms(delayMs); @@ -49,30 +49,26 @@ FFRTHandle FFRTUtils::SubmitDelayTask(FFRTTask& task, uint32_t delayMs, std::sha return queue->submit_h(task, ffrt::task_attr().delay(us.count())); } -bool FFRTUtils::SubmitTimeoutTask(const FFRTTask& task, uint32_t timeoutMs) +bool FFRTUtils::SubmitTimeoutTask(const FFRTTask &task, uint32_t timeoutMs) { ffrt::future future = ffrt::async(task); auto status = future.wait_for(std::chrono::milliseconds(timeoutMs)); return status == ffrt::future_status::ready; } -int FFRTUtils::CancelTask(FFRTHandle& handle, FFRTQueue& queue) +int FFRTUtils::CancelTask(FFRTHandle &handle, FFRTQueue &queue) { return queue.cancel(handle); } -int FFRTUtils::CancelTask(FFRTHandle& handle, std::shared_ptr queue) +int FFRTUtils::CancelTask(FFRTHandle &handle, std::shared_ptr queue) { return queue->cancel(handle); } -FFRTTimer::FFRTTimer(): queue_("ffrt_timer") -{ -} +FFRTTimer::FFRTTimer() : queue_("ffrt_timer") {} -FFRTTimer::FFRTTimer(const char *timer_name): queue_(timer_name) -{ -} +FFRTTimer::FFRTTimer(const char *timer_name) : queue_(timer_name) {} FFRTTimer::~FFRTTimer() { @@ -103,18 +99,18 @@ void FFRTTimer::CancelTimer(const std::string &timerId) mutex_.unlock(); } -void FFRTTimer::SetTimer(const std::string &timerId, FFRTTask& task) +void FFRTTimer::SetTimer(const std::string &timerId, FFRTTask &task) { mutex_.lock(); CancelTimerInner(timerId); ++taskId_[timerId]; - PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "Timer[%{public}s] Add Task[%{public}u]", timerId.c_str(), - taskId_[timerId]); + PASTEBOARD_HILOGD( + PASTEBOARD_MODULE_SERVICE, "Timer[%{public}s] Add Task[%{public}u]", timerId.c_str(), taskId_[timerId]); FFRTUtils::SubmitTask(task); mutex_.unlock(); } -void FFRTTimer::SetTimer(const std::string &timerId, FFRTTask& task, uint32_t delayMs) +void FFRTTimer::SetTimer(const std::string &timerId, FFRTTask &task, uint32_t delayMs) { if (delayMs == 0) { return SetTimer(timerId, task); @@ -152,8 +148,8 @@ void FFRTTimer::CancelAllTimerInner() void FFRTTimer::CancelTimerInner(const std::string &timerId) { if (handleMap_[timerId] != nullptr) { - PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "Timer[%{public}s] Cancel Task[%{public}u]", timerId.c_str(), - taskId_[timerId]); + PASTEBOARD_HILOGD( + PASTEBOARD_MODULE_SERVICE, "Timer[%{public}s] Cancel Task[%{public}u]", timerId.c_str(), taskId_[timerId]); FFRTUtils::CancelTask(handleMap_[timerId], queue_); handleMap_[timerId] = nullptr; } diff --git a/framework/framework/include/common/concurrent_map.h b/framework/framework/include/common/concurrent_map.h index cad24f22..ca9ec73d 100644 --- a/framework/framework/include/common/concurrent_map.h +++ b/framework/framework/include/common/concurrent_map.h @@ -140,8 +140,9 @@ public: } std::lock_guard lock(mutex_); #if __cplusplus > 201703L - auto count = std::erase_if( - entries_, [&action](value_type &value) -> bool { return action(value.first, value.second); }); + auto count = std::erase_if(entries_, [&action](value_type &value) -> bool { + return action(value.first, value.second); + }); #else auto count = entries_.size(); for (auto it = entries_.begin(); it != entries_.end();) { diff --git a/framework/framework/include/serializable/serializable.h b/framework/framework/include/serializable/serializable.h index a32ac6a7..f2daaad1 100644 --- a/framework/framework/include/serializable/serializable.h +++ b/framework/framework/include/serializable/serializable.h @@ -30,7 +30,7 @@ namespace DistributedData { #endif struct Serializable { public: - using json = cJSON*; + using json = cJSON *; API_EXPORT bool Unmarshall(const std::string &jsonStr); API_EXPORT std::string Marshall() const; virtual bool Marshal(json &node) const = 0; @@ -45,30 +45,19 @@ public: API_EXPORT static bool GetValue(const json node, const std::string &name, bool &value); API_EXPORT static bool GetValue(const json node, const std::string &name, std::vector &value); API_EXPORT static bool GetValue(const json node, const std::string &name, Serializable &value); - API_EXPORT static bool SetValue( - json &node, const std::string &value, const std::string &name = ""); - API_EXPORT static bool SetValue( - json &node, const uint8_t &value, const std::string &name = ""); - API_EXPORT static bool SetValue( - json &node, const uint16_t &value, const std::string &name = ""); - API_EXPORT static bool SetValue( - json &node, const uint32_t &value, const std::string &name = ""); - API_EXPORT static bool SetValue( - json &node, const uint64_t &value, const std::string &name = ""); - API_EXPORT static bool SetValue( - json &node, const int32_t &value, const std::string &name = ""); - API_EXPORT static bool SetValue( - json &node, const int64_t &value, const std::string &name = ""); - API_EXPORT static bool SetValue( - json &node, const bool &value, const std::string &name = ""); - API_EXPORT static bool SetValue( - json &node, const std::vector &value, const std::string &name = ""); - API_EXPORT static bool SetValue( - json &node, const Serializable &value, const std::string &name = ""); + API_EXPORT static bool SetValue(json &node, const std::string &value, const std::string &name = ""); + API_EXPORT static bool SetValue(json &node, const uint8_t &value, const std::string &name = ""); + API_EXPORT static bool SetValue(json &node, const uint16_t &value, const std::string &name = ""); + API_EXPORT static bool SetValue(json &node, const uint32_t &value, const std::string &name = ""); + API_EXPORT static bool SetValue(json &node, const uint64_t &value, const std::string &name = ""); + API_EXPORT static bool SetValue(json &node, const int32_t &value, const std::string &name = ""); + API_EXPORT static bool SetValue(json &node, const int64_t &value, const std::string &name = ""); + API_EXPORT static bool SetValue(json &node, const bool &value, const std::string &name = ""); + API_EXPORT static bool SetValue(json &node, const std::vector &value, const std::string &name = ""); + API_EXPORT static bool SetValue(json &node, const Serializable &value, const std::string &name = ""); template - static bool SetValue( - json &node, const std::vector &values, const std::string &name = "") + static bool SetValue(json &node, const std::vector &values, const std::string &name = "") { bool result = true; auto subNode = cJSON_CreateArray(); @@ -85,6 +74,7 @@ public: SetValueToObject(node, subNode, name); return result; } + protected: API_EXPORT ~Serializable() = default; diff --git a/framework/framework/serializable/serializable.cpp b/framework/framework/serializable/serializable.cpp index c2c468c7..212a07e6 100644 --- a/framework/framework/serializable/serializable.cpp +++ b/framework/framework/serializable/serializable.cpp @@ -31,7 +31,7 @@ std::string Serializable::Marshall() const { json node; Marshal(node); - char* value = cJSON_PrintUnformatted(node); + char *value = cJSON_PrintUnformatted(node); std::string result; if (value != nullptr) { result = std::string(value); diff --git a/framework/innerkits/src/convert_utils.cpp b/framework/innerkits/src/convert_utils.cpp index 816daf09..87348972 100644 --- a/framework/innerkits/src/convert_utils.cpp +++ b/framework/innerkits/src/convert_utils.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ #include "convert_utils.h" - #include "pasteboard_hilog.h" #include "unified_meta.h" namespace OHOS { @@ -23,14 +22,14 @@ using UnifiedData = UDMF::UnifiedData; using UnifiedDataProperties = UDMF::UnifiedDataProperties; using UDType = UDMF::UDType; -std::shared_ptr ConvertUtils::Convert(const UnifiedData& unifiedData) +std::shared_ptr ConvertUtils::Convert(const UnifiedData &unifiedData) { auto pasteData = std::make_shared(Convert(unifiedData.GetRecords())); pasteData->SetProperty(ConvertProperty(unifiedData.GetProperties(), unifiedData)); return pasteData; } -std::shared_ptr ConvertUtils::Convert(const PasteData& pasteData) +std::shared_ptr ConvertUtils::Convert(const PasteData &pasteData) { auto unifiedData = std::make_shared(); unifiedData->SetRecords(Convert(pasteData.AllRecords())); @@ -40,20 +39,20 @@ std::shared_ptr ConvertUtils::Convert(const PasteData& pasteData) } std::vector> ConvertUtils::Convert( - const std::vector>& records) + const std::vector> &records) { std::vector> unifiedRecords; - for (auto const& record : records) { + for (auto const &record : records) { unifiedRecords.emplace_back(Convert(record)); } return unifiedRecords; } std::vector> ConvertUtils::Convert( - const std::vector>& records) + const std::vector> &records) { std::vector> pasteboardRecords; - for (auto const& record : records) { + for (auto const &record : records) { pasteboardRecords.emplace_back(Convert(record)); } return pasteboardRecords; @@ -71,8 +70,8 @@ std::shared_ptr ConvertUtils::Convert(std::shared_ptrGetUDMFValue(); if (udmfValue) { - udmfRecord->AddEntry(CommonUtils::Convert2UtdId(record->GetUDType(), record->GetMimeType()), - std::move(*udmfValue)); + udmfRecord->AddEntry( + CommonUtils::Convert2UtdId(record->GetUDType(), record->GetMimeType()), std::move(*udmfValue)); } return udmfRecord; } @@ -94,7 +93,7 @@ std::shared_ptr ConvertUtils::Convert(std::shared_ptr pbRecord = std::make_shared(); auto utdId = record->GetUtdId(); pbRecord->AddEntry(utdId, std::make_shared(utdId, record->GetOriginValue())); - for (auto const& entry : Convert(record->GetEntries())) { + for (auto const &entry : Convert(record->GetEntries())) { if (entry == nullptr) { PASTEBOARD_HILOGW(PASTEBOARD_MODULE_CLIENT, "entry is empty"); continue; @@ -113,24 +112,24 @@ std::shared_ptr ConvertUtils::Convert(std::shared_ptr> ConvertUtils::Convert( - const std::shared_ptr>& entries) + const std::shared_ptr> &entries) { std::vector> pbEntries; if (entries == nullptr) { PASTEBOARD_HILOGW(PASTEBOARD_MODULE_CLIENT, "pbEntries is empty"); return pbEntries; } - for (auto const& [utdId, value] : *entries) { + for (auto const &[utdId, value] : *entries) { pbEntries.emplace_back(std::make_shared(utdId, value)); } return pbEntries; } std::shared_ptr> ConvertUtils::Convert( - const std::vector>& entries) + const std::vector> &entries) { std::map udmfEntries; - for (auto const& entry : entries) { + for (auto const &entry : entries) { if (entry == nullptr) { continue; } @@ -139,8 +138,8 @@ std::shared_ptr> ConvertUtils::Convert( return std::make_shared>(udmfEntries); } -PasteDataProperty ConvertUtils::ConvertProperty(const std::shared_ptr& properties, - const UnifiedData& unifiedData) +PasteDataProperty ConvertUtils::ConvertProperty( + const std::shared_ptr &properties, const UnifiedData &unifiedData) { if (!properties) { return {}; @@ -156,7 +155,7 @@ PasteDataProperty ConvertUtils::ConvertProperty(const std::shared_ptr ConvertUtils::ConvertProperty(const PasteDataProperty& properties) +std::shared_ptr ConvertUtils::ConvertProperty(const PasteDataProperty &properties) { auto unifiedDataProperties = std::make_shared(); unifiedDataProperties->shareOptions = properties.shareOption == InApp ? UDMF::ShareOptions::IN_APP @@ -168,10 +167,10 @@ std::shared_ptr ConvertUtils::ConvertProperty(const Paste return unifiedDataProperties; } -std::vector ConvertUtils::Convert(const std::vector& utdIds) +std::vector ConvertUtils::Convert(const std::vector &utdIds) { std::vector types; - for (const auto& utdId : utdIds) { + for (const auto &utdId : utdIds) { types.push_back(CommonUtils::Convert2MimeType(utdId)); } return types; diff --git a/framework/innerkits/src/paste_data.cpp b/framework/innerkits/src/paste_data.cpp index 4730ad6a..248c1913 100644 --- a/framework/innerkits/src/paste_data.cpp +++ b/framework/innerkits/src/paste_data.cpp @@ -14,11 +14,10 @@ * limitations under the License. */ -#include "paste_data.h" - #include #include "parcel_util.h" +#include "paste_data.h" #include "paste_data_record.h" #include "pasteboard_hilog.h" #include "type_traits" @@ -77,9 +76,10 @@ PasteData::~PasteData() records_.clear(); } -PasteData::PasteData(const PasteData &data) : orginAuthority_(data.orginAuthority_), valid_(data.valid_), - isDraggedData_(data.isDraggedData_), isLocalPaste_(data.isLocalPaste_), isDelayData_(data.isDelayData_), - pasteId_(data.pasteId_), isDelayRecord_(data.isDelayRecord_), dataId_(data.dataId_) +PasteData::PasteData(const PasteData &data) + : orginAuthority_(data.orginAuthority_), valid_(data.valid_), isDraggedData_(data.isDraggedData_), + isLocalPaste_(data.isLocalPaste_), isDelayData_(data.isDelayData_), pasteId_(data.pasteId_), + isDelayRecord_(data.isDelayRecord_), dataId_(data.dataId_) { this->props_ = data.props_; for (const auto &item : data.records_) { @@ -96,7 +96,7 @@ PasteData::PasteData(std::vector> records) : re InitDecodeMap(); } -PasteData& PasteData::operator=(const PasteData &data) +PasteData &PasteData::operator=(const PasteData &data) { PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "PasteData copy"); if (this == &data) { @@ -449,24 +449,42 @@ bool PasteData::Encode(std::vector &buffer) void PasteData::InitDecodeMap() { decodeMap_ = { - {TAG_PROPS, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, props_, head);}}, - {TAG_RECORDS, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, records_, head);}}, - {TAG_DRAGGED_DATA_FLAG, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, isDraggedData_, head);}}, - {TAG_LOCAL_PASTE_FLAG, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, isLocalPaste_, head);}}, - {TAG_DELAY_DATA_FLAG, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, isDelayData_, head);}}, - {TAG_DEVICE_ID, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, deviceId_, head);}}, - {TAG_PASTE_ID, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, pasteId_, head);}}, - {TAG_DELAY_RECORD_FLAG, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, isDelayRecord_, head);}}, - {TAG_DATA_ID, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, dataId_, head);}}, + { TAG_PROPS, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, props_, head); + } }, + { TAG_RECORDS, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, records_, head); + } }, + { TAG_DRAGGED_DATA_FLAG, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, isDraggedData_, head); + } }, + { TAG_LOCAL_PASTE_FLAG, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, isLocalPaste_, head); + } }, + { TAG_DELAY_DATA_FLAG, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, isDelayData_, head); + } }, + { TAG_DEVICE_ID, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, deviceId_, head); + } }, + { TAG_PASTE_ID, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, pasteId_, head); + } }, + { TAG_DELAY_RECORD_FLAG, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, isDelayRecord_, head); + } }, + { TAG_DATA_ID, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, dataId_, head); + } }, }; } @@ -484,8 +502,8 @@ bool PasteData::Decode(const std::vector &buffer) func(ret, buffer, head); } if (!ret) { - PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "read value,tag:%{public}u, len:%{public}u", - head.tag, head.len); + PASTEBOARD_HILOGE( + PASTEBOARD_MODULE_CLIENT, "read value,tag:%{public}u, len:%{public}u", head.tag, head.len); return false; } } @@ -550,7 +568,7 @@ uint32_t PasteData::GetDataId() const bool PasteData::Marshalling(Parcel &parcel) const { std::vector pasteDataTlv(0); - if (!const_cast(this)->Encode(pasteDataTlv)) { + if (!const_cast(this)->Encode(pasteDataTlv)) { PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "Encode failed"); return false; } @@ -561,9 +579,9 @@ bool PasteData::Marshalling(Parcel &parcel) const return true; } -PasteData* PasteData::Unmarshalling(Parcel &parcel) +PasteData *PasteData::Unmarshalling(Parcel &parcel) { - PasteData* pasteData = new (std::nothrow) PasteData(); + PasteData *pasteData = new (std::nothrow) PasteData(); if (pasteData != nullptr && !pasteData->ReadFromParcel(parcel)) { delete pasteData; pasteData = nullptr; @@ -591,8 +609,8 @@ bool PasteData::ReadFromParcel(Parcel &parcel) PasteDataProperty::PasteDataProperty(const PasteDataProperty &property) : tag(property.tag), timestamp(property.timestamp), localOnly(property.localOnly), - shareOption(property.shareOption), tokenId(property.tokenId), isRemote(property.isRemote), - bundleName(property.bundleName), setTime(property.setTime), screenStatus(property.screenStatus) + shareOption(property.shareOption), tokenId(property.tokenId), isRemote(property.isRemote), + bundleName(property.bundleName), setTime(property.setTime), screenStatus(property.screenStatus) { this->additions = property.additions; std::copy(property.mimeTypes.begin(), property.mimeTypes.end(), std::back_inserter(this->mimeTypes)); @@ -603,7 +621,7 @@ PasteDataProperty::~PasteDataProperty() mimeTypes.clear(); } -PasteDataProperty& PasteDataProperty::operator=(const PasteDataProperty &property) +PasteDataProperty &PasteDataProperty::operator=(const PasteDataProperty &property) { PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "PasteDataProperty copy"); if (this == &property) { @@ -624,7 +642,6 @@ PasteDataProperty& PasteDataProperty::operator=(const PasteDataProperty &propert return *this; } - bool PasteDataProperty::Encode(std::vector &buffer) { bool ret = Write(buffer, TAG_ADDITIONS, ParcelUtil::Parcelable2Raw(&additions)); diff --git a/framework/innerkits/src/paste_data_entry.cpp b/framework/innerkits/src/paste_data_entry.cpp index b1b453e6..04fa9c86 100644 --- a/framework/innerkits/src/paste_data_entry.cpp +++ b/framework/innerkits/src/paste_data_entry.cpp @@ -13,9 +13,8 @@ * limitations under the License. */ -#include "paste_data_entry.h" - #include "common/constant.h" +#include "paste_data_entry.h" #include "pasteboard_hilog.h" #include "pixel_map.h" #include "tlv_object.h" @@ -37,18 +36,18 @@ std::map> MineCustomData::GetItemData() return this->itemData_; } -void MineCustomData::AddItemData(const std::string& mimeType, const std::vector& arrayBuffer) +void MineCustomData::AddItemData(const std::string &mimeType, const std::vector &arrayBuffer) { itemData_.emplace(mimeType, arrayBuffer); PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "itemData_.size = %{public}zu", itemData_.size()); } -bool MineCustomData::Encode(std::vector& buffer) +bool MineCustomData::Encode(std::vector &buffer) { return Write(buffer, TAG_ITEM_DATA, itemData_); } -bool MineCustomData::Decode(const std::vector& buffer) +bool MineCustomData::Decode(const std::vector &buffer) { for (; IsEnough();) { TLVHead head{}; @@ -73,12 +72,12 @@ size_t MineCustomData::Count() return TLVObject::Count(itemData_); } -PasteDataEntry::PasteDataEntry(const PasteDataEntry& entry) +PasteDataEntry::PasteDataEntry(const PasteDataEntry &entry) : utdId_(entry.utdId_), mimeType_(entry.mimeType_), value_(entry.value_) { } -PasteDataEntry& PasteDataEntry::operator=(const PasteDataEntry& entry) +PasteDataEntry &PasteDataEntry::operator=(const PasteDataEntry &entry) { if (this == &entry) { return *this; @@ -89,17 +88,17 @@ PasteDataEntry& PasteDataEntry::operator=(const PasteDataEntry& entry) return *this; } -PasteDataEntry::PasteDataEntry(const std::string& utdId, const EntryValue& value) : utdId_(utdId), value_(value) +PasteDataEntry::PasteDataEntry(const std::string &utdId, const EntryValue &value) : utdId_(utdId), value_(value) { mimeType_ = CommonUtils::Convert2MimeType(utdId_); } -PasteDataEntry::PasteDataEntry(const std::string& utdId, const std::string& mimeType, const EntryValue& value) +PasteDataEntry::PasteDataEntry(const std::string &utdId, const std::string &mimeType, const EntryValue &value) : utdId_(utdId), mimeType_(std::move(mimeType)), value_(std::move(value)) { } -void PasteDataEntry::SetUtdId(const std::string& utdId) +void PasteDataEntry::SetUtdId(const std::string &utdId) { utdId_ = utdId; } @@ -109,7 +108,7 @@ std::string PasteDataEntry::GetUtdId() const return utdId_; } -void PasteDataEntry::SetMimeType(const std::string& mimeType) +void PasteDataEntry::SetMimeType(const std::string &mimeType) { mimeType_ = mimeType; } @@ -124,12 +123,12 @@ EntryValue PasteDataEntry::GetValue() const return value_; } -void PasteDataEntry::SetValue(const EntryValue& value) +void PasteDataEntry::SetValue(const EntryValue &value) { value_ = value; } -bool PasteDataEntry::Encode(std::vector& buffer) +bool PasteDataEntry::Encode(std::vector &buffer) { bool ret = Write(buffer, TAG_ENTRY_UTDID, utdId_); ret = ret && Write(buffer, TAG_ENTRY_MIMETYPE, mimeType_); @@ -137,7 +136,7 @@ bool PasteDataEntry::Encode(std::vector& buffer) return ret; } -bool PasteDataEntry::Decode(const std::vector& buffer) +bool PasteDataEntry::Decode(const std::vector &buffer) { for (; IsEnough();) { TLVHead head{}; @@ -167,13 +166,13 @@ bool PasteDataEntry::Decode(const std::vector& buffer) return true; } -bool PasteDataEntry::Marshalling(std::vector& buffer) +bool PasteDataEntry::Marshalling(std::vector &buffer) { Init(buffer); return Encode(buffer); } -bool PasteDataEntry::Unmarshalling(const std::vector& buffer) +bool PasteDataEntry::Unmarshalling(const std::vector &buffer) { total_ = buffer.size(); return Decode(buffer); @@ -356,7 +355,7 @@ std::string CommonUtils::Convert(UDType uDType) } } -std::string CommonUtils::Convert2MimeType(const std::string& utdId) +std::string CommonUtils::Convert2MimeType(const std::string &utdId) { if (utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::PLAIN_TEXT) || utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::HYPERLINK)) { @@ -378,7 +377,7 @@ std::string CommonUtils::Convert2MimeType(const std::string& utdId) } // other is appdefined-types -std::string CommonUtils::Convert2UtdId(int32_t uDType, const std::string& mimeType) +std::string CommonUtils::Convert2UtdId(int32_t uDType, const std::string &mimeType) { if (mimeType == MIMETYPE_TEXT_PLAIN && uDType == UDMF::HYPERLINK) { return UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::HYPERLINK); @@ -401,7 +400,7 @@ std::string CommonUtils::Convert2UtdId(int32_t uDType, const std::string& mimeTy return mimeType; } -UDMF::UDType CommonUtils::Convert(int32_t uDType, const std::string& mimeType) +UDMF::UDType CommonUtils::Convert(int32_t uDType, const std::string &mimeType) { if (uDType != UDMF::UD_BUTT) { return static_cast(uDType); diff --git a/framework/innerkits/src/paste_data_record.cpp b/framework/innerkits/src/paste_data_record.cpp index c5be21b6..0a726c4c 100644 --- a/framework/innerkits/src/paste_data_record.cpp +++ b/framework/innerkits/src/paste_data_record.cpp @@ -12,14 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "paste_data_record.h" - #include #include #include "convert_utils.h" #include "copy_uri_handler.h" #include "parcel_util.h" +#include "paste_data_record.h" #include "pasteboard_hilog.h" #include "pixel_map_parcel.h" @@ -62,7 +61,7 @@ PasteDataRecord::Builder &PasteDataRecord::Builder::SetHtmlText(std::shared_ptr< return *this; } -PasteDataRecord::Builder& PasteDataRecord::Builder::SetWant(std::shared_ptr want) +PasteDataRecord::Builder &PasteDataRecord::Builder::SetWant(std::shared_ptr want) { record_->want_ = std::move(want); return *this; @@ -179,7 +178,7 @@ PasteDataRecord::~PasteDataRecord() decodeMap.clear(); } -PasteDataRecord::PasteDataRecord(const PasteDataRecord& record) +PasteDataRecord::PasteDataRecord(const PasteDataRecord &record) : mimeType_(record.mimeType_), htmlText_(record.htmlText_), want_(record.want_), plainText_(record.plainText_), uri_(record.uri_), convertUri_(record.convertUri_), pixelMap_(record.pixelMap_), customData_(record.customData_), hasGrantUriPermission_(record.hasGrantUriPermission_), fd_(record.fd_), udType_(record.udType_), @@ -194,48 +193,84 @@ PasteDataRecord::PasteDataRecord(const PasteDataRecord& record) void PasteDataRecord::InitDecodeMap() { decodeMap = { - {TAG_MIMETYPE, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, mimeType_, head);}}, - {TAG_HTMLTEXT, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, htmlText_, head);}}, - {TAG_WANT, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - RawMem rawMem{}; - ret = ret && ReadValue(buffer, rawMem, head); - want_ = ParcelUtil::Raw2Parcelable(rawMem);}}, - {TAG_PLAINTEXT, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, plainText_, head); }}, - {TAG_URI, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - RawMem rawMem{}; - ret = ret && ReadValue(buffer, rawMem, head); - uri_ = ParcelUtil::Raw2Parcelable(rawMem);}}, - {TAG_CONVERT_URI, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, convertUri_, head);}}, - {TAG_PIXELMAP, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - std::vector value; - ret = ret && ReadValue(buffer, value, head); - pixelMap_ = Vector2PixelMap(value);}}, - {TAG_CUSTOM_DATA, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, customData_, head);}}, - {TAG_URI_PERMISSION, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, hasGrantUriPermission_, head);}}, - {TAG_UDC_UDTYPE, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, udType_, head);}}, - {TAG_UDC_DETAILS, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, details_, head);}}, - {TAG_UDC_TEXTCONTENT, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, textContent_, head);}}, - {TAG_UDC_SYSTEMCONTENTS, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, systemDefinedContents_, head);}}, - {TAG_UDC_UDMFVALUE, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, udmfValue_, head);}}, - {TAG_UDC_ENTYIES, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, entries_, head);}}, - {TAG_DATA_ID, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, dataId_, head);}}, - {TAG_RECORD_ID, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, recordId_, head);}}, - {TAG_DELAY_RECORD_FLAG, [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { - ret = ret && ReadValue(buffer, isDelay_, head);}}, + { TAG_MIMETYPE, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, mimeType_, head); + } }, + { TAG_HTMLTEXT, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, htmlText_, head); + } }, + { TAG_WANT, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + RawMem rawMem{}; + ret = ret && ReadValue(buffer, rawMem, head); + want_ = ParcelUtil::Raw2Parcelable(rawMem); + } }, + { TAG_PLAINTEXT, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, plainText_, head); + } }, + { TAG_URI, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + RawMem rawMem{}; + ret = ret && ReadValue(buffer, rawMem, head); + uri_ = ParcelUtil::Raw2Parcelable(rawMem); + } }, + { TAG_CONVERT_URI, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, convertUri_, head); + } }, + { TAG_PIXELMAP, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + std::vector value; + ret = ret && ReadValue(buffer, value, head); + pixelMap_ = Vector2PixelMap(value); + } }, + { TAG_CUSTOM_DATA, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, customData_, head); + } }, + { TAG_URI_PERMISSION, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, hasGrantUriPermission_, head); + } }, + { TAG_UDC_UDTYPE, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, udType_, head); + } }, + { TAG_UDC_DETAILS, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, details_, head); + } }, + { TAG_UDC_TEXTCONTENT, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, textContent_, head); + } }, + { TAG_UDC_SYSTEMCONTENTS, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, systemDefinedContents_, head); + } }, + { TAG_UDC_UDMFVALUE, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, udmfValue_, head); + } }, + { TAG_UDC_ENTYIES, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, entries_, head); + } }, + { TAG_DATA_ID, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, dataId_, head); + } }, + { TAG_RECORD_ID, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, recordId_, head); + } }, + { TAG_DELAY_RECORD_FLAG, + [&](bool &ret, const std::vector &buffer, TLVHead &head) -> void { + ret = ret && ReadValue(buffer, isDelay_, head); + } }, }; } @@ -283,7 +318,7 @@ std::shared_ptr PasteDataRecord::GetOrginUri() const if (uri_) { return uri_; } - for (auto const& entry: entries_) { + for (auto const &entry : entries_) { if (entry && entry->GetMimeType() == MIMETYPE_TEXT_URI) { return entry->ConvertToUri(); } @@ -351,8 +386,8 @@ bool PasteDataRecord::Decode(const std::vector &buffer) func(ret, buffer, head); } if (!ret) { - PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "read value,tag:%{public}u, len:%{public}u", - head.tag, head.len); + PASTEBOARD_HILOGE( + PASTEBOARD_MODULE_CLIENT, "read value,tag:%{public}u, len:%{public}u", head.tag, head.len); return false; } } @@ -471,7 +506,7 @@ bool PasteDataRecord::HasGrantUriPermission() return hasGrantUriPermission_; } -void PasteDataRecord::SetTextContent(const std::string& content) +void PasteDataRecord::SetTextContent(const std::string &content) { this->textContent_ = content; } @@ -481,7 +516,7 @@ std::string PasteDataRecord::GetTextContent() const return this->textContent_; } -void PasteDataRecord::SetDetails(const Details& details) +void PasteDataRecord::SetDetails(const Details &details) { this->details_ = std::make_shared
(details); } @@ -491,7 +526,7 @@ std::shared_ptr
PasteDataRecord::GetDetails() const return this->details_; } -void PasteDataRecord::SetSystemDefinedContent(const Details& contents) +void PasteDataRecord::SetSystemDefinedContent(const Details &contents) { this->systemDefinedContents_ = std::make_shared
(contents); } @@ -510,11 +545,11 @@ void PasteDataRecord::SetUDType(int32_t type) this->udType_ = type; } -std::vector PasteDataRecord::GetValidTypes(const std::vector& types) const +std::vector PasteDataRecord::GetValidTypes(const std::vector &types) const { std::vector res; auto allTypes = GetUdtTypes(); - for (auto const& type : types) { + for (auto const &type : types) { if (allTypes.find(type) != allTypes.end()) { res.emplace_back(type); } @@ -527,7 +562,7 @@ bool PasteDataRecord::IsEmpty() const if (udmfValue_ && !std::holds_alternative(*udmfValue_)) { return false; } - for (auto const& entry : entries_) { + for (auto const &entry : entries_) { if (!std::holds_alternative(entry->GetValue())) { return false; } @@ -535,7 +570,7 @@ bool PasteDataRecord::IsEmpty() const return true; } -void PasteDataRecord::SetUDMFValue(const std::shared_ptr& udmfValue) +void PasteDataRecord::SetUDMFValue(const std::shared_ptr &udmfValue) { this->udmfValue_ = udmfValue; } @@ -594,13 +629,13 @@ std::set PasteDataRecord::GetUdtTypes() const { std::set types; types.emplace(CommonUtils::Convert2UtdId(udType_, mimeType_)); - for (auto const& entry: entries_) { + for (auto const &entry : entries_) { types.emplace(entry->GetUtdId()); } return types; } -void PasteDataRecord::AddEntry(const std::string& utdType, std::shared_ptr value) +void PasteDataRecord::AddEntry(const std::string &utdType, std::shared_ptr value) { if (!value) { PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "entry is null"); @@ -634,7 +669,7 @@ void PasteDataRecord::AddEntry(const std::string& utdType, std::shared_ptrGetUtdId() == utdType) { entry = value; has = true; @@ -646,12 +681,12 @@ void PasteDataRecord::AddEntry(const std::string& utdType, std::shared_ptr PasteDataRecord::GetEntry(const std::string& utdType) const +std::shared_ptr PasteDataRecord::GetEntry(const std::string &utdType) const { if (udmfValue_ && CommonUtils::Convert2UtdId(udType_, mimeType_) == utdType) { return std::make_shared(utdType, *udmfValue_); } - for (auto const& entry : entries_) { + for (auto const &entry : entries_) { if (entry->GetUtdId() == utdType) { return entry; } diff --git a/services/core/src/pasteboard_dialog.cpp b/services/core/src/pasteboard_dialog.cpp index e6bfc918..cb77418c 100644 --- a/services/core/src/pasteboard_dialog.cpp +++ b/services/core/src/pasteboard_dialog.cpp @@ -15,12 +15,12 @@ #include -#include "pasteboard_dialog.h" -#include "pasteboard_error.h" #include "ability_connect_callback_stub.h" #include "ability_manager_proxy.h" #include "in_process_call_wrapper.h" #include "iservice_registry.h" +#include "pasteboard_dialog.h" +#include "pasteboard_error.h" #include "pasteboard_hilog.h" #include "system_ability_definition.h" @@ -28,9 +28,7 @@ namespace OHOS::MiscServices { using namespace OHOS::AAFwk; class DialogConnection : public AAFwk::AbilityConnectionStub { public: - explicit DialogConnection(PasteBoardDialog::Cancel cancel) : cancel_(std::move(cancel)) - { - } + explicit DialogConnection(PasteBoardDialog::Cancel cancel) : cancel_(std::move(cancel)) {} DialogConnection(const DialogConnection &) = delete; DialogConnection &operator=(const DialogConnection &) = delete; DialogConnection(DialogConnection &&) = delete; @@ -78,8 +76,8 @@ int32_t PasteBoardDialog::ShowToast(const ToastMessageInfo &message) std::lock_guard lock(connectionLock_); connection_ = new DialogConnection(nullptr); - int32_t result = IN_PROCESS_CALL(abilityManager->ConnectAbility(want, iface_cast( - connection_), nullptr)); + int32_t result = IN_PROCESS_CALL( + abilityManager->ConnectAbility(want, iface_cast(connection_), nullptr)); if (result != 0) { PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "start pasteboard toast failed, result:%{public}d", result); return static_cast(PasteboardError::TASK_PROCESSING);