Signed-off-by: z30053452 <zhiyihang1@huawei.com>
This commit is contained in:
z30053452 2024-09-28 10:10:40 +08:00
parent c114c7318a
commit bd29800d40
17 changed files with 287 additions and 263 deletions

View File

@ -13,29 +13,30 @@
* limitations under the License.
*/
#include <memory>
#include <string>
#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 <memory>
#include <string>
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<IRemoteObject> DataShareDelegate::remoteObj_ = nullptr;
DataShareDelegate* DataShareDelegate::instance_ = nullptr;
DataShareDelegate& DataShareDelegate::GetInstance()
DataShareDelegate *DataShareDelegate::instance_ = nullptr;
DataShareDelegate &DataShareDelegate::GetInstance()
{
if (instance_ == nullptr) {
std::lock_guard<std::mutex> lock(mutex_);
@ -81,20 +82,20 @@ bool DataShareDelegate::ReleaseDataShareHelper(std::shared_ptr<DataShare::DataSh
return true;
}
int32_t DataShareDelegate::GetValue(const std::string& key, std::string& value)
int32_t DataShareDelegate::GetValue(const std::string &key, std::string &value)
{
auto helper = CreateDataShareHelper();
if (helper == nullptr) {
return static_cast<int32_t>(PasteboardError::CREATE_DATASHARE_SERVICE_ERROR);
}
std::vector<std::string> columns = {SETTING_COLUMN_VALUE};
std::vector<std::string> 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<int32_t>(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<int32_t>(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<AAFwk::IDataAbilityObserver> observer)
int32_t DataShareDelegate::RegisterObserver(const std::string &key, sptr<AAFwk::IDataAbilityObserver> observer)
{
auto uri = MakeUri(key);
auto helper = CreateDataShareHelper();
@ -135,7 +136,7 @@ int32_t DataShareDelegate::RegisterObserver(const std::string& key, sptr<AAFwk::
return ERR_OK;
}
int32_t DataShareDelegate::UnregisterObserver(const std::string& key, sptr<AAFwk::IDataAbilityObserver> observer)
int32_t DataShareDelegate::UnregisterObserver(const std::string &key, sptr<AAFwk::IDataAbilityObserver> observer)
{
auto uri = MakeUri(key);
auto helper = CreateDataShareHelper();

View File

@ -19,16 +19,17 @@
#include <cstdint>
#include <memory>
#include <shared_mutex>
#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<AAFwk::IDataAbilityObserver> observer);
int32_t UnregisterObserver(const std::string& key, sptr<AAFwk::IDataAbilityObserver> observer);
int32_t GetValue(const std::string& key, std::string& value);
static DataShareDelegate &GetInstance();
int32_t RegisterObserver(const std::string &key, sptr<AAFwk::IDataAbilityObserver> observer);
int32_t UnregisterObserver(const std::string &key, sptr<AAFwk::IDataAbilityObserver> 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<DataShare::DataShareHelper> helper);
std::shared_ptr<DataShare::DataShareHelper> 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<IRemoteObject> remoteObj_;
};
} // namespace OHOS::MiscServices

View File

@ -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 <vector>
#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

View File

@ -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();

View File

@ -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::GlobalEvent> ClipPlugin::GetTopEvents(uint32_t topN)
{
@ -73,9 +70,7 @@ std::vector<ClipPlugin::GlobalEvent> ClipPlugin::GetTopEvents(uint32_t topN, int
return std::vector<GlobalEvent>();
}
void ClipPlugin::Clear()
{
}
void ClipPlugin::Clear() {}
int32_t ClipPlugin::PublishServiceState(const std::string &networkId, ServiceStatus status)
{

View File

@ -29,9 +29,7 @@ std::vector<DefaultClip::GlobalEvent> DefaultClip::GetTopEvents(uint32_t topN, i
return std::vector<GlobalEvent>();
}
void DefaultClip::Clear(int32_t user)
{
}
void DefaultClip::Clear(int32_t user) {}
int32_t DefaultClip::PublishServiceState(const std::string &networkId, ServiceStatus status)
{

View File

@ -12,12 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dev_profile.h"
#include <cstring>
#include <thread>
#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<int32_t>(PasteboardError::E_OK) &&
(enabledStatus == ret.second)) {
if (ret.first == static_cast<int32_t>(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<int32_t, std::string> DevProfile::GetEnabledStatus(const std::string &
return std::make_pair(static_cast<int32_t>(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<int32_t>(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<IProfileChangeListener> subscribeDPChangeListener = new(std::nothrow) SubscribeDPChangeListener;
sptr<IProfileChangeListener> 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

View File

@ -12,11 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "distributed_module_config.h"
#include <thread>
#include "dev_profile.h"
#include "distributed_module_config.h"
#include "pasteboard_error.h"
#include "pasteboard_hilog.h"
#include <thread>
namespace OHOS {
namespace MiscServices {
@ -61,15 +62,19 @@ void DistributedModuleConfig::GetRetryTask()
++retry;
status = GetEnabledStatus();
if (status == static_cast<int32_t>(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<int32_t>(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();
});
}

View File

@ -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<FFRTTask>& tasks, FFRTQueue& queue)
void FFRTUtils::SubmitQueueTasks(const std::vector<FFRTTask> &tasks, FFRTQueue &queue)
{
if (tasks.empty()) {
return;
@ -33,7 +33,7 @@ void FFRTUtils::SubmitQueueTasks(const std::vector<FFRTTask>& 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<FFRTQueue> queue)
FFRTHandle FFRTUtils::SubmitDelayTask(FFRTTask &task, uint32_t delayMs, std::shared_ptr<FFRTQueue> 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<void> 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<FFRTQueue> queue)
int FFRTUtils::CancelTask(FFRTHandle &handle, std::shared_ptr<FFRTQueue> 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;
}

View File

@ -140,8 +140,9 @@ public:
}
std::lock_guard<decltype(mutex_)> 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();) {

View File

@ -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<uint8_t> &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<uint8_t> &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<uint8_t> &value, const std::string &name = "");
API_EXPORT static bool SetValue(json &node, const Serializable &value, const std::string &name = "");
template<typename T>
static bool SetValue(
json &node, const std::vector<T> &values, const std::string &name = "")
static bool SetValue(json &node, const std::vector<T> &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;

View File

@ -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);

View File

@ -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<PasteData> ConvertUtils::Convert(const UnifiedData& unifiedData)
std::shared_ptr<PasteData> ConvertUtils::Convert(const UnifiedData &unifiedData)
{
auto pasteData = std::make_shared<PasteData>(Convert(unifiedData.GetRecords()));
pasteData->SetProperty(ConvertProperty(unifiedData.GetProperties(), unifiedData));
return pasteData;
}
std::shared_ptr<UnifiedData> ConvertUtils::Convert(const PasteData& pasteData)
std::shared_ptr<UnifiedData> ConvertUtils::Convert(const PasteData &pasteData)
{
auto unifiedData = std::make_shared<UnifiedData>();
unifiedData->SetRecords(Convert(pasteData.AllRecords()));
@ -40,20 +39,20 @@ std::shared_ptr<UnifiedData> ConvertUtils::Convert(const PasteData& pasteData)
}
std::vector<std::shared_ptr<UnifiedRecord>> ConvertUtils::Convert(
const std::vector<std::shared_ptr<PasteDataRecord>>& records)
const std::vector<std::shared_ptr<PasteDataRecord>> &records)
{
std::vector<std::shared_ptr<UnifiedRecord>> unifiedRecords;
for (auto const& record : records) {
for (auto const &record : records) {
unifiedRecords.emplace_back(Convert(record));
}
return unifiedRecords;
}
std::vector<std::shared_ptr<PasteDataRecord>> ConvertUtils::Convert(
const std::vector<std::shared_ptr<UnifiedRecord>>& records)
const std::vector<std::shared_ptr<UnifiedRecord>> &records)
{
std::vector<std::shared_ptr<PasteDataRecord>> 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<UnifiedRecord> ConvertUtils::Convert(std::shared_ptr<PasteDataRe
PASTEBOARD_HILOGW(PASTEBOARD_MODULE_CLIENT, "entries is nullptr");
auto udmfValue = record->GetUDMFValue();
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<PasteDataRecord> ConvertUtils::Convert(std::shared_ptr<UnifiedRe
std::shared_ptr<PasteDataRecord> pbRecord = std::make_shared<PasteDataRecord>();
auto utdId = record->GetUtdId();
pbRecord->AddEntry(utdId, std::make_shared<PasteDataEntry>(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<PasteDataRecord> ConvertUtils::Convert(std::shared_ptr<UnifiedRe
}
std::vector<std::shared_ptr<PasteDataEntry>> ConvertUtils::Convert(
const std::shared_ptr<std::map<std::string, UDMF::ValueType>>& entries)
const std::shared_ptr<std::map<std::string, UDMF::ValueType>> &entries)
{
std::vector<std::shared_ptr<PasteDataEntry>> 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<PasteDataEntry>(utdId, value));
}
return pbEntries;
}
std::shared_ptr<std::map<std::string, UDMF::ValueType>> ConvertUtils::Convert(
const std::vector<std::shared_ptr<PasteDataEntry>>& entries)
const std::vector<std::shared_ptr<PasteDataEntry>> &entries)
{
std::map<std::string, UDMF::ValueType> udmfEntries;
for (auto const& entry : entries) {
for (auto const &entry : entries) {
if (entry == nullptr) {
continue;
}
@ -139,8 +138,8 @@ std::shared_ptr<std::map<std::string, UDMF::ValueType>> ConvertUtils::Convert(
return std::make_shared<std::map<std::string, UDMF::ValueType>>(udmfEntries);
}
PasteDataProperty ConvertUtils::ConvertProperty(const std::shared_ptr<UnifiedDataProperties>& properties,
const UnifiedData& unifiedData)
PasteDataProperty ConvertUtils::ConvertProperty(
const std::shared_ptr<UnifiedDataProperties> &properties, const UnifiedData &unifiedData)
{
if (!properties) {
return {};
@ -156,7 +155,7 @@ PasteDataProperty ConvertUtils::ConvertProperty(const std::shared_ptr<UnifiedDat
return PasteDataProperty(pasteDataProperty);
}
std::shared_ptr<UnifiedDataProperties> ConvertUtils::ConvertProperty(const PasteDataProperty& properties)
std::shared_ptr<UnifiedDataProperties> ConvertUtils::ConvertProperty(const PasteDataProperty &properties)
{
auto unifiedDataProperties = std::make_shared<UnifiedDataProperties>();
unifiedDataProperties->shareOptions = properties.shareOption == InApp ? UDMF::ShareOptions::IN_APP
@ -168,10 +167,10 @@ std::shared_ptr<UnifiedDataProperties> ConvertUtils::ConvertProperty(const Paste
return unifiedDataProperties;
}
std::vector<std::string> ConvertUtils::Convert(const std::vector<std::string>& utdIds)
std::vector<std::string> ConvertUtils::Convert(const std::vector<std::string> &utdIds)
{
std::vector<std::string> types;
for (const auto& utdId : utdIds) {
for (const auto &utdId : utdIds) {
types.push_back(CommonUtils::Convert2MimeType(utdId));
}
return types;

View File

@ -14,11 +14,10 @@
* limitations under the License.
*/
#include "paste_data.h"
#include <new>
#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<std::shared_ptr<PasteDataRecord>> 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<std::uint8_t> &buffer)
void PasteData::InitDecodeMap()
{
decodeMap_ = {
{TAG_PROPS, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, props_, head);}},
{TAG_RECORDS, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, records_, head);}},
{TAG_DRAGGED_DATA_FLAG, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, isDraggedData_, head);}},
{TAG_LOCAL_PASTE_FLAG, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, isLocalPaste_, head);}},
{TAG_DELAY_DATA_FLAG, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, isDelayData_, head);}},
{TAG_DEVICE_ID, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, deviceId_, head);}},
{TAG_PASTE_ID, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, pasteId_, head);}},
{TAG_DELAY_RECORD_FLAG, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, isDelayRecord_, head);}},
{TAG_DATA_ID, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, dataId_, head);}},
{ TAG_PROPS,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, props_, head);
} },
{ TAG_RECORDS,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, records_, head);
} },
{ TAG_DRAGGED_DATA_FLAG,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, isDraggedData_, head);
} },
{ TAG_LOCAL_PASTE_FLAG,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, isLocalPaste_, head);
} },
{ TAG_DELAY_DATA_FLAG,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, isDelayData_, head);
} },
{ TAG_DEVICE_ID,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, deviceId_, head);
} },
{ TAG_PASTE_ID,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, pasteId_, head);
} },
{ TAG_DELAY_RECORD_FLAG,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, isDelayRecord_, head);
} },
{ TAG_DATA_ID,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, dataId_, head);
} },
};
}
@ -484,8 +502,8 @@ bool PasteData::Decode(const std::vector<std::uint8_t> &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<uint8_t> pasteDataTlv(0);
if (!const_cast<PasteData*>(this)->Encode(pasteDataTlv)) {
if (!const_cast<PasteData *>(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<std::uint8_t> &buffer)
{
bool ret = Write(buffer, TAG_ADDITIONS, ParcelUtil::Parcelable2Raw(&additions));

View File

@ -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<std::string, std::vector<uint8_t>> MineCustomData::GetItemData()
return this->itemData_;
}
void MineCustomData::AddItemData(const std::string& mimeType, const std::vector<uint8_t>& arrayBuffer)
void MineCustomData::AddItemData(const std::string &mimeType, const std::vector<uint8_t> &arrayBuffer)
{
itemData_.emplace(mimeType, arrayBuffer);
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "itemData_.size = %{public}zu", itemData_.size());
}
bool MineCustomData::Encode(std::vector<std::uint8_t>& buffer)
bool MineCustomData::Encode(std::vector<std::uint8_t> &buffer)
{
return Write(buffer, TAG_ITEM_DATA, itemData_);
}
bool MineCustomData::Decode(const std::vector<std::uint8_t>& buffer)
bool MineCustomData::Decode(const std::vector<std::uint8_t> &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<std::uint8_t>& buffer)
bool PasteDataEntry::Encode(std::vector<std::uint8_t> &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<std::uint8_t>& buffer)
return ret;
}
bool PasteDataEntry::Decode(const std::vector<std::uint8_t>& buffer)
bool PasteDataEntry::Decode(const std::vector<std::uint8_t> &buffer)
{
for (; IsEnough();) {
TLVHead head{};
@ -167,13 +166,13 @@ bool PasteDataEntry::Decode(const std::vector<std::uint8_t>& buffer)
return true;
}
bool PasteDataEntry::Marshalling(std::vector<std::uint8_t>& buffer)
bool PasteDataEntry::Marshalling(std::vector<std::uint8_t> &buffer)
{
Init(buffer);
return Encode(buffer);
}
bool PasteDataEntry::Unmarshalling(const std::vector<std::uint8_t>& buffer)
bool PasteDataEntry::Unmarshalling(const std::vector<std::uint8_t> &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>(uDType);

View File

@ -12,14 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "paste_data_record.h"
#include <sys/stat.h>
#include <unistd.h>
#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<OHOS::AAFwk::Want> want)
PasteDataRecord::Builder &PasteDataRecord::Builder::SetWant(std::shared_ptr<OHOS::AAFwk::Want> 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<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, mimeType_, head);}},
{TAG_HTMLTEXT, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, htmlText_, head);}},
{TAG_WANT, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
RawMem rawMem{};
ret = ret && ReadValue(buffer, rawMem, head);
want_ = ParcelUtil::Raw2Parcelable<AAFwk::Want>(rawMem);}},
{TAG_PLAINTEXT, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, plainText_, head); }},
{TAG_URI, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
RawMem rawMem{};
ret = ret && ReadValue(buffer, rawMem, head);
uri_ = ParcelUtil::Raw2Parcelable<OHOS::Uri>(rawMem);}},
{TAG_CONVERT_URI, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, convertUri_, head);}},
{TAG_PIXELMAP, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
std::vector<std::uint8_t> value;
ret = ret && ReadValue(buffer, value, head);
pixelMap_ = Vector2PixelMap(value);}},
{TAG_CUSTOM_DATA, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, customData_, head);}},
{TAG_URI_PERMISSION, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, hasGrantUriPermission_, head);}},
{TAG_UDC_UDTYPE, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, udType_, head);}},
{TAG_UDC_DETAILS, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, details_, head);}},
{TAG_UDC_TEXTCONTENT, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, textContent_, head);}},
{TAG_UDC_SYSTEMCONTENTS, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, systemDefinedContents_, head);}},
{TAG_UDC_UDMFVALUE, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, udmfValue_, head);}},
{TAG_UDC_ENTYIES, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, entries_, head);}},
{TAG_DATA_ID, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, dataId_, head);}},
{TAG_RECORD_ID, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, recordId_, head);}},
{TAG_DELAY_RECORD_FLAG, [&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, isDelay_, head);}},
{ TAG_MIMETYPE,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, mimeType_, head);
} },
{ TAG_HTMLTEXT,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, htmlText_, head);
} },
{ TAG_WANT,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
RawMem rawMem{};
ret = ret && ReadValue(buffer, rawMem, head);
want_ = ParcelUtil::Raw2Parcelable<AAFwk::Want>(rawMem);
} },
{ TAG_PLAINTEXT,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, plainText_, head);
} },
{ TAG_URI,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
RawMem rawMem{};
ret = ret && ReadValue(buffer, rawMem, head);
uri_ = ParcelUtil::Raw2Parcelable<OHOS::Uri>(rawMem);
} },
{ TAG_CONVERT_URI,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, convertUri_, head);
} },
{ TAG_PIXELMAP,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
std::vector<std::uint8_t> value;
ret = ret && ReadValue(buffer, value, head);
pixelMap_ = Vector2PixelMap(value);
} },
{ TAG_CUSTOM_DATA,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, customData_, head);
} },
{ TAG_URI_PERMISSION,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, hasGrantUriPermission_, head);
} },
{ TAG_UDC_UDTYPE,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, udType_, head);
} },
{ TAG_UDC_DETAILS,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, details_, head);
} },
{ TAG_UDC_TEXTCONTENT,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, textContent_, head);
} },
{ TAG_UDC_SYSTEMCONTENTS,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, systemDefinedContents_, head);
} },
{ TAG_UDC_UDMFVALUE,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, udmfValue_, head);
} },
{ TAG_UDC_ENTYIES,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, entries_, head);
} },
{ TAG_DATA_ID,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, dataId_, head);
} },
{ TAG_RECORD_ID,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, recordId_, head);
} },
{ TAG_DELAY_RECORD_FLAG,
[&](bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head) -> void {
ret = ret && ReadValue(buffer, isDelay_, head);
} },
};
}
@ -283,7 +318,7 @@ std::shared_ptr<OHOS::Uri> 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<std::uint8_t> &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>(details);
}
@ -491,7 +526,7 @@ std::shared_ptr<Details> PasteDataRecord::GetDetails() const
return this->details_;
}
void PasteDataRecord::SetSystemDefinedContent(const Details& contents)
void PasteDataRecord::SetSystemDefinedContent(const Details &contents)
{
this->systemDefinedContents_ = std::make_shared<Details>(contents);
}
@ -510,11 +545,11 @@ void PasteDataRecord::SetUDType(int32_t type)
this->udType_ = type;
}
std::vector<std::string> PasteDataRecord::GetValidTypes(const std::vector<std::string>& types) const
std::vector<std::string> PasteDataRecord::GetValidTypes(const std::vector<std::string> &types) const
{
std::vector<std::string> 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<std::monostate>(*udmfValue_)) {
return false;
}
for (auto const& entry : entries_) {
for (auto const &entry : entries_) {
if (!std::holds_alternative<std::monostate>(entry->GetValue())) {
return false;
}
@ -535,7 +570,7 @@ bool PasteDataRecord::IsEmpty() const
return true;
}
void PasteDataRecord::SetUDMFValue(const std::shared_ptr<EntryValue>& udmfValue)
void PasteDataRecord::SetUDMFValue(const std::shared_ptr<EntryValue> &udmfValue)
{
this->udmfValue_ = udmfValue;
}
@ -594,13 +629,13 @@ std::set<std::string> PasteDataRecord::GetUdtTypes() const
{
std::set<std::string> 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<PasteDataEntry> value)
void PasteDataRecord::AddEntry(const std::string &utdType, std::shared_ptr<PasteDataEntry> value)
{
if (!value) {
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "entry is null");
@ -634,7 +669,7 @@ void PasteDataRecord::AddEntry(const std::string& utdType, std::shared_ptr<Paste
}
// not firest entry
bool has = false;
for (auto& entry : entries_) {
for (auto &entry : entries_) {
if (entry->GetUtdId() == utdType) {
entry = value;
has = true;
@ -646,12 +681,12 @@ void PasteDataRecord::AddEntry(const std::string& utdType, std::shared_ptr<Paste
}
}
std::shared_ptr<PasteDataEntry> PasteDataRecord::GetEntry(const std::string& utdType) const
std::shared_ptr<PasteDataEntry> PasteDataRecord::GetEntry(const std::string &utdType) const
{
if (udmfValue_ && CommonUtils::Convert2UtdId(udType_, mimeType_) == utdType) {
return std::make_shared<PasteDataEntry>(utdType, *udmfValue_);
}
for (auto const& entry : entries_) {
for (auto const &entry : entries_) {
if (entry->GetUtdId() == utdType) {
return entry;
}

View File

@ -15,12 +15,12 @@
#include <thread>
#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<std::mutex> lock(connectionLock_);
connection_ = new DialogConnection(nullptr);
int32_t result = IN_PROCESS_CALL(abilityManager->ConnectAbility(want, iface_cast<AAFwk::IAbilityConnection>(
connection_), nullptr));
int32_t result = IN_PROCESS_CALL(
abilityManager->ConnectAbility(want, iface_cast<AAFwk::IAbilityConnection>(connection_), nullptr));
if (result != 0) {
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "start pasteboard toast failed, result:%{public}d", result);
return static_cast<int32_t>(PasteboardError::TASK_PROCESSING);