mirror of
https://gitee.com/openharmony/distributeddatamgr_pasteboard
synced 2024-11-23 07:59:55 +00:00
commit
8193ef6dcd
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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();
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
@ -13,9 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "device/dm_adapter.h"
|
||||
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "pasteboard_error.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
#ifdef PB_DEVICE_MANAGER_ENABLE
|
||||
#include "device_manager.h"
|
||||
#include "device_manager_callback.h"
|
||||
@ -30,7 +29,7 @@ public:
|
||||
DmStateObserver(const std::function<void(const DmDeviceInfo &)> online,
|
||||
const std::function<void(const DmDeviceInfo &)> onReady,
|
||||
const std::function<void(const DmDeviceInfo &)> offline)
|
||||
:online_(std::move(online)), onReady_(std::move(onReady)), offline_(std::move(offline))
|
||||
: online_(std::move(online)), onReady_(std::move(onReady)), offline_(std::move(offline))
|
||||
{
|
||||
}
|
||||
|
||||
@ -45,7 +44,7 @@ public:
|
||||
|
||||
void OnDeviceOffline(const DmDeviceInfo &deviceInfo) override
|
||||
{
|
||||
if (offline_ == nullptr) {
|
||||
if (offline_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
offline_(deviceInfo);
|
||||
@ -93,13 +92,9 @@ private:
|
||||
};
|
||||
#endif
|
||||
|
||||
DMAdapter::DMAdapter()
|
||||
{
|
||||
}
|
||||
DMAdapter::DMAdapter() {}
|
||||
|
||||
DMAdapter::~DMAdapter()
|
||||
{
|
||||
}
|
||||
DMAdapter::~DMAdapter() {}
|
||||
|
||||
DMAdapter &DMAdapter::GetInstance()
|
||||
{
|
||||
@ -110,24 +105,27 @@ DMAdapter &DMAdapter::GetInstance()
|
||||
bool DMAdapter::Initialize(const std::string &pkgName)
|
||||
{
|
||||
#ifdef PB_DEVICE_MANAGER_ENABLE
|
||||
auto stateObserver = std::make_shared<DmStateObserver>([this](const DmDeviceInfo &deviceInfo) {
|
||||
observers_.ForEachCopies([&deviceInfo](auto &key, auto &value) {
|
||||
DMAdapter::GetInstance().SetDevices();
|
||||
value->Online(deviceInfo.networkId);
|
||||
return false;
|
||||
auto stateObserver = std::make_shared<DmStateObserver>(
|
||||
[this](const DmDeviceInfo &deviceInfo) {
|
||||
observers_.ForEachCopies([&deviceInfo](auto &key, auto &value) {
|
||||
DMAdapter::GetInstance().SetDevices();
|
||||
value->Online(deviceInfo.networkId);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
[this](const DmDeviceInfo &deviceInfo) {
|
||||
observers_.ForEachCopies([&deviceInfo](auto &key, auto &value) {
|
||||
value->OnReady(deviceInfo.networkId);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
[this](const DmDeviceInfo &deviceInfo) {
|
||||
observers_.ForEachCopies([&deviceInfo](auto &key, auto &value) {
|
||||
DMAdapter::GetInstance().SetDevices();
|
||||
value->Offline(deviceInfo.networkId);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}, [this](const DmDeviceInfo &deviceInfo) {
|
||||
observers_.ForEachCopies([&deviceInfo](auto &key, auto &value) {
|
||||
value->OnReady(deviceInfo.networkId);
|
||||
return false;
|
||||
});
|
||||
}, [this](const DmDeviceInfo &deviceInfo) {
|
||||
observers_.ForEachCopies([&deviceInfo](auto &key, auto &value) {
|
||||
DMAdapter::GetInstance().SetDevices();
|
||||
value->Offline(deviceInfo.networkId);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
pkgName_ = pkgName + NAME_EX;
|
||||
auto deathObserver = std::make_shared<DmDeath>(stateObserver, pkgName_);
|
||||
deathObserver->OnRemoteDied();
|
||||
@ -138,7 +136,7 @@ bool DMAdapter::Initialize(const std::string &pkgName)
|
||||
|
||||
void DMAdapter::DeInitialize()
|
||||
{
|
||||
auto& deviceManager = DeviceManager::GetInstance();
|
||||
auto &deviceManager = DeviceManager::GetInstance();
|
||||
deviceManager.UnRegisterDevStateCallback(pkgName_);
|
||||
deviceManager.UnInitDeviceManager(pkgName_);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ bool PasteboardStaticCapability::IsSupportCapability()
|
||||
return true;
|
||||
}
|
||||
|
||||
DistributedDeviceProfile::IStaticCapabilityCollector* GetStaticCapabilityCollector()
|
||||
DistributedDeviceProfile::IStaticCapabilityCollector *GetStaticCapabilityCollector()
|
||||
{
|
||||
return &PasteboardStaticCapability::GetInstance();
|
||||
}
|
||||
|
@ -15,12 +15,8 @@
|
||||
|
||||
#include "eventcenter/event.h"
|
||||
namespace OHOS::MiscServices {
|
||||
Event::Event(int32_t evtId) : evtId_(evtId)
|
||||
{
|
||||
}
|
||||
Event::~Event()
|
||||
{
|
||||
}
|
||||
Event::Event(int32_t evtId) : evtId_(evtId) {}
|
||||
Event::~Event() {}
|
||||
int32_t Event::GetEventId() const
|
||||
{
|
||||
return evtId_;
|
||||
|
@ -16,8 +16,7 @@
|
||||
#include "eventcenter/pasteboard_event.h"
|
||||
namespace OHOS::MiscServices {
|
||||
|
||||
PasteboardEvent::PasteboardEvent(int32_t evtId, std::string networkId)
|
||||
: Event(evtId), networkId_(std::move(networkId))
|
||||
PasteboardEvent::PasteboardEvent(int32_t evtId, std::string networkId) : Event(evtId), networkId_(std::move(networkId))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
std::string account;
|
||||
std::vector<std::string> dataType;
|
||||
int32_t syncTime = 0;
|
||||
bool operator == (const GlobalEvent globalEvent)
|
||||
bool operator==(const GlobalEvent globalEvent)
|
||||
{
|
||||
return globalEvent.seqId == this->seqId && globalEvent.deviceId == this->deviceId;
|
||||
}
|
||||
|
@ -20,9 +20,7 @@ namespace OHOS {
|
||||
template<typename T>
|
||||
class BlockObject {
|
||||
public:
|
||||
explicit BlockObject(uint32_t interval, const T &invalid = T()) : interval_(interval), data_(invalid)
|
||||
{
|
||||
}
|
||||
explicit BlockObject(uint32_t interval, const T &invalid = T()) : interval_(interval), data_(invalid) {}
|
||||
~BlockObject() = default;
|
||||
|
||||
void SetValue(T data)
|
||||
@ -36,7 +34,9 @@ public:
|
||||
T GetValue()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
cv_.wait_for(lock, std::chrono::milliseconds(interval_), [this]() { return isSet_; });
|
||||
cv_.wait_for(lock, std::chrono::milliseconds(interval_), [this]() {
|
||||
return isSet_;
|
||||
});
|
||||
isSet_ = false;
|
||||
T data = std::move(data_);
|
||||
cv_.notify_one();
|
||||
|
@ -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();) {
|
||||
|
@ -16,10 +16,10 @@
|
||||
#ifndef OHOS_DISTRIBUTED_DATA_PASTEBOARD_FRAMEWORK_COMMON_CONSTANT_H
|
||||
#define OHOS_DISTRIBUTED_DATA_PASTEBOARD_FRAMEWORK_COMMON_CONSTANT_H
|
||||
namespace OHOS::MiscServices {
|
||||
static constexpr const char *MIMETYPE_PIXELMAP = "pixelMap";
|
||||
static constexpr const char *MIMETYPE_TEXT_HTML = "text/html";
|
||||
static constexpr const char *MIMETYPE_TEXT_PLAIN = "text/plain";
|
||||
static constexpr const char *MIMETYPE_TEXT_URI = "text/uri";
|
||||
static constexpr const char *MIMETYPE_TEXT_WANT = "text/want";
|
||||
static constexpr const char *MIMETYPE_PIXELMAP = "pixelMap";
|
||||
static constexpr const char *MIMETYPE_TEXT_HTML = "text/html";
|
||||
static constexpr const char *MIMETYPE_TEXT_PLAIN = "text/plain";
|
||||
static constexpr const char *MIMETYPE_TEXT_URI = "text/uri";
|
||||
static constexpr const char *MIMETYPE_TEXT_WANT = "text/want";
|
||||
} // namespace OHOS::MiscServices
|
||||
#endif // OHOS_DISTRIBUTED_DATA_PASTEBOARD_FRAMEWORK_COMMON_CONSTANT_H
|
@ -16,8 +16,9 @@
|
||||
#ifndef PASTE_BOARD_DEV_PROFILE_H
|
||||
#define PASTE_BOARD_DEV_PROFILE_H
|
||||
|
||||
#include "api/visibility.h"
|
||||
#include <functional>
|
||||
|
||||
#include "api/visibility.h"
|
||||
#ifdef PB_DEVICE_INFO_MANAGER_ENABLE
|
||||
#include "distributed_device_profile_client.h"
|
||||
#include "profile_change_listener_stub.h"
|
||||
@ -39,7 +40,7 @@ public:
|
||||
void Watch(Observer observer);
|
||||
static constexpr const uint32_t FIRST_VERSION = 4;
|
||||
|
||||
#ifdef PB_DEVICE_INFO_MANAGER_ENABLE
|
||||
#ifdef PB_DEVICE_INFO_MANAGER_ENABLE
|
||||
class SubscribeDPChangeListener : public DistributedDeviceProfile::ProfileChangeListenerStub {
|
||||
public:
|
||||
SubscribeDPChangeListener();
|
||||
@ -61,7 +62,7 @@ public:
|
||||
int32_t OnCharacteristicProfileUpdate(const DistributedDeviceProfile::CharacteristicProfile &oldProfile,
|
||||
const DistributedDeviceProfile::CharacteristicProfile &newProfile) override;
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
private:
|
||||
DevProfile();
|
||||
@ -69,10 +70,9 @@ private:
|
||||
void Notify(bool isEnable);
|
||||
std::mutex callbackMutex_;
|
||||
Observer observer_ = nullptr;
|
||||
#ifdef PB_DEVICE_INFO_MANAGER_ENABLE
|
||||
#ifdef PB_DEVICE_INFO_MANAGER_ENABLE
|
||||
std::map<std::string, DistributedDeviceProfile::SubscribeInfo> subscribeInfoCache_;
|
||||
#endif // PB_DEVICE_INFO_MANAGER_ENABLE
|
||||
|
||||
#endif // PB_DEVICE_INFO_MANAGER_ENABLE
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -16,9 +16,10 @@
|
||||
#ifndef PASTE_BOARD_DISTRIBUTE_MODULE_CONFIG_H
|
||||
#define PASTE_BOARD_DISTRIBUTE_MODULE_CONFIG_H
|
||||
|
||||
#include "api/visibility.h"
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
|
||||
#include "api/visibility.h"
|
||||
#include "device/dm_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -30,10 +31,12 @@ public:
|
||||
void Watch(Observer observer);
|
||||
void Init();
|
||||
void DeInit();
|
||||
|
||||
protected:
|
||||
void Online(const std::string &device) override;
|
||||
void Offline(const std::string &device) override;
|
||||
void OnReady(const std::string &device) override;
|
||||
|
||||
private:
|
||||
int32_t GetEnabledStatus();
|
||||
void Notify();
|
||||
@ -44,9 +47,9 @@ private:
|
||||
std::atomic<bool> retrying_ = false;
|
||||
static constexpr uint32_t RETRY_TIMES = 30;
|
||||
static constexpr uint32_t RETRY_INTERVAL = 1000; //milliseconds
|
||||
static constexpr uint32_t RANDOM_MAX = 500; //milliseconds
|
||||
static constexpr uint32_t RANDOM_MIN = 5; //milliseconds
|
||||
static constexpr const char* SUPPORT_STATUS = "1";
|
||||
static constexpr uint32_t RANDOM_MAX = 500; //milliseconds
|
||||
static constexpr uint32_t RANDOM_MIN = 5; //milliseconds
|
||||
static constexpr const char *SUPPORT_STATUS = "1";
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -49,10 +49,10 @@ public:
|
||||
bool IsSameAccount(const std::string &networkId);
|
||||
void SetDevices();
|
||||
|
||||
#ifdef PB_DEVICE_MANAGER_ENABLE
|
||||
#ifdef PB_DEVICE_MANAGER_ENABLE
|
||||
int32_t GetRemoteDeviceInfo(const std::string &networkId, DmDeviceInfo &remoteDevice);
|
||||
std::vector<DmDeviceInfo> GetDevices();
|
||||
#endif
|
||||
#endif
|
||||
std::string GetDeviceName(const std::string &networkId);
|
||||
void Register(DMObserver *observer);
|
||||
void Unregister(DMObserver *observer);
|
||||
@ -70,10 +70,10 @@ private:
|
||||
mutable std::mutex mutex_{};
|
||||
std::string localDeviceUdid_{};
|
||||
ConcurrentMap<DMObserver *, DMObserver *> observers_;
|
||||
#ifdef PB_DEVICE_MANAGER_ENABLE
|
||||
#ifdef PB_DEVICE_MANAGER_ENABLE
|
||||
std::shared_mutex dmMutex_;
|
||||
std::vector<DmDeviceInfo> devices_;
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
} // namespace OHOS::MiscServices
|
||||
#endif // OHOS_PASTEBOARD_SERVICES_DEVICE_DM_ADAPTER_H
|
||||
|
@ -29,7 +29,8 @@ namespace OHOS {
|
||||
namespace MiscServices {
|
||||
#ifdef PB_DEVICE_INFO_MANAGER_ENABLE
|
||||
class PasteboardStaticCapability : public DistributedDeviceProfile::IStaticCapabilityCollector {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(PasteboardStaticCapability);
|
||||
DECLARE_SINGLE_INSTANCE_BASE(PasteboardStaticCapability);
|
||||
|
||||
public:
|
||||
PasteboardStaticCapability() = default;
|
||||
~PasteboardStaticCapability() = default;
|
||||
@ -39,7 +40,7 @@ public:
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
API_EXPORT DistributedDeviceProfile::IStaticCapabilityCollector* GetStaticCapabilityCollector();
|
||||
API_EXPORT DistributedDeviceProfile::IStaticCapabilityCollector *GetStaticCapabilityCollector();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -16,8 +16,9 @@
|
||||
#ifndef OHOS_DISTRIBUTED_DATA_PASTEBOARD_SERVICES_FRAMEWORK_EVENTCENTER_EVENT_H
|
||||
#define OHOS_DISTRIBUTED_DATA_PASTEBOARD_SERVICES_FRAMEWORK_EVENTCENTER_EVENT_H
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "api/visibility.h"
|
||||
namespace OHOS::MiscServices {
|
||||
class Event {
|
||||
|
@ -16,11 +16,12 @@
|
||||
#ifndef OHOS_DISTRIBUTED_DATA_PASTEBOARD_SERVICES_FRAMEWORK_EVENTCENTER_EVENT_CENTER_H
|
||||
#define OHOS_DISTRIBUTED_DATA_PASTEBOARD_SERVICES_FRAMEWORK_EVENTCENTER_EVENT_CENTER_H
|
||||
#include <list>
|
||||
#include <queue>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
|
||||
#include "api/visibility.h"
|
||||
#include "common/concurrent_map.h"
|
||||
#include "eventcenter/event.h"
|
||||
#include "api/visibility.h"
|
||||
namespace OHOS::MiscServices {
|
||||
class EventCenter {
|
||||
public:
|
||||
@ -34,15 +35,16 @@ public:
|
||||
public:
|
||||
API_EXPORT Defer(std::function<void(const Event &)> handler = nullptr, int32_t evtId = Event::EVT_INVALID);
|
||||
API_EXPORT ~Defer();
|
||||
void *operator new (size_t size) = delete;
|
||||
void *operator new[] (size_t size) = delete;
|
||||
void operator delete (void *) = delete;
|
||||
void operator delete[] (void *) = delete;
|
||||
void *operator new(size_t size) = delete;
|
||||
void *operator new[](size_t size) = delete;
|
||||
void operator delete(void *) = delete;
|
||||
void operator delete[](void *) = delete;
|
||||
};
|
||||
API_EXPORT static EventCenter &GetInstance();
|
||||
API_EXPORT bool Subscribe(int32_t evtId, const std::function<void(const Event &)> &observer);
|
||||
API_EXPORT bool Unsubscribe(int32_t evtId);
|
||||
API_EXPORT int32_t PostEvent(std::unique_ptr<Event> evt) const;
|
||||
|
||||
private:
|
||||
void Dispatch(const Event &evt) const;
|
||||
class AsyncQueue final {
|
||||
@ -53,6 +55,7 @@ private:
|
||||
bool operator<=(int32_t depth) const;
|
||||
void Post(std::unique_ptr<Event> event);
|
||||
void AddHandler(int32_t evtId, std::function<void(const Event &)> handler);
|
||||
|
||||
private:
|
||||
std::map<int32_t, std::function<void(const Event &)>> handlers_;
|
||||
std::deque<std::unique_ptr<Event>> events_;
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define OHOS_DISTRIBUTED_DATA_PASTEBOARD_SERVICES_FRAMEWORK_EVENTCENTER_DISTRIBUTED_PASTEBOARD_EVENT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "eventcenter/event.h"
|
||||
namespace OHOS::MiscServices {
|
||||
class API_EXPORT PasteboardEvent : public Event {
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "api/visibility.h"
|
||||
#include "ffrt_inner.h"
|
||||
|
||||
@ -45,75 +46,75 @@ using FFRTMutex = ffrt::mutex;
|
||||
class API_EXPORT FFRTUtils final {
|
||||
public:
|
||||
/**
|
||||
* Submit an FFRT atomization task without blocking the current thread.
|
||||
*
|
||||
* @param task FFRT task.
|
||||
*/
|
||||
static void SubmitTask(const FFRTTask& task);
|
||||
* Submit an FFRT atomization task without blocking the current thread.
|
||||
*
|
||||
* @param task FFRT task.
|
||||
*/
|
||||
static void SubmitTask(const FFRTTask &task);
|
||||
|
||||
/**
|
||||
* Submit an FFRT serial task without blocking the current thread.
|
||||
*
|
||||
* @param task FFRT task.
|
||||
*/
|
||||
static void SubmitQueueTasks(const std::vector<FFRTTask>& tasks, FFRTQueue& queue);
|
||||
* Submit an FFRT serial task without blocking the current thread.
|
||||
*
|
||||
* @param task FFRT task.
|
||||
*/
|
||||
static void SubmitQueueTasks(const std::vector<FFRTTask> &tasks, FFRTQueue &queue);
|
||||
|
||||
/**
|
||||
* Submit the FFRT delayed task without blocking the current thread.
|
||||
* <p>
|
||||
* When the delay time is reached, the task starts to be executed.
|
||||
*
|
||||
* @param task FFRT task.
|
||||
* @param delayMs Delay time, in milliseconds.
|
||||
* @param queue FFRT task execution queue.
|
||||
*
|
||||
* @return FFRT task handle.
|
||||
*/
|
||||
static FFRTHandle SubmitDelayTask(FFRTTask& task, uint32_t delayMs, FFRTQueue& queue);
|
||||
* Submit the FFRT delayed task without blocking the current thread.
|
||||
* <p>
|
||||
* When the delay time is reached, the task starts to be executed.
|
||||
*
|
||||
* @param task FFRT task.
|
||||
* @param delayMs Delay time, in milliseconds.
|
||||
* @param queue FFRT task execution queue.
|
||||
*
|
||||
* @return FFRT task handle.
|
||||
*/
|
||||
static FFRTHandle SubmitDelayTask(FFRTTask &task, uint32_t delayMs, FFRTQueue &queue);
|
||||
|
||||
/**
|
||||
* Submit the FFRT delayed task without blocking the current thread.
|
||||
* <p>
|
||||
* When the delay time is reached, the task starts to be executed.
|
||||
*
|
||||
* @param task FFRT task.
|
||||
* @param delayMs Delay time, in milliseconds.
|
||||
* @param queue Shared_ptr of FFRT task execution queue.
|
||||
*
|
||||
* @return FFRT task handle.
|
||||
*/
|
||||
static FFRTHandle SubmitDelayTask(FFRTTask& task, uint32_t delayMs, std::shared_ptr<FFRTQueue> queue);
|
||||
* Submit the FFRT delayed task without blocking the current thread.
|
||||
* <p>
|
||||
* When the delay time is reached, the task starts to be executed.
|
||||
*
|
||||
* @param task FFRT task.
|
||||
* @param delayMs Delay time, in milliseconds.
|
||||
* @param queue Shared_ptr of FFRT task execution queue.
|
||||
*
|
||||
* @return FFRT task handle.
|
||||
*/
|
||||
static FFRTHandle SubmitDelayTask(FFRTTask &task, uint32_t delayMs, std::shared_ptr<FFRTQueue> queue);
|
||||
|
||||
/**
|
||||
* Submit an FFRT timeout task without blocking the current thread.
|
||||
* <p>
|
||||
* When the timeout period is reached, the task will be canceled.
|
||||
*
|
||||
* @param task FFRT task.
|
||||
* @param timeoutMs Timeout interval, in milliseconds.
|
||||
*
|
||||
* @return true: The task is executed successfully. false: The task execution times out.
|
||||
*/
|
||||
static bool SubmitTimeoutTask(const FFRTTask& task, uint32_t timeoutMs);
|
||||
* Submit an FFRT timeout task without blocking the current thread.
|
||||
* <p>
|
||||
* When the timeout period is reached, the task will be canceled.
|
||||
*
|
||||
* @param task FFRT task.
|
||||
* @param timeoutMs Timeout interval, in milliseconds.
|
||||
*
|
||||
* @return true: The task is executed successfully. false: The task execution times out.
|
||||
*/
|
||||
static bool SubmitTimeoutTask(const FFRTTask &task, uint32_t timeoutMs);
|
||||
|
||||
/**
|
||||
* Cancel the FFRT task.
|
||||
* <p>
|
||||
* You cannot cancel a completed task.
|
||||
*
|
||||
* @param handle FFRT task.
|
||||
*/
|
||||
static int CancelTask(FFRTHandle& handle, FFRTQueue& queue);
|
||||
* Cancel the FFRT task.
|
||||
* <p>
|
||||
* You cannot cancel a completed task.
|
||||
*
|
||||
* @param handle FFRT task.
|
||||
*/
|
||||
static int CancelTask(FFRTHandle &handle, FFRTQueue &queue);
|
||||
|
||||
/**
|
||||
* Cancel the FFRT task.
|
||||
* <p>
|
||||
* You cannot cancel a completed task.
|
||||
*
|
||||
* @param handle FFRT task.
|
||||
* @param queue Shared_ptr of FFRT task cancel queue.
|
||||
*/
|
||||
static int CancelTask(FFRTHandle& handle, std::shared_ptr<FFRTQueue> queue);
|
||||
* Cancel the FFRT task.
|
||||
* <p>
|
||||
* You cannot cancel a completed task.
|
||||
*
|
||||
* @param handle FFRT task.
|
||||
* @param queue Shared_ptr of FFRT task cancel queue.
|
||||
*/
|
||||
static int CancelTask(FFRTHandle &handle, std::shared_ptr<FFRTQueue> queue);
|
||||
};
|
||||
|
||||
class API_EXPORT FFRTTimer {
|
||||
@ -124,9 +125,10 @@ public:
|
||||
void Clear();
|
||||
void CancelAllTimer();
|
||||
void CancelTimer(const std::string &timerId);
|
||||
void SetTimer(const std::string &timerId, FFRTTask& task);
|
||||
void SetTimer(const std::string &timerId, FFRTTask& task, uint32_t delayMs);
|
||||
void SetTimer(const std::string &timerId, FFRTTask &task);
|
||||
void SetTimer(const std::string &timerId, FFRTTask &task, uint32_t delayMs);
|
||||
uint32_t GetTaskId(const std::string &timerId);
|
||||
|
||||
private:
|
||||
/* inner functions must be called when mutex_ is locked */
|
||||
void CancelAllTimerInner();
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -12,9 +12,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "device/dm_adapter.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "device/dm_adapter.h"
|
||||
namespace OHOS::MiscServices {
|
||||
using namespace testing::ext;
|
||||
|
||||
@ -26,21 +26,13 @@ public:
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void DMAdapterTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
void DMAdapterTest::SetUpTestCase(void) {}
|
||||
|
||||
void DMAdapterTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
void DMAdapterTest::TearDownTestCase(void) {}
|
||||
|
||||
void DMAdapterTest::SetUp(void)
|
||||
{
|
||||
}
|
||||
void DMAdapterTest::SetUp(void) {}
|
||||
|
||||
void DMAdapterTest::TearDown(void)
|
||||
{
|
||||
}
|
||||
void DMAdapterTest::TearDown(void) {}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLocalDeviceUdid
|
||||
@ -52,4 +44,4 @@ HWTEST_F(DMAdapterTest, GetLocalDeviceUdid, TestSize.Level0)
|
||||
auto &udid = DMAdapter::GetInstance().GetLocalDeviceUdid();
|
||||
ASSERT_FALSE(udid.empty());
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::MiscServices
|
||||
|
@ -27,27 +27,27 @@ public:
|
||||
using UnifiedDataProperties = UDMF::UnifiedDataProperties;
|
||||
using UDType = UDMF::UDType;
|
||||
|
||||
static std::shared_ptr<PasteData> Convert(const UnifiedData& unifiedData);
|
||||
static std::shared_ptr<UnifiedData> Convert(const PasteData& pasteData);
|
||||
static std::shared_ptr<PasteData> Convert(const UnifiedData &unifiedData);
|
||||
static std::shared_ptr<UnifiedData> Convert(const PasteData &pasteData);
|
||||
|
||||
static std::vector<std::shared_ptr<PasteDataRecord>> Convert(
|
||||
const std::vector<std::shared_ptr<UnifiedRecord>>& records);
|
||||
const std::vector<std::shared_ptr<UnifiedRecord>> &records);
|
||||
static std::vector<std::shared_ptr<UnifiedRecord>> Convert(
|
||||
const std::vector<std::shared_ptr<PasteDataRecord>>& records);
|
||||
const std::vector<std::shared_ptr<PasteDataRecord>> &records);
|
||||
|
||||
static std::shared_ptr<PasteDataRecord> Convert(std::shared_ptr<UnifiedRecord> record);
|
||||
static std::shared_ptr<UnifiedRecord> Convert(std::shared_ptr<PasteDataRecord> record);
|
||||
|
||||
static PasteDataProperty ConvertProperty(const std::shared_ptr<UnifiedDataProperties>& properties,
|
||||
const UnifiedData& unifiedData);
|
||||
static std::shared_ptr<UnifiedDataProperties> ConvertProperty(const PasteDataProperty& properties);
|
||||
static PasteDataProperty ConvertProperty(
|
||||
const std::shared_ptr<UnifiedDataProperties> &properties, const UnifiedData &unifiedData);
|
||||
static std::shared_ptr<UnifiedDataProperties> ConvertProperty(const PasteDataProperty &properties);
|
||||
|
||||
static std::vector<std::shared_ptr<PasteDataEntry>> Convert(
|
||||
const std::shared_ptr<std::map<std::string, UDMF::ValueType>>& entries);
|
||||
const std::shared_ptr<std::map<std::string, UDMF::ValueType>> &entries);
|
||||
static std::shared_ptr<std::map<std::string, UDMF::ValueType>> Convert(
|
||||
const std::vector<std::shared_ptr<PasteDataEntry>>& entries);
|
||||
const std::vector<std::shared_ptr<PasteDataEntry>> &entries);
|
||||
|
||||
static std::vector<std::string> Convert(const std::vector<std::string>& utdIds);
|
||||
static std::vector<std::string> Convert(const std::vector<std::string> &utdIds);
|
||||
|
||||
private:
|
||||
static constexpr const char *CHANNEL_NAME = "pasteboard";
|
||||
|
@ -22,13 +22,13 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "parcel.h"
|
||||
#include "paste_data_record.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "tlv_object.h"
|
||||
#include "uri.h"
|
||||
#include "want.h"
|
||||
#include "want_params.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -38,7 +38,7 @@ struct API_EXPORT PasteDataProperty : public TLVObject {
|
||||
PasteDataProperty() = default;
|
||||
~PasteDataProperty();
|
||||
explicit PasteDataProperty(const PasteDataProperty &property);
|
||||
PasteDataProperty& operator=(const PasteDataProperty &property);
|
||||
PasteDataProperty &operator=(const PasteDataProperty &property);
|
||||
AAFwk::WantParams additions;
|
||||
std::vector<std::string> mimeTypes;
|
||||
std::string tag;
|
||||
@ -63,7 +63,7 @@ public:
|
||||
PasteData();
|
||||
~PasteData();
|
||||
PasteData(const PasteData &data);
|
||||
PasteData& operator=(const PasteData &data);
|
||||
PasteData &operator=(const PasteData &data);
|
||||
explicit PasteData(std::vector<std::shared_ptr<PasteDataRecord>> records);
|
||||
|
||||
void AddHtmlRecord(const std::string &html);
|
||||
@ -132,7 +132,7 @@ public:
|
||||
void SetDataId(uint32_t dataId);
|
||||
uint32_t GetDataId() const;
|
||||
bool Marshalling(Parcel &parcel) const override;
|
||||
static PasteData* Unmarshalling(Parcel &parcel);
|
||||
static PasteData *Unmarshalling(Parcel &parcel);
|
||||
void SetPasteId(const std::string &pasteId);
|
||||
std::string GetPasteId() const;
|
||||
std::string GetDeviceId() const;
|
||||
@ -168,7 +168,6 @@ private:
|
||||
using Func = std::function<void(bool &ret, const std::vector<std::uint8_t> &buffer, TLVHead &head)>;
|
||||
std::map<uint16_t, Func> decodeMap_;
|
||||
void InitDecodeMap();
|
||||
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -25,9 +25,9 @@ class API_EXPORT MineCustomData : public TLVObject {
|
||||
public:
|
||||
MineCustomData() = default;
|
||||
std::map<std::string, std::vector<uint8_t>> GetItemData();
|
||||
void AddItemData(const std::string& mimeType, const std::vector<uint8_t>& arrayBuffer);
|
||||
bool Encode(std::vector<std::uint8_t>& buffer) override;
|
||||
bool Decode(const std::vector<std::uint8_t>& buffer) override;
|
||||
void AddItemData(const std::string &mimeType, const std::vector<uint8_t> &arrayBuffer);
|
||||
bool Encode(std::vector<std::uint8_t> &buffer) override;
|
||||
bool Decode(const std::vector<std::uint8_t> &buffer) override;
|
||||
size_t Count() override;
|
||||
|
||||
private:
|
||||
@ -38,10 +38,10 @@ class API_EXPORT PasteDataEntry : public TLVObject {
|
||||
public:
|
||||
using UDType = UDMF::UDType;
|
||||
PasteDataEntry() = default;
|
||||
PasteDataEntry(const PasteDataEntry& entry);
|
||||
PasteDataEntry& operator=(const PasteDataEntry& entry);
|
||||
PasteDataEntry(const std::string& utdId, const EntryValue& value);
|
||||
PasteDataEntry(const std::string& utdId, const std::string& mimeType, const EntryValue& value);
|
||||
PasteDataEntry(const PasteDataEntry &entry);
|
||||
PasteDataEntry &operator=(const PasteDataEntry &entry);
|
||||
PasteDataEntry(const std::string &utdId, const EntryValue &value);
|
||||
PasteDataEntry(const std::string &utdId, const std::string &mimeType, const EntryValue &value);
|
||||
|
||||
std::shared_ptr<std::string> ConvertToPlianText() const;
|
||||
std::shared_ptr<std::string> ConvertToHtml() const;
|
||||
@ -50,18 +50,19 @@ public:
|
||||
std::shared_ptr<Media::PixelMap> ConvertToPixelMap() const;
|
||||
std::shared_ptr<MineCustomData> ConvertToCustomData() const;
|
||||
|
||||
void SetValue(const EntryValue& value);
|
||||
void SetValue(const EntryValue &value);
|
||||
EntryValue GetValue() const;
|
||||
void SetUtdId(const std::string& utdId);
|
||||
void SetUtdId(const std::string &utdId);
|
||||
std::string GetUtdId() const;
|
||||
void SetMimeType(const std::string& mimeType);
|
||||
void SetMimeType(const std::string &mimeType);
|
||||
std::string GetMimeType() const;
|
||||
bool Encode(std::vector<std::uint8_t>& buffer) override;
|
||||
bool Decode(const std::vector<std::uint8_t>& buffer) override;
|
||||
bool Encode(std::vector<std::uint8_t> &buffer) override;
|
||||
bool Decode(const std::vector<std::uint8_t> &buffer) override;
|
||||
size_t Count() override;
|
||||
|
||||
bool Marshalling(std::vector<std::uint8_t>& buffer);
|
||||
bool Unmarshalling(const std::vector<std::uint8_t>& buffer);
|
||||
bool Marshalling(std::vector<std::uint8_t> &buffer);
|
||||
bool Unmarshalling(const std::vector<std::uint8_t> &buffer);
|
||||
|
||||
private:
|
||||
std::string utdId_;
|
||||
std::string mimeType_; // pasteboard mimeType
|
||||
@ -72,9 +73,9 @@ class API_EXPORT CommonUtils {
|
||||
public:
|
||||
using UDType = UDMF::UDType;
|
||||
static std::string Convert(UDType uDType);
|
||||
static std::string Convert2MimeType(const std::string& utdId);
|
||||
static UDType Convert(int32_t uDType, const std::string& mimeType);
|
||||
static std::string Convert2UtdId(int32_t uDType, const std::string& mimeType);
|
||||
static std::string Convert2MimeType(const std::string &utdId);
|
||||
static UDType Convert(int32_t uDType, const std::string &mimeType);
|
||||
static std::string Convert2UtdId(int32_t uDType, const std::string &mimeType);
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -86,22 +86,22 @@ public:
|
||||
void SetGrantUriPermission(bool hasPermission);
|
||||
bool HasGrantUriPermission();
|
||||
|
||||
void SetTextContent(const std::string& content);
|
||||
void SetTextContent(const std::string &content);
|
||||
std::string GetTextContent() const;
|
||||
void SetDetails(const Details& details);
|
||||
void SetDetails(const Details &details);
|
||||
std::shared_ptr<Details> GetDetails() const;
|
||||
void SetSystemDefinedContent(const Details& contents);
|
||||
void SetSystemDefinedContent(const Details &contents);
|
||||
std::shared_ptr<Details> GetSystemDefinedContent() const;
|
||||
int32_t GetUDType() const;
|
||||
void SetUDType(int32_t type);
|
||||
|
||||
bool IsEmpty() const;
|
||||
void SetUDMFValue(const std::shared_ptr<EntryValue>& udmfValue);
|
||||
void SetUDMFValue(const std::shared_ptr<EntryValue> &udmfValue);
|
||||
std::shared_ptr<EntryValue> GetUDMFValue();
|
||||
void AddEntry(const std::string& utdType, std::shared_ptr<PasteDataEntry> value);
|
||||
std::shared_ptr<PasteDataEntry> GetEntry(const std::string& utdType) const;
|
||||
void AddEntry(const std::string &utdType, std::shared_ptr<PasteDataEntry> value);
|
||||
std::shared_ptr<PasteDataEntry> GetEntry(const std::string &utdType) const;
|
||||
std::vector<std::shared_ptr<PasteDataEntry>> GetEntries() const;
|
||||
std::vector<std::string> GetValidTypes(const std::vector<std::string>& types) const;
|
||||
std::vector<std::string> GetValidTypes(const std::vector<std::string> &types) const;
|
||||
|
||||
void SetDelayRecordFlag(bool isDelay);
|
||||
bool IsDelayRecord() const;
|
||||
|
@ -16,9 +16,10 @@
|
||||
#ifndef PASTE_BOARD_CLIENT_H
|
||||
#define PASTE_BOARD_CLIENT_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <singleton.h>
|
||||
#include <condition_variable>
|
||||
|
||||
#include "i_pasteboard_service.h"
|
||||
#include "paste_data.h"
|
||||
#include "paste_data_record.h"
|
||||
@ -45,337 +46,337 @@ public:
|
||||
DISALLOW_COPY_AND_MOVE(PasteboardClient);
|
||||
|
||||
/**
|
||||
* CreateHtmlTextRecord
|
||||
* @descrition Create Html Text Record.
|
||||
* @param std::string text.
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
* CreateHtmlTextRecord
|
||||
* @descrition Create Html Text Record.
|
||||
* @param std::string text.
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
std::shared_ptr<PasteDataRecord> CreateHtmlTextRecord(const std::string &text);
|
||||
|
||||
/**
|
||||
* CreatePlainTextRecord
|
||||
* @descrition Create Plaint Text Record.
|
||||
* @param std::string text.
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
* CreatePlainTextRecord
|
||||
* @descrition Create Plaint Text Record.
|
||||
* @param std::string text.
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
std::shared_ptr<PasteDataRecord> CreatePlainTextRecord(const std::string &text);
|
||||
|
||||
/**
|
||||
* CreatePixelMapRecord
|
||||
* @descrition Create PixelMap Record.
|
||||
* @param OHOS::Media::PixelMap pixelMap.
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
* CreatePixelMapRecord
|
||||
* @descrition Create PixelMap Record.
|
||||
* @param OHOS::Media::PixelMap pixelMap.
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
std::shared_ptr<PasteDataRecord> CreatePixelMapRecord(std::shared_ptr<OHOS::Media::PixelMap> pixelMap);
|
||||
|
||||
/**
|
||||
* CreateUriRecord
|
||||
* @descrition Create Uri Text Record.
|
||||
* @param OHOS::Uri uri.
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
* CreateUriRecord
|
||||
* @descrition Create Uri Text Record.
|
||||
* @param OHOS::Uri uri.
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
std::shared_ptr<PasteDataRecord> CreateUriRecord(const OHOS::Uri &uri);
|
||||
|
||||
/**
|
||||
* CreateWantRecord
|
||||
* @descrition Create Plaint Want Record.
|
||||
* @param OHOS::AAFwk::Want want.
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
* CreateWantRecord
|
||||
* @descrition Create Plaint Want Record.
|
||||
* @param OHOS::AAFwk::Want want.
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
std::shared_ptr<PasteDataRecord> CreateWantRecord(std::shared_ptr<OHOS::AAFwk::Want> want);
|
||||
|
||||
/**
|
||||
* CreateKvRecord
|
||||
* @descrition Create Kv Record.
|
||||
* @param std::string mimeType
|
||||
* @param std::vector<uint8_t> arrayBuffer
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
* CreateKvRecord
|
||||
* @descrition Create Kv Record.
|
||||
* @param std::string mimeType
|
||||
* @param std::vector<uint8_t> arrayBuffer
|
||||
* @return PasteDataRecord.
|
||||
*/
|
||||
std::shared_ptr<PasteDataRecord> CreateKvRecord(
|
||||
const std::string &mimeType, const std::vector<uint8_t> &arrayBuffer);
|
||||
|
||||
/**
|
||||
* CreateHtmlData
|
||||
* @descrition Create Html Paste Data.
|
||||
* @param std::string text .
|
||||
* @return PasteData.
|
||||
*/
|
||||
* CreateHtmlData
|
||||
* @descrition Create Html Paste Data.
|
||||
* @param std::string text .
|
||||
* @return PasteData.
|
||||
*/
|
||||
std::shared_ptr<PasteData> CreateHtmlData(const std::string &htmlText);
|
||||
|
||||
/**
|
||||
* CreatePlainTextData
|
||||
* @descritionCreate Plain Text Paste Data.
|
||||
* @param std::string text .
|
||||
* @return PasteData.
|
||||
*/
|
||||
* CreatePlainTextData
|
||||
* @descritionCreate Plain Text Paste Data.
|
||||
* @param std::string text .
|
||||
* @return PasteData.
|
||||
*/
|
||||
std::shared_ptr<PasteData> CreatePlainTextData(const std::string &text);
|
||||
|
||||
/**
|
||||
* CreatePixelMapData
|
||||
* @descrition Create PixelMap Paste Data.
|
||||
* @param OHOS::Media::PixelMap pixelMap .
|
||||
* @return PasteData.
|
||||
*/
|
||||
* CreatePixelMapData
|
||||
* @descrition Create PixelMap Paste Data.
|
||||
* @param OHOS::Media::PixelMap pixelMap .
|
||||
* @return PasteData.
|
||||
*/
|
||||
std::shared_ptr<PasteData> CreatePixelMapData(std::shared_ptr<OHOS::Media::PixelMap> pixelMap);
|
||||
|
||||
/**
|
||||
* CreateUriData
|
||||
* @descrition Create Uri Paste Data.
|
||||
* @param OHOS::Uri uri .
|
||||
* @return PasteData.
|
||||
*/
|
||||
* CreateUriData
|
||||
* @descrition Create Uri Paste Data.
|
||||
* @param OHOS::Uri uri .
|
||||
* @return PasteData.
|
||||
*/
|
||||
std::shared_ptr<PasteData> CreateUriData(const OHOS::Uri &uri);
|
||||
|
||||
/**
|
||||
* CreateWantData
|
||||
* @descrition Create Want Paste Data.
|
||||
* @param OHOS::AAFwk::Want want .
|
||||
* @return PasteData.
|
||||
*/
|
||||
* CreateWantData
|
||||
* @descrition Create Want Paste Data.
|
||||
* @param OHOS::AAFwk::Want want .
|
||||
* @return PasteData.
|
||||
*/
|
||||
std::shared_ptr<PasteData> CreateWantData(std::shared_ptr<OHOS::AAFwk::Want> want);
|
||||
|
||||
/**
|
||||
* CreateKvData
|
||||
* @descrition Create Kv Paste Data.
|
||||
* @param std::string mimeType
|
||||
* @param std::vector<uint8_t> arrayBuffer
|
||||
* @return PasteData.
|
||||
*/
|
||||
* CreateKvData
|
||||
* @descrition Create Kv Paste Data.
|
||||
* @param std::string mimeType
|
||||
* @param std::vector<uint8_t> arrayBuffer
|
||||
* @return PasteData.
|
||||
*/
|
||||
std::shared_ptr<PasteData> CreateKvData(const std::string &mimeType, const std::vector<uint8_t> &arrayBuffer);
|
||||
|
||||
/**
|
||||
* GetRecordValueByType
|
||||
* @descrition get entry value from the pasteboard.
|
||||
* @param dataId the dataId of the PasteData.
|
||||
* @param recordId the recordId of the PasteRecord.
|
||||
* @param value the value of the PasteDataEntry.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t GetRecordValueByType(uint32_t dataId, uint32_t recordId, PasteDataEntry& value);
|
||||
* GetRecordValueByType
|
||||
* @descrition get entry value from the pasteboard.
|
||||
* @param dataId the dataId of the PasteData.
|
||||
* @param recordId the recordId of the PasteRecord.
|
||||
* @param value the value of the PasteDataEntry.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t GetRecordValueByType(uint32_t dataId, uint32_t recordId, PasteDataEntry &value);
|
||||
|
||||
/**
|
||||
* GetPasteData
|
||||
* @descrition get paste data from the pasteboard.
|
||||
* @param pasteData the object of the PasteDate.
|
||||
* @return int32_t.
|
||||
*/
|
||||
* GetPasteData
|
||||
* @descrition get paste data from the pasteboard.
|
||||
* @param pasteData the object of the PasteDate.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t GetPasteData(PasteData &pasteData);
|
||||
|
||||
/**
|
||||
* HasPasteData
|
||||
* @descrition check paste data exist in the pasteboard.
|
||||
* @return bool. True exists, false does not exist
|
||||
*/
|
||||
* HasPasteData
|
||||
* @descrition check paste data exist in the pasteboard.
|
||||
* @return bool. True exists, false does not exist
|
||||
*/
|
||||
bool HasPasteData();
|
||||
|
||||
/**
|
||||
* Clear
|
||||
* @descrition Clear Current pasteboard data.
|
||||
* @return void.
|
||||
*/
|
||||
* Clear
|
||||
* @descrition Clear Current pasteboard data.
|
||||
* @return void.
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
/**
|
||||
* SetPasteData
|
||||
* @descrition set paste data to the pasteboard.
|
||||
* @param pasteData the object of the PasteData.
|
||||
* @param pasteData the object of the PasteboardDelayGetter.
|
||||
* @param pasteData the map of the EntryGetter.
|
||||
* @return int32_t.
|
||||
*/
|
||||
* SetPasteData
|
||||
* @descrition set paste data to the pasteboard.
|
||||
* @param pasteData the object of the PasteData.
|
||||
* @param pasteData the object of the PasteboardDelayGetter.
|
||||
* @param pasteData the map of the EntryGetter.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t SetPasteData(PasteData &pasteData, std::shared_ptr<PasteboardDelayGetter> delayGetter = nullptr,
|
||||
std::map<uint32_t, std::shared_ptr<UDMF::EntryGetter>> entryGetters = {});
|
||||
|
||||
/**
|
||||
* SetPasteData
|
||||
* @descrition set paste data to the pasteboard.
|
||||
* @param unifiedData the object of the PasteDate.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t SetUnifiedData(const UDMF::UnifiedData &unifiedData,
|
||||
std::shared_ptr<PasteboardDelayGetter> delayGetter = nullptr);
|
||||
* SetPasteData
|
||||
* @descrition set paste data to the pasteboard.
|
||||
* @param unifiedData the object of the PasteDate.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t SetUnifiedData(
|
||||
const UDMF::UnifiedData &unifiedData, std::shared_ptr<PasteboardDelayGetter> delayGetter = nullptr);
|
||||
|
||||
/**
|
||||
* SetPasteData
|
||||
* @descrition set paste data to the pasteboard.
|
||||
* @param unifiedData the object of the PasteDate.
|
||||
* @return int32_t.
|
||||
*/
|
||||
* SetPasteData
|
||||
* @descrition set paste data to the pasteboard.
|
||||
* @param unifiedData the object of the PasteDate.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t GetUnifiedData(UDMF::UnifiedData &unifiedData);
|
||||
|
||||
/**
|
||||
* SetUdsdData
|
||||
* @descrition set unified data with uds entries to the pasteboard.
|
||||
* @param unifiedData the object of the PasteDate.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t SetUdsdData(const UDMF::UnifiedData& unifiedData);
|
||||
* SetUdsdData
|
||||
* @descrition set unified data with uds entries to the pasteboard.
|
||||
* @param unifiedData the object of the PasteDate.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t SetUdsdData(const UDMF::UnifiedData &unifiedData);
|
||||
|
||||
/**
|
||||
* GetUnifiedDataWithEntry
|
||||
* @descrition get unified data with uds entries from the pasteboard.
|
||||
* @param unifiedData the object of the PasteDate.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t GetUdsdData(UDMF::UnifiedData& unifiedData);
|
||||
* GetUnifiedDataWithEntry
|
||||
* @descrition get unified data with uds entries from the pasteboard.
|
||||
* @param unifiedData the object of the PasteDate.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t GetUdsdData(UDMF::UnifiedData &unifiedData);
|
||||
|
||||
/**
|
||||
* IsRemoteData
|
||||
* @descrition check if remote data.
|
||||
* @return bool. True is remote data, else false.
|
||||
*/
|
||||
* IsRemoteData
|
||||
* @descrition check if remote data.
|
||||
* @return bool. True is remote data, else false.
|
||||
*/
|
||||
bool IsRemoteData();
|
||||
|
||||
/**
|
||||
* GetDataSource
|
||||
* @descrition Obtain the package name of the data source application.
|
||||
* @param std::string bundleName The package name of the application.
|
||||
* @return int32_t.
|
||||
*/
|
||||
* GetDataSource
|
||||
* @descrition Obtain the package name of the data source application.
|
||||
* @param std::string bundleName The package name of the application.
|
||||
* @return int32_t.
|
||||
*/
|
||||
int32_t GetDataSource(std::string &bundleName);
|
||||
|
||||
/**
|
||||
* HasDataType
|
||||
* @descrition Check if there is data of the specified type in the pasteboard.
|
||||
* @param std::string mimeType Specified mimetype.
|
||||
* @return bool. True exists, false does not exist
|
||||
*/
|
||||
* HasDataType
|
||||
* @descrition Check if there is data of the specified type in the pasteboard.
|
||||
* @param std::string mimeType Specified mimetype.
|
||||
* @return bool. True exists, false does not exist
|
||||
*/
|
||||
bool HasDataType(const std::string &mimeType);
|
||||
|
||||
/**
|
||||
* DetectPatterns
|
||||
* @description Checks the specified patterns contained in clipboard, and removes if not found.
|
||||
* @param patternsToCheck A reference to an set of Pattern to check against the clipboard.
|
||||
* @return Returns DetectPatterns.
|
||||
*/
|
||||
* DetectPatterns
|
||||
* @description Checks the specified patterns contained in clipboard, and removes if not found.
|
||||
* @param patternsToCheck A reference to an set of Pattern to check against the clipboard.
|
||||
* @return Returns DetectPatterns.
|
||||
*/
|
||||
std::set<Pattern> DetectPatterns(const std::set<Pattern> &patternsToCheck);
|
||||
|
||||
/**
|
||||
* Subscribe
|
||||
* @descrition
|
||||
* @param type observer type
|
||||
* @param observer pasteboard change callback.
|
||||
* @return void.
|
||||
*/
|
||||
* Subscribe
|
||||
* @descrition
|
||||
* @param type observer type
|
||||
* @param observer pasteboard change callback.
|
||||
* @return void.
|
||||
*/
|
||||
void Subscribe(PasteboardObserverType type, sptr<PasteboardObserver> callback);
|
||||
|
||||
/**
|
||||
* AddPasteboardChangedObserver
|
||||
* @descrition
|
||||
* @param observer pasteboard change callback.
|
||||
* @return void.
|
||||
*/
|
||||
* AddPasteboardChangedObserver
|
||||
* @descrition
|
||||
* @param observer pasteboard change callback.
|
||||
* @return void.
|
||||
*/
|
||||
void AddPasteboardChangedObserver(sptr<PasteboardObserver> callback);
|
||||
|
||||
/**
|
||||
* AddPasteboardEventObserver
|
||||
* @descrition
|
||||
* @param observer pasteboard event(read or change) callback.
|
||||
* @return void.
|
||||
*/
|
||||
* AddPasteboardEventObserver
|
||||
* @descrition
|
||||
* @param observer pasteboard event(read or change) callback.
|
||||
* @return void.
|
||||
*/
|
||||
void AddPasteboardEventObserver(sptr<PasteboardObserver> callback);
|
||||
|
||||
/**
|
||||
* Unsubscribe
|
||||
* @descrition
|
||||
* @param type observer type
|
||||
* @param observer pasteboard change callback.
|
||||
* @return void.
|
||||
*/
|
||||
/**
|
||||
* Unsubscribe
|
||||
* @descrition
|
||||
* @param type observer type
|
||||
* @param observer pasteboard change callback.
|
||||
* @return void.
|
||||
*/
|
||||
void Unsubscribe(PasteboardObserverType type, sptr<PasteboardObserver> callback);
|
||||
|
||||
/**
|
||||
* RemovePasteboardChangedObserver
|
||||
* @descrition
|
||||
* @param observer pasteboard change callback.
|
||||
* @return void.
|
||||
*/
|
||||
* RemovePasteboardChangedObserver
|
||||
* @descrition
|
||||
* @param observer pasteboard change callback.
|
||||
* @return void.
|
||||
*/
|
||||
void RemovePasteboardChangedObserver(sptr<PasteboardObserver> callback);
|
||||
|
||||
/**
|
||||
* RemovePasteboardEventObserver
|
||||
* @descrition
|
||||
* @param observer pasteboard event callback.
|
||||
* @return void.
|
||||
*/
|
||||
* RemovePasteboardEventObserver
|
||||
* @descrition
|
||||
* @param observer pasteboard event callback.
|
||||
* @return void.
|
||||
*/
|
||||
void RemovePasteboardEventObserver(sptr<PasteboardObserver> callback);
|
||||
|
||||
/**
|
||||
* SetGlobalShareOption
|
||||
* @descrition Set globalShareOptions.
|
||||
* @param globalShareOption globalShareOptions
|
||||
* @return int32_t
|
||||
*/
|
||||
* SetGlobalShareOption
|
||||
* @descrition Set globalShareOptions.
|
||||
* @param globalShareOption globalShareOptions
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t SetGlobalShareOption(const std::map<uint32_t, ShareOption> &globalShareOptions);
|
||||
|
||||
/**
|
||||
* RemoveGlobalShareOption
|
||||
* @descrition Remove globalShareOptions.
|
||||
* @param tokenId tokenIds
|
||||
* @return int32_t
|
||||
*/
|
||||
* RemoveGlobalShareOption
|
||||
* @descrition Remove globalShareOptions.
|
||||
* @param tokenId tokenIds
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t RemoveGlobalShareOption(const std::vector<uint32_t> &tokenIds);
|
||||
|
||||
/**
|
||||
* GetGlobalShareOption
|
||||
* @descrition Get globalShareOptions.
|
||||
* @param tokenId tokenIds
|
||||
* @return globalShareOptions
|
||||
*/
|
||||
* GetGlobalShareOption
|
||||
* @descrition Get globalShareOptions.
|
||||
* @param tokenId tokenIds
|
||||
* @return globalShareOptions
|
||||
*/
|
||||
std::map<uint32_t, ShareOption> GetGlobalShareOption(const std::vector<uint32_t> &tokenIds);
|
||||
|
||||
/**
|
||||
* SetAppShareOptions
|
||||
* @description Sets a unified ShareOptions for the application.
|
||||
* @param shareOptions shareOptions
|
||||
* @return result
|
||||
*/
|
||||
* SetAppShareOptions
|
||||
* @description Sets a unified ShareOptions for the application.
|
||||
* @param shareOptions shareOptions
|
||||
* @return result
|
||||
*/
|
||||
int32_t SetAppShareOptions(const ShareOption &shareOptions);
|
||||
|
||||
/**
|
||||
* RemoveAppShareOptions
|
||||
* @description Removes the ShareOptions for the application.
|
||||
* @return result
|
||||
*/
|
||||
* RemoveAppShareOptions
|
||||
* @description Removes the ShareOptions for the application.
|
||||
* @return result
|
||||
*/
|
||||
int32_t RemoveAppShareOptions();
|
||||
|
||||
/**
|
||||
* OnRemoteSaDied
|
||||
* @descrition
|
||||
* @param object systemAbility proxy object
|
||||
* @return void.
|
||||
*/
|
||||
* OnRemoteSaDied
|
||||
* @descrition
|
||||
* @param object systemAbility proxy object
|
||||
* @return void.
|
||||
*/
|
||||
void OnRemoteSaDied(const wptr<IRemoteObject> &object);
|
||||
|
||||
/**
|
||||
* LoadSystemAbilitySuccess
|
||||
* @descrition inherit SystemAbilityLoadCallbackStub override LoadSystemAbilitySuccess
|
||||
* @param remoteObject systemAbility proxy object.
|
||||
* @return void.
|
||||
*/
|
||||
* LoadSystemAbilitySuccess
|
||||
* @descrition inherit SystemAbilityLoadCallbackStub override LoadSystemAbilitySuccess
|
||||
* @param remoteObject systemAbility proxy object.
|
||||
* @return void.
|
||||
*/
|
||||
void LoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject);
|
||||
|
||||
/**
|
||||
* LoadSystemAbilityFail
|
||||
* @descrition inherit SystemAbilityLoadCallbackStub override LoadSystemAbilityFail
|
||||
* @return void.
|
||||
*/
|
||||
* LoadSystemAbilityFail
|
||||
* @descrition inherit SystemAbilityLoadCallbackStub override LoadSystemAbilityFail
|
||||
* @return void.
|
||||
*/
|
||||
void LoadSystemAbilityFail();
|
||||
|
||||
/**
|
||||
* PasteStart
|
||||
* @descrition Utilized to notify pasteboard service while reading PasteData, in this case, the service will help to
|
||||
* preserve the context and resources
|
||||
* @return void.
|
||||
*/
|
||||
* PasteStart
|
||||
* @descrition Utilized to notify pasteboard service while reading PasteData, in this case, the service will help to
|
||||
* preserve the context and resources
|
||||
* @return void.
|
||||
*/
|
||||
void PasteStart(const std::string &pasteId);
|
||||
|
||||
/**
|
||||
* PasteComplete
|
||||
* @descrition Invoked to notify pasteboard service the utilization of PasteData has completed and occupied
|
||||
* resources can be released for further usage
|
||||
* @return void.
|
||||
*/
|
||||
* PasteComplete
|
||||
* @descrition Invoked to notify pasteboard service the utilization of PasteData has completed and occupied
|
||||
* resources can be released for further usage
|
||||
* @return void.
|
||||
*/
|
||||
void PasteComplete(const std::string &deviceId, const std::string &pasteId);
|
||||
|
||||
private:
|
||||
@ -389,20 +390,20 @@ private:
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_{ nullptr };
|
||||
std::atomic<uint32_t> getSequenceId_ = 0;
|
||||
class StaticDestoryMonitor {
|
||||
public:
|
||||
StaticDestoryMonitor() : destoryed_(false) {}
|
||||
~StaticDestoryMonitor()
|
||||
{
|
||||
destoryed_ = true;
|
||||
}
|
||||
public:
|
||||
StaticDestoryMonitor() : destoryed_(false) {}
|
||||
~StaticDestoryMonitor()
|
||||
{
|
||||
destoryed_ = true;
|
||||
}
|
||||
|
||||
bool IsDestoryed() const
|
||||
{
|
||||
return destoryed_;
|
||||
}
|
||||
bool IsDestoryed() const
|
||||
{
|
||||
return destoryed_;
|
||||
}
|
||||
|
||||
private:
|
||||
bool destoryed_;
|
||||
private:
|
||||
bool destoryed_;
|
||||
};
|
||||
static StaticDestoryMonitor staticDestoryMonitor_;
|
||||
void RebuildWebviewPasteData(PasteData &pasteData);
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
|
||||
PasteboardDelayGetter() = default;
|
||||
|
||||
virtual ~PasteboardDelayGetter() {};
|
||||
virtual ~PasteboardDelayGetter(){};
|
||||
|
||||
virtual void GetPasteData(const std::string &type, PasteData &data) = 0;
|
||||
|
||||
|
@ -25,11 +25,13 @@ public:
|
||||
PasteboardEntryGetter() = default;
|
||||
~PasteboardEntryGetter() = default;
|
||||
UDMF::ValueType GetValueByType(uint32_t dataId, uint32_t recordId, const std::string &utdId) override;
|
||||
|
||||
private:
|
||||
class Factory {
|
||||
public:
|
||||
Factory();
|
||||
~Factory();
|
||||
|
||||
private:
|
||||
std::shared_ptr<PasteboardEntryGetter> getter_;
|
||||
};
|
||||
|
@ -31,10 +31,10 @@ namespace MiscServices {
|
||||
|
||||
class API_EXPORT PasteboardWebController : public RefBase {
|
||||
public:
|
||||
PasteboardWebController() {};
|
||||
~PasteboardWebController() {};
|
||||
PasteboardWebController(){};
|
||||
~PasteboardWebController(){};
|
||||
|
||||
static PasteboardWebController& GetInstance();
|
||||
static PasteboardWebController &GetInstance();
|
||||
|
||||
std::shared_ptr<PasteData> SplitHtml(std::shared_ptr<std::string> html) noexcept;
|
||||
std::shared_ptr<std::string> RebuildHtml(std::shared_ptr<PasteData> pasteData) noexcept;
|
||||
@ -43,11 +43,11 @@ private:
|
||||
std::vector<std::pair<std::string, uint32_t>> SplitHtmlWithImgLabel(
|
||||
const std::shared_ptr<std::string> html) noexcept;
|
||||
std::map<std::string, std::vector<uint8_t>> SplitHtmlWithImgSrcLabel(
|
||||
const std::vector<std::pair<std::string, uint32_t>>& matchVec) noexcept;
|
||||
const std::vector<std::pair<std::string, uint32_t>> &matchVec) noexcept;
|
||||
std::shared_ptr<PasteData> BuildPasteData(
|
||||
std::shared_ptr<std::string> html, const std::map<std::string, std::vector<uint8_t>>& imgSrcMap) noexcept;
|
||||
std::shared_ptr<std::string> html, const std::map<std::string, std::vector<uint8_t>> &imgSrcMap) noexcept;
|
||||
void RemoveAllRecord(std::shared_ptr<PasteData> pasteData) noexcept;
|
||||
bool IsLocalURI(std::string& uri) noexcept;
|
||||
bool IsLocalURI(std::string &uri) noexcept;
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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_),
|
||||
@ -283,7 +282,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 +350,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 +470,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 +480,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 +490,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 +509,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 +526,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 +534,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 +593,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 +633,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 +645,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;
|
||||
}
|
||||
|
@ -13,14 +13,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <if_system_ability_manager.h>
|
||||
#include <ipc_skeleton.h>
|
||||
#include <iservice_registry.h>
|
||||
#include <chrono>
|
||||
|
||||
#include "convert_utils.h"
|
||||
#include "file_uri.h"
|
||||
#include "hiview_adapter.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "hiview_adapter.h"
|
||||
#include "ipasteboard_client_death_observer.h"
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_delay_getter_client.h"
|
||||
#include "pasteboard_entry_getter_client.h"
|
||||
@ -28,11 +30,10 @@
|
||||
#include "pasteboard_event_dfx.h"
|
||||
#include "pasteboard_load_callback.h"
|
||||
#include "pasteboard_observer.h"
|
||||
#include "pasteboard_utils.h"
|
||||
#include "pasteboard_web_controller.h"
|
||||
#include "string_ex.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "pasteboard_web_controller.h"
|
||||
#include "pasteboard_utils.h"
|
||||
#include "ipasteboard_client_death_observer.h"
|
||||
using namespace OHOS::Media;
|
||||
|
||||
namespace OHOS {
|
||||
@ -230,7 +231,7 @@ int32_t PasteboardClient::GetPasteData(PasteData &pasteData)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t PasteboardClient::GetUnifiedData(UDMF::UnifiedData& unifiedData)
|
||||
int32_t PasteboardClient::GetUnifiedData(UDMF::UnifiedData &unifiedData)
|
||||
{
|
||||
StartAsyncTrace(HITRACE_TAG_MISC, "PasteboardClient::GetUnifiedData", HITRACE_GETPASTEDATA);
|
||||
PasteData pasteData;
|
||||
@ -258,7 +259,7 @@ void PasteboardClient::RebuildWebviewPasteData(PasteData &pasteData)
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "Rebuild webview PasteData start.");
|
||||
auto details = std::make_shared<Details>();
|
||||
std::string textContent;
|
||||
for (auto& item : pasteData.AllRecords()) {
|
||||
for (auto &item : pasteData.AllRecords()) {
|
||||
if (!item->GetTextContent().empty() && textContent.empty()) {
|
||||
details = item->GetDetails();
|
||||
textContent = item->GetTextContent();
|
||||
@ -327,8 +328,8 @@ bool PasteboardClient::HasPasteData()
|
||||
return proxyService->HasPasteData();
|
||||
}
|
||||
|
||||
int32_t PasteboardClient::SetPasteData(PasteData &pasteData, std::shared_ptr <PasteboardDelayGetter> delayGetter,
|
||||
std::map <uint32_t, std::shared_ptr<UDMF::EntryGetter>> entryGetters)
|
||||
int32_t PasteboardClient::SetPasteData(PasteData &pasteData, std::shared_ptr<PasteboardDelayGetter> delayGetter,
|
||||
std::map<uint32_t, std::shared_ptr<UDMF::EntryGetter>> entryGetters)
|
||||
{
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "SetPasteData start.");
|
||||
RADAR_REPORT(RadarReporter::DFX_SET_PASTEBOARD, RadarReporter::DFX_SET_BIZ_SCENE, RadarReporter::DFX_SUCCESS,
|
||||
@ -345,10 +346,10 @@ int32_t PasteboardClient::SetPasteData(PasteData &pasteData, std::shared_ptr <Pa
|
||||
pasteData.SetDelayData(true);
|
||||
delayGetterAgent = new (std::nothrow) PasteboardDelayGetterClient(delayGetter);
|
||||
}
|
||||
sptr <PasteboardEntryGetterClient> entryGetterAgent;
|
||||
sptr<PasteboardEntryGetterClient> entryGetterAgent;
|
||||
if (!(entryGetters.empty())) {
|
||||
pasteData.SetDelayRecord(true);
|
||||
entryGetterAgent = new(std::nothrow) PasteboardEntryGetterClient(entryGetters);
|
||||
entryGetterAgent = new (std::nothrow) PasteboardEntryGetterClient(entryGetters);
|
||||
}
|
||||
std::shared_ptr<std::string> html = pasteData.GetPrimaryHtml();
|
||||
if (html == nullptr) {
|
||||
@ -370,8 +371,8 @@ int32_t PasteboardClient::SetPasteData(PasteData &pasteData, std::shared_ptr <Pa
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t PasteboardClient::SetUnifiedData(const UDMF::UnifiedData &unifiedData,
|
||||
std::shared_ptr<PasteboardDelayGetter> delayGetter)
|
||||
int32_t PasteboardClient::SetUnifiedData(
|
||||
const UDMF::UnifiedData &unifiedData, std::shared_ptr<PasteboardDelayGetter> delayGetter)
|
||||
{
|
||||
auto pasteData = PasteboardUtils::GetInstance().Convert(unifiedData);
|
||||
return SetPasteData(*pasteData, delayGetter);
|
||||
@ -380,7 +381,7 @@ int32_t PasteboardClient::SetUnifiedData(const UDMF::UnifiedData &unifiedData,
|
||||
int32_t PasteboardClient::SetUdsdData(const UDMF::UnifiedData &unifiedData)
|
||||
{
|
||||
auto pasteData = ConvertUtils::Convert(unifiedData);
|
||||
std::map <uint32_t, std::shared_ptr<UDMF::EntryGetter>> entryGetters;
|
||||
std::map<uint32_t, std::shared_ptr<UDMF::EntryGetter>> entryGetters;
|
||||
for (auto record : unifiedData.GetRecords()) {
|
||||
if (record != nullptr && record->GetEntryGetter() != nullptr) {
|
||||
entryGetters.emplace(record->GetRecordId(), record->GetEntryGetter());
|
||||
@ -609,8 +610,9 @@ sptr<IPasteboardService> PasteboardClient::GetPasteboardService()
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "Failed to load systemAbility.");
|
||||
return nullptr;
|
||||
}
|
||||
auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(LOADSA_TIMEOUT_MS),
|
||||
[this]() { return pasteboardServiceProxy_ != nullptr; });
|
||||
auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(LOADSA_TIMEOUT_MS), [this]() {
|
||||
return pasteboardServiceProxy_ != nullptr;
|
||||
});
|
||||
if (!waitStatus) {
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "Load systemAbility timeout.");
|
||||
return nullptr;
|
||||
@ -672,9 +674,7 @@ void PasteboardClient::PasteComplete(const std::string &deviceId, const std::str
|
||||
proxyService->PasteComplete(deviceId, pasteId);
|
||||
}
|
||||
|
||||
PasteboardSaDeathRecipient::PasteboardSaDeathRecipient()
|
||||
{
|
||||
}
|
||||
PasteboardSaDeathRecipient::PasteboardSaDeathRecipient() {}
|
||||
|
||||
void PasteboardSaDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
|
||||
{
|
||||
|
@ -14,8 +14,8 @@
|
||||
*/
|
||||
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_error.h"
|
||||
#include "pasteboard_entry_getter.h"
|
||||
#include "pasteboard_error.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -39,8 +39,8 @@ PasteboardEntryGetter::Factory::~Factory()
|
||||
|
||||
UDMF::ValueType PasteboardEntryGetter::GetValueByType(uint32_t dataId, uint32_t recordId, const std::string &utdId)
|
||||
{
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "dataId:%{public}d. recordId:%{public}d, utdId:%{public}s",
|
||||
dataId, recordId, utdId.c_str());
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "dataId:%{public}d. recordId:%{public}d, utdId:%{public}s", dataId,
|
||||
recordId, utdId.c_str());
|
||||
auto pasteType = CommonUtils::Convert2MimeType(utdId);
|
||||
PasteDataEntry entryValue;
|
||||
entryValue.SetUtdId(utdId);
|
||||
|
@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "pasteboard_load_callback.h"
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_load_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -31,5 +31,5 @@ void PasteboardLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
|
||||
PasteboardClient::GetInstance()->LoadSystemAbilityFail();
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "Load system ability failed!");
|
||||
}
|
||||
}
|
||||
} // namespace MiscServices
|
||||
}
|
@ -12,8 +12,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "pasteboard_utils.h"
|
||||
|
||||
#include "application_defined_record.h"
|
||||
#include "audio.h"
|
||||
#include "folder.h"
|
||||
@ -21,13 +19,14 @@
|
||||
#include "image.h"
|
||||
#include "link.h"
|
||||
#include "paste_data_record.h"
|
||||
#include "pasteboard_utils.h"
|
||||
#include "pixel_map.h"
|
||||
#include "plain_text.h"
|
||||
#include "system_defined_appitem.h"
|
||||
#include "system_defined_form.h"
|
||||
#include "system_defined_pixelmap.h"
|
||||
#include "unified_record.h"
|
||||
#include "video.h"
|
||||
#include "system_defined_pixelmap.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -74,7 +73,7 @@ void PasteboardUtils::InitDecodeMap()
|
||||
};
|
||||
}
|
||||
|
||||
std::shared_ptr<PasteData> PasteboardUtils::Convert(const UnifiedData& unifiedData)
|
||||
std::shared_ptr<PasteData> PasteboardUtils::Convert(const UnifiedData &unifiedData)
|
||||
{
|
||||
auto unifiedRecords = unifiedData.GetRecords();
|
||||
auto pasteData = std::make_shared<PasteData>(Convert(unifiedRecords));
|
||||
@ -86,7 +85,7 @@ std::shared_ptr<PasteData> PasteboardUtils::Convert(const UnifiedData& unifiedDa
|
||||
return pasteData;
|
||||
}
|
||||
|
||||
std::shared_ptr<UnifiedData> PasteboardUtils::Convert(const PasteData& pasteData)
|
||||
std::shared_ptr<UnifiedData> PasteboardUtils::Convert(const PasteData &pasteData)
|
||||
{
|
||||
auto unifiedData = std::make_shared<UnifiedData>();
|
||||
for (std::size_t i = 0; i < pasteData.GetRecordCount(); ++i) {
|
||||
@ -110,10 +109,10 @@ std::shared_ptr<UnifiedData> PasteboardUtils::Convert(const PasteData& pasteData
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<PasteDataRecord>> PasteboardUtils::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) {
|
||||
if (record == nullptr) {
|
||||
continue;
|
||||
}
|
||||
@ -130,7 +129,7 @@ std::vector<std::shared_ptr<PasteDataRecord>> PasteboardUtils::Convert(
|
||||
return pasteboardRecords;
|
||||
}
|
||||
|
||||
PasteDataProperty PasteboardUtils::Convert(const UnifiedDataProperties& properties)
|
||||
PasteDataProperty PasteboardUtils::Convert(const UnifiedDataProperties &properties)
|
||||
{
|
||||
PasteDataProperty pasteDataProperty;
|
||||
pasteDataProperty.shareOption = static_cast<ShareOption>(properties.shareOptions);
|
||||
@ -141,11 +140,11 @@ PasteDataProperty PasteboardUtils::Convert(const UnifiedDataProperties& properti
|
||||
return PasteDataProperty(pasteDataProperty);
|
||||
}
|
||||
|
||||
std::shared_ptr<UnifiedDataProperties> PasteboardUtils::Convert(const PasteDataProperty& properties)
|
||||
std::shared_ptr<UnifiedDataProperties> PasteboardUtils::Convert(const PasteDataProperty &properties)
|
||||
{
|
||||
auto unifiedDataProperties = std::make_shared<UnifiedDataProperties>();
|
||||
unifiedDataProperties->shareOptions = properties.shareOption == ShareOption::InApp ? UDMF::ShareOptions::IN_APP
|
||||
: UDMF::ShareOptions::CROSS_APP;
|
||||
: UDMF::ShareOptions::CROSS_APP;
|
||||
unifiedDataProperties->extras = properties.additions;
|
||||
unifiedDataProperties->timestamp = properties.timestamp;
|
||||
unifiedDataProperties->tag = properties.tag;
|
||||
@ -153,10 +152,10 @@ std::shared_ptr<UnifiedDataProperties> PasteboardUtils::Convert(const PasteDataP
|
||||
return unifiedDataProperties;
|
||||
}
|
||||
|
||||
std::vector<std::string> PasteboardUtils::Convert(const std::vector<std::string>& utdIds)
|
||||
std::vector<std::string> PasteboardUtils::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;
|
||||
@ -185,7 +184,7 @@ std::string PasteboardUtils::Convert(UDType uDType)
|
||||
}
|
||||
}
|
||||
|
||||
UDType PasteboardUtils::Convert(int32_t uDType, const std::string& mimeType)
|
||||
UDType PasteboardUtils::Convert(int32_t uDType, const std::string &mimeType)
|
||||
{
|
||||
if (uDType != UDMF::UD_BUTT) {
|
||||
return static_cast<UDType>(uDType);
|
||||
@ -214,7 +213,7 @@ UDType PasteboardUtils::Convert(int32_t uDType, const std::string& mimeType)
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::PlainText2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto plainText = static_cast<UDMF::PlainText*>(record.get());
|
||||
auto plainText = static_cast<UDMF::PlainText *>(record.get());
|
||||
if (plainText == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get PLAIN_TEXT record failed.");
|
||||
return nullptr;
|
||||
@ -255,7 +254,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2PlaintText(const std
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::Want2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto want = static_cast<UDMF::UnifiedRecord*>(record.get());
|
||||
auto want = static_cast<UDMF::UnifiedRecord *>(record.get());
|
||||
if (want == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get want record failed.");
|
||||
return nullptr;
|
||||
@ -287,7 +286,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2Want(const std::shar
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::Html2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto html = static_cast<UDMF::Html*>(record.get());
|
||||
auto html = static_cast<UDMF::Html *>(record.get());
|
||||
if (html == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get HTML record failed.");
|
||||
return nullptr;
|
||||
@ -328,7 +327,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2Html(const std::shar
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::Link2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto link = static_cast<UDMF::Link*>(record.get());
|
||||
auto link = static_cast<UDMF::Link *>(record.get());
|
||||
if (link == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get Link record failed.");
|
||||
return nullptr;
|
||||
@ -369,7 +368,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2Link(const std::shar
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::File2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto file = static_cast<UDMF::File*>(record.get());
|
||||
auto file = static_cast<UDMF::File *>(record.get());
|
||||
if (file == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get file record failed.");
|
||||
return nullptr;
|
||||
@ -401,7 +400,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2File(const std::shar
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::Image2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto image = static_cast<UDMF::Image*>(record.get());
|
||||
auto image = static_cast<UDMF::Image *>(record.get());
|
||||
if (image == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get image record failed.");
|
||||
return nullptr;
|
||||
@ -433,7 +432,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2Image(const std::sha
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::Video2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto video = static_cast<UDMF::Video*>(record.get());
|
||||
auto video = static_cast<UDMF::Video *>(record.get());
|
||||
if (video == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get video record failed.");
|
||||
return nullptr;
|
||||
@ -465,7 +464,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2Video(const std::sha
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::Audio2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto audio = static_cast<UDMF::Audio*>(record.get());
|
||||
auto audio = static_cast<UDMF::Audio *>(record.get());
|
||||
if (audio == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get audio record failed.");
|
||||
return nullptr;
|
||||
@ -497,7 +496,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2Audio(const std::sha
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::Folder2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto folder = static_cast<UDMF::Folder*>(record.get());
|
||||
auto folder = static_cast<UDMF::Folder *>(record.get());
|
||||
if (folder == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get folder record failed.");
|
||||
return nullptr;
|
||||
@ -529,7 +528,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2Folder(const std::sh
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::PixelMap2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto pixelMap = static_cast<UDMF::SystemDefinedPixelMap*>(record.get());
|
||||
auto pixelMap = static_cast<UDMF::SystemDefinedPixelMap *>(record.get());
|
||||
if (pixelMap == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get pixelMap record failed.");
|
||||
return nullptr;
|
||||
@ -561,7 +560,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2PixelMap(const std::
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::AppItem2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto appItem = static_cast<UDMF::SystemDefinedAppItem*>(record.get());
|
||||
auto appItem = static_cast<UDMF::SystemDefinedAppItem *>(record.get());
|
||||
if (appItem == nullptr) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "get SystemDefinedAppItem record failed.");
|
||||
return nullptr;
|
||||
@ -605,7 +604,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2AppItem(const std::s
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::Form2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto form = static_cast<UDMF::SystemDefinedForm*>(record.get());
|
||||
auto form = static_cast<UDMF::SystemDefinedForm *>(record.get());
|
||||
if (form == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get SystemDefinedForm record failed.");
|
||||
return nullptr;
|
||||
@ -635,7 +634,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2Form(const std::shar
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::SystemDefined2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto systemDefined = static_cast<UDMF::SystemDefinedRecord*>(record.get());
|
||||
auto systemDefined = static_cast<UDMF::SystemDefinedRecord *>(record.get());
|
||||
if (systemDefined == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get systemRecord record failed.");
|
||||
return nullptr;
|
||||
@ -661,7 +660,7 @@ std::shared_ptr<UnifiedRecord> PasteboardUtils::PasteRecord2SystemDefined(const
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::Text2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto text = static_cast<UDMF::Text*>(record.get());
|
||||
auto text = static_cast<UDMF::Text *>(record.get());
|
||||
if (text == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get TEXT record failed.");
|
||||
return nullptr;
|
||||
@ -698,7 +697,7 @@ std::vector<std::shared_ptr<UnifiedRecord>> PasteboardUtils::Custom2AppDefined(
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "customData is null");
|
||||
return unifiedRecords;
|
||||
}
|
||||
for (auto& [type, rawData] : customData->GetItemData()) {
|
||||
for (auto &[type, rawData] : customData->GetItemData()) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "app defied type:%{public}s.", type.c_str());
|
||||
unifiedRecords.push_back(std::make_shared<UDMF::ApplicationDefinedRecord>(type, rawData));
|
||||
}
|
||||
@ -707,7 +706,7 @@ std::vector<std::shared_ptr<UnifiedRecord>> PasteboardUtils::Custom2AppDefined(
|
||||
|
||||
std::shared_ptr<PasteDataRecord> PasteboardUtils::AppDefined2PasteRecord(const std::shared_ptr<UnifiedRecord> record)
|
||||
{
|
||||
auto appRecord = static_cast<UDMF::ApplicationDefinedRecord*>(record.get());
|
||||
auto appRecord = static_cast<UDMF::ApplicationDefinedRecord *>(record.get());
|
||||
if (appRecord == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "get ApplicationDefinedRecord record failed.");
|
||||
return nullptr;
|
||||
@ -732,7 +731,7 @@ PasteboardUtils::PasteboardUtils()
|
||||
InitDecodeMap();
|
||||
}
|
||||
|
||||
PasteboardUtils& PasteboardUtils::GetInstance()
|
||||
PasteboardUtils &PasteboardUtils::GetInstance()
|
||||
{
|
||||
static PasteboardUtils instance;
|
||||
return instance;
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include <regex>
|
||||
|
||||
#include "file_uri.h"
|
||||
#include "pasteboard_web_controller.h"
|
||||
|
||||
@ -27,7 +28,7 @@ constexpr uint32_t FOUR_BYTES = 4;
|
||||
constexpr uint32_t EIGHT_BIT = 8;
|
||||
|
||||
struct Cmp {
|
||||
bool operator()(const uint32_t& lhs, const uint32_t& rhs) const
|
||||
bool operator()(const uint32_t &lhs, const uint32_t &rhs) const
|
||||
{
|
||||
return lhs > rhs;
|
||||
}
|
||||
@ -38,7 +39,7 @@ namespace OHOS {
|
||||
namespace MiscServices {
|
||||
|
||||
// static
|
||||
PasteboardWebController& PasteboardWebController::GetInstance()
|
||||
PasteboardWebController &PasteboardWebController::GetInstance()
|
||||
{
|
||||
static PasteboardWebController instance;
|
||||
return instance;
|
||||
@ -55,14 +56,13 @@ std::shared_ptr<PasteData> PasteboardWebController::SplitHtml(std::shared_ptr<st
|
||||
return pasteData;
|
||||
}
|
||||
|
||||
std::shared_ptr<std::string> PasteboardWebController::RebuildHtml(
|
||||
std::shared_ptr<PasteData> pasteData) noexcept
|
||||
std::shared_ptr<std::string> PasteboardWebController::RebuildHtml(std::shared_ptr<PasteData> pasteData) noexcept
|
||||
{
|
||||
std::vector<std::shared_ptr<PasteDataRecord>> pasteDataRecords = pasteData->AllRecords();
|
||||
std::shared_ptr<std::string> htmlData;
|
||||
std::map<uint32_t, std::pair<std::string, std::string>, Cmp> replaceUris;
|
||||
|
||||
for (auto& item : pasteDataRecords) {
|
||||
for (auto &item : pasteDataRecords) {
|
||||
std::shared_ptr<std::string> html = item->GetHtmlText();
|
||||
if (html) {
|
||||
htmlData = html;
|
||||
@ -73,7 +73,7 @@ std::shared_ptr<std::string> PasteboardWebController::RebuildHtml(
|
||||
continue;
|
||||
}
|
||||
std::map<std::string, std::vector<uint8_t>> customItemData = customData->GetItemData();
|
||||
for (auto& itemData : customItemData) {
|
||||
for (auto &itemData : customItemData) {
|
||||
for (uint32_t i = 0; i < itemData.second.size(); i += FOUR_BYTES) {
|
||||
uint32_t offset = static_cast<uint32_t>(itemData.second[i]) |
|
||||
static_cast<uint32_t>(itemData.second[i + 1] << 8) |
|
||||
@ -85,7 +85,7 @@ std::shared_ptr<std::string> PasteboardWebController::RebuildHtml(
|
||||
}
|
||||
|
||||
RemoveAllRecord(pasteData);
|
||||
for (auto& replaceUri : replaceUris) {
|
||||
for (auto &replaceUri : replaceUris) {
|
||||
htmlData->replace(replaceUri.first, replaceUri.second.second.size(), replaceUri.second.first);
|
||||
}
|
||||
pasteData->AddHtmlRecord(*htmlData);
|
||||
@ -114,12 +114,12 @@ std::vector<std::pair<std::string, uint32_t>> PasteboardWebController::SplitHtml
|
||||
}
|
||||
|
||||
std::map<std::string, std::vector<uint8_t>> PasteboardWebController::SplitHtmlWithImgSrcLabel(
|
||||
const std::vector<std::pair<std::string, uint32_t>>& matchVec) noexcept
|
||||
const std::vector<std::pair<std::string, uint32_t>> &matchVec) noexcept
|
||||
{
|
||||
std::map<std::string, std::vector<uint8_t>> res;
|
||||
std::smatch match;
|
||||
std::regex re(IMG_TAG_SRC_PATTERN);
|
||||
for (auto& node : matchVec) {
|
||||
for (auto &node : matchVec) {
|
||||
std::string::const_iterator iterStart = node.first.begin();
|
||||
std::string::const_iterator iterEnd = node.first.end();
|
||||
|
||||
@ -142,11 +142,11 @@ std::map<std::string, std::vector<uint8_t>> PasteboardWebController::SplitHtmlWi
|
||||
}
|
||||
|
||||
std::shared_ptr<PasteData> PasteboardWebController::BuildPasteData(
|
||||
std::shared_ptr<std::string> html, const std::map<std::string, std::vector<uint8_t>>& imgSrcMap) noexcept
|
||||
std::shared_ptr<std::string> html, const std::map<std::string, std::vector<uint8_t>> &imgSrcMap) noexcept
|
||||
{
|
||||
std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
|
||||
pasteData->AddHtmlRecord(*html);
|
||||
for (auto& item : imgSrcMap) {
|
||||
for (auto &item : imgSrcMap) {
|
||||
PasteDataRecord::Builder builder(MiscServices::MIMETYPE_TEXT_URI);
|
||||
auto uri = std::make_shared<OHOS::Uri>(item.first);
|
||||
builder.SetUri(uri);
|
||||
@ -170,7 +170,7 @@ void PasteboardWebController::RemoveAllRecord(std::shared_ptr<PasteData> pasteDa
|
||||
}
|
||||
}
|
||||
|
||||
bool PasteboardWebController::IsLocalURI(std::string& uri) noexcept
|
||||
bool PasteboardWebController::IsLocalURI(std::string &uri) noexcept
|
||||
{
|
||||
return uri.substr(0, IMG_LOCAL_URI.size()) == IMG_LOCAL_URI || uri.find(IMG_LOCAL_PATH) == std::string::npos;
|
||||
}
|
||||
|
@ -43,5 +43,5 @@ bool ClipFactory::Destroy(ClipPlugin *plugin)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::MiscServices
|
||||
#endif // PASTE_DATA_TEST_CLIP_FACTORY_H
|
@ -17,6 +17,7 @@
|
||||
#define DISTRIBUTED_PASTEBOARD_FRAMEWORK_DISTRIBUTED_CLIP_H
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
|
||||
#include "device/dm_adapter.h"
|
||||
|
||||
namespace OHOS::MiscServices {
|
||||
@ -27,16 +28,10 @@ public:
|
||||
void OnReady(const std::string &device) override;
|
||||
};
|
||||
|
||||
void DistributedClip::Online(const std::string &device)
|
||||
{
|
||||
}
|
||||
void DistributedClip::Online(const std::string &device) {}
|
||||
|
||||
void DistributedClip::Offline(const std::string &device)
|
||||
{
|
||||
}
|
||||
void DistributedClip::Offline(const std::string &device) {}
|
||||
|
||||
void DistributedClip::OnReady(const std::string &device)
|
||||
{
|
||||
}
|
||||
void DistributedClip::OnReady(const std::string &device) {}
|
||||
} // namespace OHOS::MiscServices
|
||||
#endif // DISTRIBUTED_PASTEBOARD_FRAMEWORK_DISTRIBUTED_CLIP_H
|
||||
|
@ -13,12 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "convert_utils.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <paste_data.h>
|
||||
#include <unified_data.h>
|
||||
|
||||
#include "convert_utils.h"
|
||||
#include "paste_data_entry.h"
|
||||
#include "tlv_object.h"
|
||||
#include "unified_meta.h"
|
||||
@ -45,7 +44,7 @@ protected:
|
||||
std::vector<uint8_t> rawData1_ = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
std::vector<uint8_t> rawData2_ = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
void CheckEntries(const std::vector<std::shared_ptr<PasteDataEntry>>& entries);
|
||||
void CheckEntries(const std::vector<std::shared_ptr<PasteDataEntry>> &entries);
|
||||
void CheckPlainUds(const std::shared_ptr<PasteDataEntry> entry);
|
||||
void CheckFileUriUds(const std::shared_ptr<PasteDataEntry> entry);
|
||||
void CheckPixelMapUds(const std::shared_ptr<PasteDataEntry> entry);
|
||||
@ -53,23 +52,23 @@ protected:
|
||||
void CheckLinkUds(const std::shared_ptr<PasteDataEntry> entry);
|
||||
void CheckCustomEntry(const std::shared_ptr<PasteDataEntry> entry);
|
||||
|
||||
void InitDataWithEntries(UDMF::UnifiedData& data);
|
||||
void InitDataWithPlainEntry(UDMF::UnifiedData& data);
|
||||
void InitDataWithHtmlEntry(UDMF::UnifiedData& data);
|
||||
void InitDataWithFileUriEntry(UDMF::UnifiedData& data);
|
||||
void InitDataWithPixelMapEntry(UDMF::UnifiedData& data);
|
||||
void InitDataWitCustomEntry(UDMF::UnifiedData& data);
|
||||
void InitDataWitSameCustomEntry(UDMF::UnifiedData& data);
|
||||
void InitDataWithEntries(UDMF::UnifiedData &data);
|
||||
void InitDataWithPlainEntry(UDMF::UnifiedData &data);
|
||||
void InitDataWithHtmlEntry(UDMF::UnifiedData &data);
|
||||
void InitDataWithFileUriEntry(UDMF::UnifiedData &data);
|
||||
void InitDataWithPixelMapEntry(UDMF::UnifiedData &data);
|
||||
void InitDataWitCustomEntry(UDMF::UnifiedData &data);
|
||||
void InitDataWitSameCustomEntry(UDMF::UnifiedData &data);
|
||||
|
||||
void AddPlainUdsEntry(UDMF::UnifiedRecord& record);
|
||||
void AddFileUriUdsEntry(UDMF::UnifiedRecord& record);
|
||||
void AddHtmlUdsEntry(UDMF::UnifiedRecord& record);
|
||||
void AddPixelMapUdsEntry(UDMF::UnifiedRecord& record);
|
||||
void AddLinkUdsEntry(UDMF::UnifiedRecord& record);
|
||||
void AddCustomEntry(UDMF::UnifiedRecord& record);
|
||||
void AddCustomEntries(UDMF::UnifiedRecord& record);
|
||||
void AddPlainUdsEntry(UDMF::UnifiedRecord &record);
|
||||
void AddFileUriUdsEntry(UDMF::UnifiedRecord &record);
|
||||
void AddHtmlUdsEntry(UDMF::UnifiedRecord &record);
|
||||
void AddPixelMapUdsEntry(UDMF::UnifiedRecord &record);
|
||||
void AddLinkUdsEntry(UDMF::UnifiedRecord &record);
|
||||
void AddCustomEntry(UDMF::UnifiedRecord &record);
|
||||
void AddCustomEntries(UDMF::UnifiedRecord &record);
|
||||
|
||||
static PasteData TlvData(const std::shared_ptr<PasteData>& data);
|
||||
static PasteData TlvData(const std::shared_ptr<PasteData> &data);
|
||||
};
|
||||
|
||||
void ConvertUtilsTest::SetUpTestCase(void) {}
|
||||
@ -80,7 +79,7 @@ void ConvertUtilsTest::SetUp(void) {}
|
||||
|
||||
void ConvertUtilsTest::TearDown(void) {}
|
||||
|
||||
PasteData ConvertUtilsTest::TlvData(const std::shared_ptr<PasteData>& data)
|
||||
PasteData ConvertUtilsTest::TlvData(const std::shared_ptr<PasteData> &data)
|
||||
{
|
||||
std::vector<std::uint8_t> buffer;
|
||||
data->Init(buffer);
|
||||
@ -90,7 +89,7 @@ PasteData ConvertUtilsTest::TlvData(const std::shared_ptr<PasteData>& data)
|
||||
return decodePasteData;
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::AddPlainUdsEntry(UDMF::UnifiedRecord& record)
|
||||
void ConvertUtilsTest::AddPlainUdsEntry(UDMF::UnifiedRecord &record)
|
||||
{
|
||||
Object plainUds;
|
||||
auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::PLAIN_TEXT);
|
||||
@ -99,7 +98,7 @@ void ConvertUtilsTest::AddPlainUdsEntry(UDMF::UnifiedRecord& record)
|
||||
record.AddEntry(utdId, std::make_shared<Object>(plainUds));
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::AddFileUriUdsEntry(UDMF::UnifiedRecord& record)
|
||||
void ConvertUtilsTest::AddFileUriUdsEntry(UDMF::UnifiedRecord &record)
|
||||
{
|
||||
Object fileUriobject;
|
||||
auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::FILE_URI);
|
||||
@ -109,7 +108,7 @@ void ConvertUtilsTest::AddFileUriUdsEntry(UDMF::UnifiedRecord& record)
|
||||
record.AddEntry(utdId, std::make_shared<Object>(fileUriobject));
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::AddHtmlUdsEntry(UDMF::UnifiedRecord& record)
|
||||
void ConvertUtilsTest::AddHtmlUdsEntry(UDMF::UnifiedRecord &record)
|
||||
{
|
||||
auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::HTML);
|
||||
Object htmlobject;
|
||||
@ -118,7 +117,7 @@ void ConvertUtilsTest::AddHtmlUdsEntry(UDMF::UnifiedRecord& record)
|
||||
record.AddEntry(utdId, std::make_shared<Object>(htmlobject));
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::AddLinkUdsEntry(UDMF::UnifiedRecord& record)
|
||||
void ConvertUtilsTest::AddLinkUdsEntry(UDMF::UnifiedRecord &record)
|
||||
{
|
||||
auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::HYPERLINK);
|
||||
Object linkObject;
|
||||
@ -127,18 +126,18 @@ void ConvertUtilsTest::AddLinkUdsEntry(UDMF::UnifiedRecord& record)
|
||||
record.AddEntry(utdId, std::make_shared<Object>(linkObject));
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::AddCustomEntry(UDMF::UnifiedRecord& record)
|
||||
void ConvertUtilsTest::AddCustomEntry(UDMF::UnifiedRecord &record)
|
||||
{
|
||||
record.AddEntry(appUtdId1_, rawData1_);
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::AddCustomEntries(UDMF::UnifiedRecord& record)
|
||||
void ConvertUtilsTest::AddCustomEntries(UDMF::UnifiedRecord &record)
|
||||
{
|
||||
record.AddEntry(appUtdId1_, rawData1_);
|
||||
record.AddEntry(appUtdId2_, rawData2_);
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::AddPixelMapUdsEntry(UDMF::UnifiedRecord& record)
|
||||
void ConvertUtilsTest::AddPixelMapUdsEntry(UDMF::UnifiedRecord &record)
|
||||
{
|
||||
auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::SYSTEM_DEFINED_PIXEL_MAP);
|
||||
Object object;
|
||||
@ -151,7 +150,7 @@ void ConvertUtilsTest::AddPixelMapUdsEntry(UDMF::UnifiedRecord& record)
|
||||
record.AddEntry(utdId, std::make_shared<Object>(object));
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::InitDataWithPlainEntry(UDMF::UnifiedData& data)
|
||||
void ConvertUtilsTest::InitDataWithPlainEntry(UDMF::UnifiedData &data)
|
||||
{
|
||||
std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
|
||||
AddPlainUdsEntry(*record);
|
||||
@ -162,7 +161,7 @@ void ConvertUtilsTest::InitDataWithPlainEntry(UDMF::UnifiedData& data)
|
||||
ASSERT_EQ(1, entriesSize);
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::InitDataWithHtmlEntry(UDMF::UnifiedData& data)
|
||||
void ConvertUtilsTest::InitDataWithHtmlEntry(UDMF::UnifiedData &data)
|
||||
{
|
||||
std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
|
||||
AddHtmlUdsEntry(*record);
|
||||
@ -173,7 +172,7 @@ void ConvertUtilsTest::InitDataWithHtmlEntry(UDMF::UnifiedData& data)
|
||||
ASSERT_EQ(1, entriesSize);
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::InitDataWithFileUriEntry(UDMF::UnifiedData& data)
|
||||
void ConvertUtilsTest::InitDataWithFileUriEntry(UDMF::UnifiedData &data)
|
||||
{
|
||||
std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
|
||||
AddFileUriUdsEntry(*record);
|
||||
@ -184,7 +183,7 @@ void ConvertUtilsTest::InitDataWithFileUriEntry(UDMF::UnifiedData& data)
|
||||
ASSERT_EQ(1, entriesSize);
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::InitDataWithPixelMapEntry(UDMF::UnifiedData& data)
|
||||
void ConvertUtilsTest::InitDataWithPixelMapEntry(UDMF::UnifiedData &data)
|
||||
{
|
||||
std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
|
||||
AddPixelMapUdsEntry(*record);
|
||||
@ -195,7 +194,7 @@ void ConvertUtilsTest::InitDataWithPixelMapEntry(UDMF::UnifiedData& data)
|
||||
ASSERT_EQ(1, entriesSize);
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::InitDataWitCustomEntry(UDMF::UnifiedData& data)
|
||||
void ConvertUtilsTest::InitDataWitCustomEntry(UDMF::UnifiedData &data)
|
||||
{
|
||||
std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
|
||||
AddCustomEntry(*record);
|
||||
@ -206,7 +205,7 @@ void ConvertUtilsTest::InitDataWitCustomEntry(UDMF::UnifiedData& data)
|
||||
ASSERT_EQ(1, entriesSize);
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::InitDataWitSameCustomEntry(UDMF::UnifiedData& data)
|
||||
void ConvertUtilsTest::InitDataWitSameCustomEntry(UDMF::UnifiedData &data)
|
||||
{
|
||||
std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
|
||||
AddCustomEntry(*record);
|
||||
@ -218,7 +217,7 @@ void ConvertUtilsTest::InitDataWitSameCustomEntry(UDMF::UnifiedData& data)
|
||||
ASSERT_EQ(1, entriesSize);
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::InitDataWithEntries(UDMF::UnifiedData& data)
|
||||
void ConvertUtilsTest::InitDataWithEntries(UDMF::UnifiedData &data)
|
||||
{
|
||||
std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
|
||||
AddPlainUdsEntry(*record);
|
||||
@ -233,9 +232,9 @@ void ConvertUtilsTest::InitDataWithEntries(UDMF::UnifiedData& data)
|
||||
ASSERT_EQ(1, size);
|
||||
}
|
||||
|
||||
void ConvertUtilsTest::CheckEntries(const std::vector<std::shared_ptr<PasteDataEntry>>& entries)
|
||||
void ConvertUtilsTest::CheckEntries(const std::vector<std::shared_ptr<PasteDataEntry>> &entries)
|
||||
{
|
||||
for (auto const& entry : entries) {
|
||||
for (auto const &entry : entries) {
|
||||
if (entry->GetUtdId() == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::PLAIN_TEXT)) {
|
||||
CheckPlainUds(entry);
|
||||
} else if (entry->GetUtdId() == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::FILE_URI)) {
|
||||
|
@ -13,9 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "device/dm_adapter.h"
|
||||
#include "distributed_clip.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include "pasteboard_error.h"
|
||||
|
||||
namespace OHOS::MiscServices {
|
||||
@ -28,21 +29,13 @@ public:
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void DMAdapterTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
void DMAdapterTest::SetUpTestCase(void) {}
|
||||
|
||||
void DMAdapterTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
void DMAdapterTest::TearDownTestCase(void) {}
|
||||
|
||||
void DMAdapterTest::SetUp(void)
|
||||
{
|
||||
}
|
||||
void DMAdapterTest::SetUp(void) {}
|
||||
|
||||
void DMAdapterTest::TearDown(void)
|
||||
{
|
||||
}
|
||||
void DMAdapterTest::TearDown(void) {}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLocalDeviceUdid
|
||||
@ -138,4 +131,4 @@ HWTEST_F(DMAdapterTest, IsSameAccount, TestSize.Level0)
|
||||
bool ret = DMAdapter::GetInstance().IsSameAccount(networkId);
|
||||
ASSERT_FALSE(ret);
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::MiscServices
|
||||
|
@ -13,10 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "eventcenter/event_center.h"
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "eventcenter/event_center.h"
|
||||
|
||||
namespace OHOS::MiscServices {
|
||||
using namespace testing::ext;
|
||||
using namespace testing;
|
||||
@ -30,15 +31,15 @@ public:
|
||||
};
|
||||
class TestBegin : public Event {
|
||||
public:
|
||||
TestBegin(): Event(TEST_EVT_BEGIN) {};
|
||||
TestBegin() : Event(TEST_EVT_BEGIN){};
|
||||
};
|
||||
class TestMiddle : public Event {
|
||||
public:
|
||||
TestMiddle(): Event(TEST_EVT_MIDDLE) {};
|
||||
TestMiddle() : Event(TEST_EVT_MIDDLE){};
|
||||
};
|
||||
class TestEnd : public Event {
|
||||
public:
|
||||
TestEnd(): Event(TEST_EVT_END) {};
|
||||
TestEnd() : Event(TEST_EVT_END){};
|
||||
};
|
||||
static void SetUpTestCase(void) {}
|
||||
static void TearDownTestCase(void) {}
|
||||
@ -135,7 +136,6 @@ HWTEST_F(EventCenterTest, ASyncEventWithoutDefer, TestSize.Level2)
|
||||
ASSERT_EQ(waitEvent_, TEST_EVT_BEGIN);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @tc.name: ImmediatelyASyncEvent
|
||||
* @tc.desc: post the async event, there is top layer and no defer; we will dispatch the async event Immediately.
|
||||
|
@ -13,9 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ffrt_utils.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "ffrt_utils.h"
|
||||
|
||||
namespace OHOS::MiscServices {
|
||||
using namespace testing::ext;
|
||||
using namespace testing;
|
||||
@ -28,21 +29,13 @@ public:
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void FFRTTimerTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
void FFRTTimerTest::SetUpTestCase(void) {}
|
||||
|
||||
void FFRTTimerTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
void FFRTTimerTest::TearDownTestCase(void) {}
|
||||
|
||||
void FFRTTimerTest::SetUp(void)
|
||||
{
|
||||
}
|
||||
void FFRTTimerTest::SetUp(void) {}
|
||||
|
||||
void FFRTTimerTest::TearDown(void)
|
||||
{
|
||||
}
|
||||
void FFRTTimerTest::TearDown(void) {}
|
||||
|
||||
/**
|
||||
* @tc.name: SetTimerTest001
|
||||
|
@ -13,8 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "convert_utils.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "convert_utils.h"
|
||||
#include "unified_meta.h"
|
||||
|
||||
namespace OHOS::MiscServices {
|
||||
@ -57,7 +58,7 @@ PasteDataEntry PasteDataEntryTest::InitPlaintTextEntry()
|
||||
auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::PLAIN_TEXT);
|
||||
udsObject->value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
|
||||
udsObject->value_[UDMF::CONTENT] = text_;
|
||||
return {utdId, udsObject};
|
||||
return { utdId, udsObject };
|
||||
}
|
||||
|
||||
PasteDataEntry PasteDataEntryTest::InitUriEntry()
|
||||
@ -67,7 +68,7 @@ PasteDataEntry PasteDataEntryTest::InitUriEntry()
|
||||
udsObject->value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
|
||||
udsObject->value_[UDMF::FILE_URI_PARAM] = uri_;
|
||||
udsObject->value_[UDMF::FILE_TYPE] = "";
|
||||
return {utdId, udsObject};
|
||||
return { utdId, udsObject };
|
||||
}
|
||||
|
||||
PasteDataEntry PasteDataEntryTest::InitWantEntry()
|
||||
@ -79,7 +80,7 @@ PasteDataEntry PasteDataEntryTest::InitWantEntry()
|
||||
int32_t idValue = 123;
|
||||
std::string deviceKey = "deviceId_key";
|
||||
want->SetParam(idKey, idValue);
|
||||
return {utdId, want};
|
||||
return { utdId, want };
|
||||
}
|
||||
|
||||
PasteDataEntry PasteDataEntryTest::InitHtmlEntry()
|
||||
@ -88,7 +89,7 @@ PasteDataEntry PasteDataEntryTest::InitHtmlEntry()
|
||||
auto udsObject = std::make_shared<Object>();
|
||||
udsObject->value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
|
||||
udsObject->value_[UDMF::HTML_CONTENT] = html_;
|
||||
return {utdId, udsObject};
|
||||
return { utdId, udsObject };
|
||||
}
|
||||
|
||||
PasteDataEntry PasteDataEntryTest::InitPixelMapEntry()
|
||||
@ -101,10 +102,9 @@ PasteDataEntry PasteDataEntryTest::InitPixelMapEntry()
|
||||
std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts);
|
||||
std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
|
||||
udsObject->value_[UDMF::PIXEL_MAP] = pixelMapIn;
|
||||
return {utdId, udsObject};
|
||||
return { utdId, udsObject };
|
||||
}
|
||||
|
||||
|
||||
void PasteDataEntryTest::CheckPlainUds(const std::shared_ptr<PasteDataEntry> entry)
|
||||
{
|
||||
ASSERT_NE(entry, nullptr);
|
||||
|
@ -13,10 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "paste_data_record.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "paste_data_record.h"
|
||||
#include "tlv_object.h"
|
||||
#include "unified_meta.h"
|
||||
|
||||
@ -42,18 +41,18 @@ protected:
|
||||
int32_t width_ = 5;
|
||||
int32_t height_ = 7;
|
||||
|
||||
void CheckEntries(const std::vector<std::shared_ptr<PasteDataEntry>>& entries);
|
||||
void CheckEntries(const std::vector<std::shared_ptr<PasteDataEntry>> &entries);
|
||||
void CheckPlainUds(const std::shared_ptr<PasteDataEntry> entry);
|
||||
void CheckFileUriUds(const std::shared_ptr<PasteDataEntry> entry);
|
||||
void CheckPixelMapUds(const std::shared_ptr<PasteDataEntry> entry);
|
||||
void CheckHtmlUds(const std::shared_ptr<PasteDataEntry> entry);
|
||||
void CheckLinkUds(const std::shared_ptr<PasteDataEntry> entry);
|
||||
|
||||
void AddPlainUdsEntry(PasteDataRecord& record);
|
||||
void AddFileUriUdsEntry(PasteDataRecord& record);
|
||||
void AddHtmlUdsEntry(PasteDataRecord& record);
|
||||
void AddPixelMapUdsEntry(PasteDataRecord& record);
|
||||
void AddLinkUdsEntry(PasteDataRecord& record);
|
||||
void AddPlainUdsEntry(PasteDataRecord &record);
|
||||
void AddFileUriUdsEntry(PasteDataRecord &record);
|
||||
void AddHtmlUdsEntry(PasteDataRecord &record);
|
||||
void AddPixelMapUdsEntry(PasteDataRecord &record);
|
||||
void AddLinkUdsEntry(PasteDataRecord &record);
|
||||
};
|
||||
|
||||
void PasteDataRecordTest::SetUpTestCase(void) {}
|
||||
@ -72,7 +71,7 @@ void PasteDataRecordTest::SetUp(void)
|
||||
|
||||
void PasteDataRecordTest::TearDown(void) {}
|
||||
|
||||
void PasteDataRecordTest::AddPlainUdsEntry(PasteDataRecord& record)
|
||||
void PasteDataRecordTest::AddPlainUdsEntry(PasteDataRecord &record)
|
||||
{
|
||||
auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::PLAIN_TEXT);
|
||||
auto object = std::make_shared<Object>();
|
||||
@ -81,7 +80,7 @@ void PasteDataRecordTest::AddPlainUdsEntry(PasteDataRecord& record)
|
||||
record.AddEntry(utdId, std::make_shared<PasteDataEntry>(utdId, object));
|
||||
}
|
||||
|
||||
void PasteDataRecordTest::AddFileUriUdsEntry(PasteDataRecord& record)
|
||||
void PasteDataRecordTest::AddFileUriUdsEntry(PasteDataRecord &record)
|
||||
{
|
||||
auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::FILE_URI);
|
||||
auto object = std::make_shared<Object>();
|
||||
@ -91,7 +90,7 @@ void PasteDataRecordTest::AddFileUriUdsEntry(PasteDataRecord& record)
|
||||
record.AddEntry(utdId, std::make_shared<PasteDataEntry>(utdId, object));
|
||||
}
|
||||
|
||||
void PasteDataRecordTest::AddHtmlUdsEntry(PasteDataRecord& record)
|
||||
void PasteDataRecordTest::AddHtmlUdsEntry(PasteDataRecord &record)
|
||||
{
|
||||
auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::HTML);
|
||||
auto object = std::make_shared<Object>();
|
||||
@ -100,7 +99,7 @@ void PasteDataRecordTest::AddHtmlUdsEntry(PasteDataRecord& record)
|
||||
record.AddEntry(utdId, std::make_shared<PasteDataEntry>(utdId, object));
|
||||
}
|
||||
|
||||
void PasteDataRecordTest::AddLinkUdsEntry(PasteDataRecord& record)
|
||||
void PasteDataRecordTest::AddLinkUdsEntry(PasteDataRecord &record)
|
||||
{
|
||||
auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::HYPERLINK);
|
||||
auto object = std::make_shared<Object>();
|
||||
@ -109,7 +108,7 @@ void PasteDataRecordTest::AddLinkUdsEntry(PasteDataRecord& record)
|
||||
record.AddEntry(utdId, std::make_shared<PasteDataEntry>(utdId, object));
|
||||
}
|
||||
|
||||
void PasteDataRecordTest::AddPixelMapUdsEntry(PasteDataRecord& record)
|
||||
void PasteDataRecordTest::AddPixelMapUdsEntry(PasteDataRecord &record)
|
||||
{
|
||||
auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::SYSTEM_DEFINED_PIXEL_MAP);
|
||||
auto object = std::make_shared<Object>();
|
||||
@ -122,9 +121,9 @@ void PasteDataRecordTest::AddPixelMapUdsEntry(PasteDataRecord& record)
|
||||
record.AddEntry(utdId, std::make_shared<PasteDataEntry>(utdId, object));
|
||||
}
|
||||
|
||||
void PasteDataRecordTest::CheckEntries(const std::vector<std::shared_ptr<PasteDataEntry>>& entries)
|
||||
void PasteDataRecordTest::CheckEntries(const std::vector<std::shared_ptr<PasteDataEntry>> &entries)
|
||||
{
|
||||
for (auto const& entry : entries) {
|
||||
for (auto const &entry : entries) {
|
||||
if (entry->GetUtdId() == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::PLAIN_TEXT)) {
|
||||
CheckPlainUds(entry);
|
||||
}
|
||||
|
@ -13,17 +13,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <cstdio>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "copy_uri_handler.h"
|
||||
#include "common/block_object.h"
|
||||
#include "clip/clip_plugin.h"
|
||||
#include "clip_factory.h"
|
||||
#include "common/block_object.h"
|
||||
#include "copy_uri_handler.h"
|
||||
#include "int_wrapper.h"
|
||||
#include "paste_uri_handler.h"
|
||||
#include "pasteboard_client.h"
|
||||
#include "remote_file_share.h"
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS::MiscServices {
|
||||
using namespace testing::ext;
|
||||
@ -40,21 +40,13 @@ public:
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void PasteDataTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
void PasteDataTest::SetUpTestCase(void) {}
|
||||
|
||||
void PasteDataTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
void PasteDataTest::TearDownTestCase(void) {}
|
||||
|
||||
void PasteDataTest::SetUp(void)
|
||||
{
|
||||
}
|
||||
void PasteDataTest::SetUp(void) {}
|
||||
|
||||
void PasteDataTest::TearDown(void)
|
||||
{
|
||||
}
|
||||
void PasteDataTest::TearDown(void) {}
|
||||
|
||||
ClipFactory::ClipFactory()
|
||||
{
|
||||
@ -345,8 +337,7 @@ HWTEST_F(PasteDataTest, MaxLength001, TestSize.Level0)
|
||||
int maxLength = 20 * 1024 * 1024;
|
||||
std::string res = "hello";
|
||||
std::string temp = "world";
|
||||
for (int i = 0; i < maxLength; i++)
|
||||
{
|
||||
for (int i = 0; i < maxLength; i++) {
|
||||
res += temp;
|
||||
}
|
||||
std::string htmlText = "<div class='disabled'>" + res + "</div>";
|
||||
@ -366,8 +357,7 @@ HWTEST_F(PasteDataTest, MaxLength002, TestSize.Level0)
|
||||
int maxLength = 20 * 1024 * 1024;
|
||||
std::string plainText = "hello";
|
||||
std::string temp = "world";
|
||||
for (int i = 0; i < maxLength; i++)
|
||||
{
|
||||
for (int i = 0; i < maxLength; i++) {
|
||||
plainText += temp;
|
||||
}
|
||||
auto record = PasteboardClient::GetInstance()->CreatePlainTextRecord(plainText);
|
||||
@ -491,7 +481,7 @@ HWTEST_F(PasteDataTest, GetPasteDataMsg002, TestSize.Level0)
|
||||
ASSERT_TRUE(primaryUri == nullptr);
|
||||
auto record = newPasteData->GetRecordAt(1);
|
||||
ASSERT_TRUE(record == nullptr);
|
||||
auto res1 = newPasteData->RemoveRecordAt(1);
|
||||
auto res1 = newPasteData->RemoveRecordAt(1);
|
||||
ASSERT_FALSE(res1);
|
||||
std::string mimeType = "text/plain";
|
||||
ASSERT_FALSE(newPasteData->HasMimeType(mimeType));
|
||||
|
@ -13,9 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "pasteboard_client.h"
|
||||
#include "unistd.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS::MiscServices {
|
||||
using namespace testing::ext;
|
||||
@ -41,13 +42,9 @@ void PasteboardClientTest::TearDownTestCase(void)
|
||||
setuid(0);
|
||||
}
|
||||
|
||||
void PasteboardClientTest::SetUp(void)
|
||||
{
|
||||
}
|
||||
void PasteboardClientTest::SetUp(void) {}
|
||||
|
||||
void PasteboardClientTest::TearDown(void)
|
||||
{
|
||||
}
|
||||
void PasteboardClientTest::TearDown(void) {}
|
||||
|
||||
/**
|
||||
* @tc.name: IsRemoteData001
|
||||
@ -183,24 +180,21 @@ HWTEST_F(PasteboardClientTest, GetDataSource001, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(PasteboardClientTest, SetGlobalShareOption, TestSize.Level0)
|
||||
{
|
||||
std::map<uint32_t, ShareOption> settings = {
|
||||
{100, ShareOption::InApp},
|
||||
{200, ShareOption::LocalDevice},
|
||||
{300, ShareOption::CrossDevice}};
|
||||
std::map<uint32_t, ShareOption> settings = { { 100, ShareOption::InApp }, { 200, ShareOption::LocalDevice },
|
||||
{ 300, ShareOption::CrossDevice } };
|
||||
PasteboardClient::GetInstance()->SetGlobalShareOption(settings);
|
||||
auto result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
|
||||
EXPECT_TRUE(result.size() == 3);
|
||||
EXPECT_EQ(result[100], ShareOption::InApp);
|
||||
EXPECT_EQ(result[200], ShareOption::LocalDevice);
|
||||
EXPECT_EQ(result[300], ShareOption::CrossDevice);
|
||||
std::map<uint32_t, ShareOption> modify = {{100, ShareOption::CrossDevice},
|
||||
{400, ShareOption::InApp}};
|
||||
std::map<uint32_t, ShareOption> modify = { { 100, ShareOption::CrossDevice }, { 400, ShareOption::InApp } };
|
||||
PasteboardClient::GetInstance()->SetGlobalShareOption(modify);
|
||||
result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
|
||||
EXPECT_TRUE(result.size() == 4);
|
||||
EXPECT_EQ(result[100], ShareOption::CrossDevice);
|
||||
EXPECT_EQ(result[400], ShareOption::InApp);
|
||||
PasteboardClient::GetInstance()->RemoveGlobalShareOption({100, 200, 300, 400});
|
||||
PasteboardClient::GetInstance()->RemoveGlobalShareOption({ 100, 200, 300, 400 });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -212,21 +206,19 @@ HWTEST_F(PasteboardClientTest, SetGlobalShareOption, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(PasteboardClientTest, GetGlobalShareOption, TestSize.Level0)
|
||||
{
|
||||
std::map<uint32_t, ShareOption> settings = {
|
||||
{100, ShareOption::InApp},
|
||||
{200, ShareOption::LocalDevice},
|
||||
{300, ShareOption::CrossDevice}};
|
||||
std::map<uint32_t, ShareOption> settings = { { 100, ShareOption::InApp }, { 200, ShareOption::LocalDevice },
|
||||
{ 300, ShareOption::CrossDevice } };
|
||||
PasteboardClient::GetInstance()->SetGlobalShareOption(settings);
|
||||
auto result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
|
||||
EXPECT_TRUE(result.size() == 3);
|
||||
EXPECT_EQ(result[100], ShareOption::InApp);
|
||||
EXPECT_EQ(result[200], ShareOption::LocalDevice);
|
||||
EXPECT_EQ(result[300], ShareOption::CrossDevice);
|
||||
result = PasteboardClient::GetInstance()->GetGlobalShareOption({100, 400});
|
||||
result = PasteboardClient::GetInstance()->GetGlobalShareOption({ 100, 400 });
|
||||
EXPECT_TRUE(result.size() == 1);
|
||||
EXPECT_EQ(result[100], ShareOption::InApp);
|
||||
EXPECT_TRUE(result.find(400) == result.end());
|
||||
PasteboardClient::GetInstance()->RemoveGlobalShareOption({100, 200, 300});
|
||||
PasteboardClient::GetInstance()->RemoveGlobalShareOption({ 100, 200, 300 });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -238,10 +230,8 @@ HWTEST_F(PasteboardClientTest, GetGlobalShareOption, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(PasteboardClientTest, RemoveGlobalShareOption, TestSize.Level0)
|
||||
{
|
||||
std::map<uint32_t, ShareOption> settings = {
|
||||
{100, ShareOption::InApp},
|
||||
{200, ShareOption::LocalDevice},
|
||||
{300, ShareOption::CrossDevice}};
|
||||
std::map<uint32_t, ShareOption> settings = { { 100, ShareOption::InApp }, { 200, ShareOption::LocalDevice },
|
||||
{ 300, ShareOption::CrossDevice } };
|
||||
PasteboardClient::GetInstance()->SetGlobalShareOption(settings);
|
||||
auto result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
|
||||
EXPECT_TRUE(result.size() == 3);
|
||||
@ -251,11 +241,11 @@ HWTEST_F(PasteboardClientTest, RemoveGlobalShareOption, TestSize.Level0)
|
||||
PasteboardClient::GetInstance()->RemoveGlobalShareOption({});
|
||||
result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
|
||||
EXPECT_TRUE(result.size() == 3);
|
||||
PasteboardClient::GetInstance()->RemoveGlobalShareOption({100, 400});
|
||||
PasteboardClient::GetInstance()->RemoveGlobalShareOption({ 100, 400 });
|
||||
result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
|
||||
EXPECT_TRUE(result.size() == 2);
|
||||
EXPECT_TRUE(result.find(100) == result.end());
|
||||
PasteboardClient::GetInstance()->RemoveGlobalShareOption({200, 300});
|
||||
PasteboardClient::GetInstance()->RemoveGlobalShareOption({ 200, 300 });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -268,39 +258,26 @@ HWTEST_F(PasteboardClientTest, RemoveGlobalShareOption, TestSize.Level0)
|
||||
HWTEST_F(PasteboardClientTest, DetectPatterns001, TestSize.Level0)
|
||||
{
|
||||
std::string plainText("r法塔赫已经,速tdghf!】qd rqdswww.comsski,.sjopwe"
|
||||
"ihhtpsdhttp我也带过去给他№のjioijhhu");
|
||||
"ihhtpsdhttp我也带过去给他№のjioijhhu");
|
||||
std::string plainText0("https://giedqwrtheeeeeefub.cerm/meeeelkove/obaklo_tjokl"
|
||||
"psetkjdttk/bkkjob/mwjweww.md)");
|
||||
"psetkjdttk/bkkjob/mwjweww.md)");
|
||||
std::string plainText1("2我就破888芙蓉王82h7");
|
||||
std::string plainText2("uhiyqydueuw@kahqw.oisko.sji");
|
||||
|
||||
std::vector<std::string> plainTextVec{
|
||||
plainText, plainText+plainText0, plainText+plainText1, plainText+plainText2,
|
||||
plainText+plainText0+plainText1, plainText0+plainText2+plainText, plainText1+plainText+plainText2,
|
||||
plainText0+plainText1+plainText+plainText2
|
||||
};
|
||||
std::vector<Patterns> patternsVec{
|
||||
{}, {Pattern::URL}, {Pattern::Number}, {Pattern::EmailAddress},
|
||||
{Pattern::URL, Pattern::Number}, {Pattern::URL, Pattern::EmailAddress},
|
||||
{Pattern::Number, Pattern::EmailAddress}, {Pattern::URL, Pattern::Number, Pattern::EmailAddress}
|
||||
};
|
||||
std::vector<std::vector<int>> patternsRightIndexVec{
|
||||
{0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{0, 1, 0, 0, 1, 1, 0, 1},
|
||||
{0, 0, 2, 0, 2, 0, 2, 2},
|
||||
{0, 0, 0, 3, 0, 3, 3, 3},
|
||||
{0, 1, 2, 0, 4, 1, 2, 4},
|
||||
{0, 1, 0, 3, 1, 5, 3, 5},
|
||||
{0, 0, 2, 3, 2, 3, 6, 6},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7}
|
||||
};
|
||||
std::vector<std::string> plainTextVec{ plainText, plainText + plainText0, plainText + plainText1,
|
||||
plainText + plainText2, plainText + plainText0 + plainText1, plainText0 + plainText2 + plainText,
|
||||
plainText1 + plainText + plainText2, plainText0 + plainText1 + plainText + plainText2 };
|
||||
std::vector<Patterns> patternsVec{ {}, { Pattern::URL }, { Pattern::Number }, { Pattern::EmailAddress },
|
||||
{ Pattern::URL, Pattern::Number }, { Pattern::URL, Pattern::EmailAddress },
|
||||
{ Pattern::Number, Pattern::EmailAddress }, { Pattern::URL, Pattern::Number, Pattern::EmailAddress } };
|
||||
std::vector<std::vector<int>> patternsRightIndexVec{ { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1, 0, 0, 1, 1, 0, 1 },
|
||||
{ 0, 0, 2, 0, 2, 0, 2, 2 }, { 0, 0, 0, 3, 0, 3, 3, 3 }, { 0, 1, 2, 0, 4, 1, 2, 4 }, { 0, 1, 0, 3, 1, 5, 3, 5 },
|
||||
{ 0, 0, 2, 3, 2, 3, 6, 6 }, { 0, 1, 2, 3, 4, 5, 6, 7 } };
|
||||
for (int i = 0; i != 8; ++i) {
|
||||
for (int j = 0; j != 8; ++j) {
|
||||
auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(
|
||||
plainTextVec[i]);
|
||||
auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainTextVec[i]);
|
||||
PasteboardClient::GetInstance()->SetPasteData(*newData);
|
||||
auto ret = PasteboardClient::GetInstance()->DetectPatterns(
|
||||
patternsVec[j]);
|
||||
auto ret = PasteboardClient::GetInstance()->DetectPatterns(patternsVec[j]);
|
||||
int rightIndex = patternsRightIndexVec[i][j];
|
||||
ASSERT_EQ(ret, patternsVec[rightIndex]);
|
||||
}
|
||||
@ -317,25 +294,26 @@ HWTEST_F(PasteboardClientTest, DetectPatterns001, TestSize.Level0)
|
||||
HWTEST_F(PasteboardClientTest, DetectPatterns002, TestSize.Level0)
|
||||
{
|
||||
std::string htmlText1 = "<!DOCTYPE html><html><head><title>"
|
||||
"超链案头研究。,封为啊啊</title></head><body><h2>发高热</h2>"
|
||||
"<p>隔热隔热的氛围<a href=\"https://exq23amwerwqple.com\">"
|
||||
"个人网站https://ex24t33tamp65hhle.com</a>。</p></body></html>";
|
||||
"超链案头研究。,封为啊啊</title></head><body><h2>发高热</h2>"
|
||||
"<p>隔热隔热的氛围<a href=\"https://exq23amwerwqple.com\">"
|
||||
"个人网站https://ex24t33tamp65hhle.com</a>。</p></body></html>";
|
||||
auto newData1 = PasteboardClient::GetInstance()->CreateHtmlData(htmlText1);
|
||||
PasteboardClient::GetInstance()->SetPasteData(*newData1);
|
||||
Patterns patternsToCheck1{Pattern::URL, Pattern::EmailAddress};
|
||||
Patterns patternsToCheck1{ Pattern::URL, Pattern::EmailAddress };
|
||||
auto ret1 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck1);
|
||||
Patterns expected1{Pattern::URL};
|
||||
Patterns expected1{ Pattern::URL };
|
||||
ASSERT_EQ(ret1, expected1);
|
||||
|
||||
std::string htmlText2 = "<!DOCTYPE html><html><head><title>"
|
||||
"各个环节</title></head><body><h2>妈妈那边的</h2>"
|
||||
"<p>啊啊分,凤凰方法,环境https://examjjuyewple.com问我的<a href=\"https://ehhgxametgeple.com\">"
|
||||
"阿婆吗weqkqo@exaetmple.com</a>。????打法</p></body></html>";
|
||||
"各个环节</title></head><body><h2>妈妈那边的</h2>"
|
||||
"<p>啊啊分,凤凰方法,环境https://examjjuyewple.com问我的<a "
|
||||
"href=\"https://ehhgxametgeple.com\">"
|
||||
"阿婆吗weqkqo@exaetmple.com</a>。????打法</p></body></html>";
|
||||
auto newData2 = PasteboardClient::GetInstance()->CreateHtmlData(htmlText2);
|
||||
PasteboardClient::GetInstance()->SetPasteData(*newData2);
|
||||
Patterns patternsToCheck2{Pattern::URL, Pattern::EmailAddress, Pattern::Number};
|
||||
Patterns patternsToCheck2{ Pattern::URL, Pattern::EmailAddress, Pattern::Number };
|
||||
auto ret2 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck2);
|
||||
Patterns expected2{Pattern::URL, Pattern::EmailAddress};
|
||||
Patterns expected2{ Pattern::URL, Pattern::EmailAddress };
|
||||
ASSERT_EQ(ret2, expected2);
|
||||
}
|
||||
|
||||
@ -349,28 +327,28 @@ HWTEST_F(PasteboardClientTest, DetectPatterns002, TestSize.Level0)
|
||||
HWTEST_F(PasteboardClientTest, DetectPatterns003, TestSize.Level0)
|
||||
{
|
||||
std::string plainText1 = "部分人的十点半:\n"
|
||||
"「而飞过海」\n"
|
||||
"方法:\n"
|
||||
"https://pr5yyye-drseyive.u54yk.cwerfe/s/42e1ewed77f3dab4"
|
||||
"网gest加尔文iqru发的我ui哦计划任务i文化人:\n"
|
||||
"~b0043fg3423tddj~";
|
||||
"「而飞过海」\n"
|
||||
"方法:\n"
|
||||
"https://pr5yyye-drseyive.u54yk.cwerfe/s/42e1ewed77f3dab4"
|
||||
"网gest加尔文iqru发的我ui哦计划任务i文化人:\n"
|
||||
"~b0043fg3423tddj~";
|
||||
auto newData1 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText1);
|
||||
PasteboardClient::GetInstance()->SetPasteData(*newData1);
|
||||
Patterns patternsToCheck{
|
||||
Pattern::Number, Pattern::URL, Pattern::EmailAddress, static_cast<Pattern>(1023)};
|
||||
Patterns patternsToCheck{ Pattern::Number, Pattern::URL, Pattern::EmailAddress, static_cast<Pattern>(1023) };
|
||||
auto ret1 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
|
||||
Patterns expected1{};
|
||||
ASSERT_EQ(ret1, expected1);
|
||||
std::string plainText2 = "【撒迪化,等我i却很难,无穷花的!】"
|
||||
"额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg"
|
||||
"(¥¥软骨素用人员为bdfdgse https://tgrthwerrwt.com/marrkerrerlorrve/ usrdq12_22swe@16rtgre3.com)";
|
||||
"额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg"
|
||||
"(¥¥软骨素用人员为bdfdgse https://tgrthwerrwt.com/marrkerrerlorrve/ "
|
||||
"usrdq12_22swe@16rtgre3.com)";
|
||||
auto newData2 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText2);
|
||||
PasteboardClient::GetInstance()->SetPasteData(*newData2);
|
||||
auto ret2 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
|
||||
Patterns expected2{};
|
||||
ASSERT_EQ(ret2, expected2);
|
||||
std::string plainText3 = "【撒迪化,等我i却很难,无穷花的!】"
|
||||
"额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg";
|
||||
"额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg";
|
||||
auto newData3 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText3);
|
||||
PasteboardClient::GetInstance()->SetPasteData(*newData3);
|
||||
auto ret3 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
|
||||
@ -387,29 +365,29 @@ HWTEST_F(PasteboardClientTest, DetectPatterns003, TestSize.Level0)
|
||||
HWTEST_F(PasteboardClientTest, DetectPatterns004, TestSize.Level0)
|
||||
{
|
||||
std::string plainText1 = "部分人的十点半:\n"
|
||||
"「而飞过海」\n"
|
||||
"方法:\n"
|
||||
"https://pr5yyye-drseyive.u54yk.cwerfe/s/42e1ewed77f3dab4"
|
||||
"网gest加尔文iqru发的我ui哦计划任务i文化人:\n"
|
||||
"~b0043fg3423tddj~";
|
||||
"「而飞过海」\n"
|
||||
"方法:\n"
|
||||
"https://pr5yyye-drseyive.u54yk.cwerfe/s/42e1ewed77f3dab4"
|
||||
"网gest加尔文iqru发的我ui哦计划任务i文化人:\n"
|
||||
"~b0043fg3423tddj~";
|
||||
auto newData1 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText1);
|
||||
PasteboardClient::GetInstance()->SetPasteData(*newData1);
|
||||
std::set<Pattern> patternsToCheck{
|
||||
Pattern::Number, Pattern::URL, Pattern::EmailAddress,
|
||||
static_cast<Pattern>(0xffffffff), static_cast<Pattern>(0xffffff1a)};
|
||||
std::set<Pattern> patternsToCheck{ Pattern::Number, Pattern::URL, Pattern::EmailAddress,
|
||||
static_cast<Pattern>(0xffffffff), static_cast<Pattern>(0xffffff1a) };
|
||||
auto ret1 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
|
||||
std::set<Pattern> expected1{};
|
||||
ASSERT_EQ(ret1, expected1);
|
||||
std::string plainText2 = "【撒迪化,等我i却很难,无穷花的!】"
|
||||
"额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg"
|
||||
"(¥¥软骨素用人员为bdfdgse https://tgrthwerrwt.com/marrkerrerlorrve/ usrdq12_22swe@16rtgre3.com)";
|
||||
"额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg"
|
||||
"(¥¥软骨素用人员为bdfdgse https://tgrthwerrwt.com/marrkerrerlorrve/ "
|
||||
"usrdq12_22swe@16rtgre3.com)";
|
||||
auto newData2 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText2);
|
||||
PasteboardClient::GetInstance()->SetPasteData(*newData2);
|
||||
auto ret2 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
|
||||
std::set<Pattern> expected2{};
|
||||
ASSERT_EQ(ret2, expected2);
|
||||
std::string plainText3 = "【撒迪化,等我i却很难,无穷花的!】"
|
||||
"额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg";
|
||||
"额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg";
|
||||
auto newData3 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText3);
|
||||
PasteboardClient::GetInstance()->SetPasteData(*newData3);
|
||||
auto ret3 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
|
||||
|
@ -15,25 +15,24 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_error.h"
|
||||
|
||||
#include "application_defined_record.h"
|
||||
#include "audio.h"
|
||||
#include "folder.h"
|
||||
#include "html.h"
|
||||
#include "image.h"
|
||||
#include "link.h"
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_error.h"
|
||||
#include "pixel_map.h"
|
||||
#include "plain_text.h"
|
||||
#include "system_defined_appitem.h"
|
||||
#include "system_defined_form.h"
|
||||
#include "system_defined_record.h"
|
||||
#include "system_defined_pixelmap.h"
|
||||
#include "system_defined_record.h"
|
||||
#include "text.h"
|
||||
#include "unified_data.h"
|
||||
#include "unified_record.h"
|
||||
#include "video.h"
|
||||
#include "pixel_map.h"
|
||||
#include "want.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
@ -90,22 +89,16 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void PasteboardClientUdmfDelayTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
void PasteboardClientUdmfDelayTest::SetUpTestCase() {}
|
||||
|
||||
void PasteboardClientUdmfDelayTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
void PasteboardClientUdmfDelayTest::TearDownTestCase() {}
|
||||
|
||||
void PasteboardClientUdmfDelayTest::SetUp()
|
||||
{
|
||||
PasteboardClient::GetInstance()->Clear();
|
||||
}
|
||||
|
||||
void PasteboardClientUdmfDelayTest::TearDown()
|
||||
{
|
||||
}
|
||||
void PasteboardClientUdmfDelayTest::TearDown() {}
|
||||
|
||||
void PasteboardClientUdmfDelayTest::SetUnifiedData()
|
||||
{
|
||||
@ -830,7 +823,6 @@ HWTEST_F(PasteboardClientUdmfDelayTest, SetWantDataTest001, TestSize.Level1)
|
||||
auto deviceValue1 = (*(want))->GetStringParam("deviceId_key");
|
||||
ASSERT_EQ(deviceValue1, "deviceId_value");
|
||||
|
||||
|
||||
PasteData pasteData;
|
||||
status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
|
||||
ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
|
||||
@ -878,4 +870,4 @@ HWTEST_F(PasteboardClientUdmfDelayTest, SetPixelMapDataTest001, TestSize.Level1)
|
||||
ASSERT_EQ(imageInfo2.size.width, 5);
|
||||
ASSERT_EQ(imageInfo2.pixelFormat, PixelFormat::ARGB_8888);
|
||||
}
|
||||
} // OHOS::Test
|
||||
} // namespace OHOS::Test
|
@ -14,12 +14,11 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_error.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
|
||||
namespace OHOS::MiscServices {
|
||||
using namespace testing;
|
||||
@ -62,17 +61,11 @@ void PasteboardMultiTypeUnifiedDataDelayTest::SetUpTestCase(void)
|
||||
PasteboardClient::GetInstance()->Clear();
|
||||
}
|
||||
|
||||
void PasteboardMultiTypeUnifiedDataDelayTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
void PasteboardMultiTypeUnifiedDataDelayTest::TearDownTestCase(void) {}
|
||||
|
||||
void PasteboardMultiTypeUnifiedDataDelayTest::SetUp()
|
||||
{
|
||||
}
|
||||
void PasteboardMultiTypeUnifiedDataDelayTest::SetUp() {}
|
||||
|
||||
void PasteboardMultiTypeUnifiedDataDelayTest::TearDown()
|
||||
{
|
||||
}
|
||||
void PasteboardMultiTypeUnifiedDataDelayTest::TearDown() {}
|
||||
|
||||
UDMF::ValueType PasteboardMultiTypeUnifiedDataDelayTest::InitPlainUds()
|
||||
{
|
||||
@ -121,10 +114,10 @@ UDMF::ValueType PasteboardMultiTypeUnifiedDataDelayTest::InitLinkUds()
|
||||
|
||||
class EntryGetterImpl : public UDMF::EntryGetter {
|
||||
public:
|
||||
UDMF::ValueType GetValueByType(const std::string& utdId) override;
|
||||
UDMF::ValueType GetValueByType(const std::string &utdId) override;
|
||||
};
|
||||
|
||||
UDMF::ValueType EntryGetterImpl::GetValueByType(const std::string& utdId)
|
||||
UDMF::ValueType EntryGetterImpl::GetValueByType(const std::string &utdId)
|
||||
{
|
||||
if (utdId == plainTextUtdId_) {
|
||||
return PasteboardMultiTypeUnifiedDataDelayTest::InitPlainUds();
|
||||
@ -361,4 +354,4 @@ HWTEST_F(PasteboardMultiTypeUnifiedDataDelayTest, SetMultiTypeUnifiedDataDelayTe
|
||||
ASSERT_TRUE(outputTypes3.find(linkUtdId_) != outputTypes3.end());
|
||||
CheckLinkUds(outputRecord3->GetEntry(linkUtdId_));
|
||||
}
|
||||
} // OHOS::MiscServices
|
||||
} // namespace OHOS::MiscServices
|
@ -273,7 +273,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetText001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::TEXT);
|
||||
auto newPlainRecord = static_cast<UDMF::Text*>(newRecord.get());
|
||||
auto newPlainRecord = static_cast<UDMF::Text *>(newRecord.get());
|
||||
auto newDetails = newPlainRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
|
||||
@ -306,7 +306,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetPlainText001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::PLAIN_TEXT);
|
||||
auto newPlainRecord = static_cast<UDMF::PlainText*>(newRecord.get());
|
||||
auto newPlainRecord = static_cast<UDMF::PlainText *>(newRecord.get());
|
||||
auto newPlainText = newPlainRecord->GetContent();
|
||||
auto newAbstract = newPlainRecord->GetAbstract();
|
||||
auto newDetails = newPlainRecord->GetDetails();
|
||||
@ -346,7 +346,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetLink001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::HYPERLINK);
|
||||
auto newPlainRecord = static_cast<UDMF::Link*>(newRecord.get());
|
||||
auto newPlainRecord = static_cast<UDMF::Link *>(newRecord.get());
|
||||
auto newUrl = newPlainRecord->GetUrl();
|
||||
auto newDescription = newPlainRecord->GetDescription();
|
||||
auto newDetails = newPlainRecord->GetDetails();
|
||||
@ -386,7 +386,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetHtml001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::HTML);
|
||||
auto newPlainRecord = static_cast<UDMF::Html*>(newRecord.get());
|
||||
auto newPlainRecord = static_cast<UDMF::Html *>(newRecord.get());
|
||||
auto newPlainText = newPlainRecord->GetHtmlContent();
|
||||
auto newAbstract = newPlainRecord->GetPlainContent();
|
||||
auto newDetails = newPlainRecord->GetDetails();
|
||||
@ -463,7 +463,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetFile001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::FILE);
|
||||
auto newFileRecord = static_cast<UDMF::File*>(newRecord.get());
|
||||
auto newFileRecord = static_cast<UDMF::File *>(newRecord.get());
|
||||
auto newDetails = newFileRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
auto uri2 = newFileRecord->GetUri();
|
||||
@ -500,7 +500,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetImage001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::IMAGE);
|
||||
auto newImageRecord = static_cast<UDMF::Image*>(newRecord.get());
|
||||
auto newImageRecord = static_cast<UDMF::Image *>(newRecord.get());
|
||||
auto newDetails = newImageRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
auto uri2 = newImageRecord->GetUri();
|
||||
@ -537,7 +537,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetAudio001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::AUDIO);
|
||||
auto newAudioRecord = static_cast<UDMF::Audio*>(newRecord.get());
|
||||
auto newAudioRecord = static_cast<UDMF::Audio *>(newRecord.get());
|
||||
auto newDetails = newAudioRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
auto uri2 = newAudioRecord->GetUri();
|
||||
@ -574,7 +574,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetVideo001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::VIDEO);
|
||||
auto newVideoRecord = static_cast<UDMF::Video*>(newRecord.get());
|
||||
auto newVideoRecord = static_cast<UDMF::Video *>(newRecord.get());
|
||||
auto newDetails = newVideoRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
auto uri2 = newVideoRecord->GetUri();
|
||||
@ -611,7 +611,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetFolder001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::FOLDER);
|
||||
auto newFolderRecord = static_cast<UDMF::Folder*>(newRecord.get());
|
||||
auto newFolderRecord = static_cast<UDMF::Folder *>(newRecord.get());
|
||||
auto newDetails = newFolderRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
auto uri2 = newFolderRecord->GetUri();
|
||||
@ -648,7 +648,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetSystemDefined001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_RECORD);
|
||||
auto newSystemRecord = static_cast<UDMF::SystemDefinedRecord*>(newRecord.get());
|
||||
auto newSystemRecord = static_cast<UDMF::SystemDefinedRecord *>(newRecord.get());
|
||||
ASSERT_EQ(newSystemRecord->GetDetails(), details_);
|
||||
|
||||
PasteData pasteData;
|
||||
@ -681,7 +681,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetAppItem001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_APP_ITEM);
|
||||
auto newAppItem = static_cast<UDMF::SystemDefinedAppItem*>(newRecord.get());
|
||||
auto newAppItem = static_cast<UDMF::SystemDefinedAppItem *>(newRecord.get());
|
||||
ASSERT_EQ(newAppItem->GetAppId(), "appId");
|
||||
ASSERT_EQ(newAppItem->GetAppIconId(), "appIconId");
|
||||
ASSERT_EQ(newAppItem->GetAppName(), "appName");
|
||||
@ -729,7 +729,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetForm001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_FORM);
|
||||
auto newForm = static_cast<UDMF::SystemDefinedForm*>(newRecord.get());
|
||||
auto newForm = static_cast<UDMF::SystemDefinedForm *>(newRecord.get());
|
||||
ASSERT_EQ(newForm->GetFormId(), 1);
|
||||
ASSERT_EQ(newForm->GetFormName(), "formName");
|
||||
ASSERT_EQ(newForm->GetModule(), "module");
|
||||
@ -778,7 +778,7 @@ HWTEST_F(PasteboardUnifiedDataTest, SetAppDefined001, TestSize.Level0)
|
||||
auto newRecord = newData.GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::APPLICATION_DEFINED_RECORD);
|
||||
auto newSystemRecord = static_cast<UDMF::ApplicationDefinedRecord*>(newRecord.get());
|
||||
auto newSystemRecord = static_cast<UDMF::ApplicationDefinedRecord *>(newRecord.get());
|
||||
ASSERT_EQ(newSystemRecord->GetRawData(), rawData_);
|
||||
|
||||
PasteData pasteData;
|
||||
|
@ -13,8 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "pasteboard_utils.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "application_defined_record.h"
|
||||
@ -23,6 +21,7 @@
|
||||
#include "html.h"
|
||||
#include "image.h"
|
||||
#include "link.h"
|
||||
#include "pasteboard_utils.h"
|
||||
#include "plain_text.h"
|
||||
#include "system_defined_appitem.h"
|
||||
#include "system_defined_form.h"
|
||||
@ -286,7 +285,7 @@ HWTEST_F(PasteboardUtilsTest, Text2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::TEXT);
|
||||
auto newPlainRecord = static_cast<UDMF::Text*>(newRecord.get());
|
||||
auto newPlainRecord = static_cast<UDMF::Text *>(newRecord.get());
|
||||
auto newDetails = newPlainRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
}
|
||||
@ -319,7 +318,7 @@ HWTEST_F(PasteboardUtilsTest, PlainText2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::PLAIN_TEXT);
|
||||
auto newPlainRecord = static_cast<UDMF::PlainText*>(newRecord.get());
|
||||
auto newPlainRecord = static_cast<UDMF::PlainText *>(newRecord.get());
|
||||
auto newPlainText = newPlainRecord->GetContent();
|
||||
auto newAbstract = newPlainRecord->GetAbstract();
|
||||
auto newDetails = newPlainRecord->GetDetails();
|
||||
@ -358,7 +357,7 @@ HWTEST_F(PasteboardUtilsTest, Html2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::HTML);
|
||||
auto newPlainRecord = static_cast<UDMF::Html*>(newRecord.get());
|
||||
auto newPlainRecord = static_cast<UDMF::Html *>(newRecord.get());
|
||||
auto newPlainText = newPlainRecord->GetHtmlContent();
|
||||
auto newAbstract = newPlainRecord->GetPlainContent();
|
||||
auto newDetails = newPlainRecord->GetDetails();
|
||||
@ -395,7 +394,7 @@ HWTEST_F(PasteboardUtilsTest, Link2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::HYPERLINK);
|
||||
auto newPlainRecord = static_cast<UDMF::Link*>(newRecord.get());
|
||||
auto newPlainRecord = static_cast<UDMF::Link *>(newRecord.get());
|
||||
auto newUrl = newPlainRecord->GetUrl();
|
||||
auto newDescription = newPlainRecord->GetDescription();
|
||||
auto newDetails = newPlainRecord->GetDetails();
|
||||
@ -464,7 +463,7 @@ HWTEST_F(PasteboardUtilsTest, File2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::FILE);
|
||||
auto newFileRecord = static_cast<UDMF::File*>(newRecord.get());
|
||||
auto newFileRecord = static_cast<UDMF::File *>(newRecord.get());
|
||||
auto newDetails = newFileRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
auto uri2 = newFileRecord->GetUri();
|
||||
@ -498,7 +497,7 @@ HWTEST_F(PasteboardUtilsTest, Image2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::IMAGE);
|
||||
auto newImageRecord = static_cast<UDMF::Image*>(newRecord.get());
|
||||
auto newImageRecord = static_cast<UDMF::Image *>(newRecord.get());
|
||||
auto newDetails = newImageRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
auto uri2 = newImageRecord->GetUri();
|
||||
@ -532,7 +531,7 @@ HWTEST_F(PasteboardUtilsTest, Audio2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::AUDIO);
|
||||
auto newAudioRecord = static_cast<UDMF::Audio*>(newRecord.get());
|
||||
auto newAudioRecord = static_cast<UDMF::Audio *>(newRecord.get());
|
||||
auto newDetails = newAudioRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
auto uri2 = newAudioRecord->GetUri();
|
||||
@ -566,7 +565,7 @@ HWTEST_F(PasteboardUtilsTest, Video2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::VIDEO);
|
||||
auto newVideoRecord = static_cast<UDMF::Video*>(newRecord.get());
|
||||
auto newVideoRecord = static_cast<UDMF::Video *>(newRecord.get());
|
||||
auto newDetails = newVideoRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
auto uri2 = newVideoRecord->GetUri();
|
||||
@ -600,7 +599,7 @@ HWTEST_F(PasteboardUtilsTest, Folder2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::FOLDER);
|
||||
auto newFolderRecord = static_cast<UDMF::Folder*>(newRecord.get());
|
||||
auto newFolderRecord = static_cast<UDMF::Folder *>(newRecord.get());
|
||||
auto newDetails = newFolderRecord->GetDetails();
|
||||
ASSERT_EQ(newDetails, details_);
|
||||
auto uri2 = newFolderRecord->GetUri();
|
||||
@ -632,7 +631,7 @@ HWTEST_F(PasteboardUtilsTest, SystemDefined2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_RECORD);
|
||||
auto newSystemRecord = static_cast<UDMF::SystemDefinedRecord*>(newRecord.get());
|
||||
auto newSystemRecord = static_cast<UDMF::SystemDefinedRecord *>(newRecord.get());
|
||||
ASSERT_EQ(newSystemRecord->GetDetails(), details_);
|
||||
}
|
||||
|
||||
@ -671,7 +670,7 @@ HWTEST_F(PasteboardUtilsTest, AppItem2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_APP_ITEM);
|
||||
auto newAppItem = static_cast<UDMF::SystemDefinedAppItem*>(newRecord.get());
|
||||
auto newAppItem = static_cast<UDMF::SystemDefinedAppItem *>(newRecord.get());
|
||||
ASSERT_EQ(newAppItem->GetAppId(), "appId");
|
||||
ASSERT_EQ(newAppItem->GetAppIconId(), "appIconId");
|
||||
ASSERT_EQ(newAppItem->GetAppName(), "appName");
|
||||
@ -717,7 +716,7 @@ HWTEST_F(PasteboardUtilsTest, Form2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_FORM);
|
||||
auto newForm = static_cast<UDMF::SystemDefinedForm*>(newRecord.get());
|
||||
auto newForm = static_cast<UDMF::SystemDefinedForm *>(newRecord.get());
|
||||
ASSERT_EQ(newForm->GetFormId(), formId1);
|
||||
ASSERT_EQ(newForm->GetFormName(), formName1);
|
||||
ASSERT_EQ(newForm->GetModule(), module1);
|
||||
@ -792,7 +791,7 @@ HWTEST_F(PasteboardUtilsTest, AppDefined2PasteRecord001, TestSize.Level0)
|
||||
auto newRecord = newData->GetRecordAt(0);
|
||||
auto newType = newRecord->GetType();
|
||||
ASSERT_EQ(newType, UDMF::APPLICATION_DEFINED_RECORD);
|
||||
auto newSystemRecord = static_cast<UDMF::ApplicationDefinedRecord*>(newRecord.get());
|
||||
auto newSystemRecord = static_cast<UDMF::ApplicationDefinedRecord *>(newRecord.get());
|
||||
ASSERT_EQ(newSystemRecord->GetRawData(), rawData_);
|
||||
}
|
||||
} // namespace OHOS::MiscServices
|
@ -12,11 +12,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "clip/clip_plugin.h"
|
||||
#include "config.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "serializable.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS::DistributedData {
|
||||
using namespace testing::ext;
|
||||
@ -29,7 +30,7 @@ public:
|
||||
void TearDown();
|
||||
void CreateConfig(Config &config, const std::string &prefix = "");
|
||||
void CreateComponent(Config::Component &component, int32_t index, const std::string &prefix);
|
||||
Serializable::json ToJson(const std::string& str);
|
||||
Serializable::json ToJson(const std::string &str);
|
||||
bool IsSame(Config &oldConfig, Config &newConfig);
|
||||
static bool IsSame(Config::Component &oldComp, Config::Component &newComp);
|
||||
|
||||
@ -49,23 +50,15 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void SerializableTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
void SerializableTest::SetUpTestCase(void) {}
|
||||
|
||||
void SerializableTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
void SerializableTest::TearDownTestCase(void) {}
|
||||
|
||||
void SerializableTest::SetUp(void)
|
||||
{
|
||||
}
|
||||
void SerializableTest::SetUp(void) {}
|
||||
|
||||
void SerializableTest::TearDown(void)
|
||||
{
|
||||
}
|
||||
void SerializableTest::TearDown(void) {}
|
||||
|
||||
Serializable::json SerializableTest::ToJson(const std::string& str)
|
||||
Serializable::json SerializableTest::ToJson(const std::string &str)
|
||||
{
|
||||
return cJSON_Parse(str.c_str());
|
||||
}
|
||||
|
@ -13,10 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tlv_object.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include "tlv_object.h"
|
||||
|
||||
namespace OHOS::MiscServices {
|
||||
using namespace testing::ext;
|
||||
@ -31,21 +32,13 @@ public:
|
||||
static std::shared_ptr<PasteDataRecord> GenRecord(std::uint32_t index);
|
||||
};
|
||||
|
||||
void TLVObjectTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
void TLVObjectTest::SetUpTestCase(void) {}
|
||||
|
||||
void TLVObjectTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
void TLVObjectTest::TearDownTestCase(void) {}
|
||||
|
||||
void TLVObjectTest::SetUp(void)
|
||||
{
|
||||
}
|
||||
void TLVObjectTest::SetUp(void) {}
|
||||
|
||||
void TLVObjectTest::TearDown(void)
|
||||
{
|
||||
}
|
||||
void TLVObjectTest::TearDown(void) {}
|
||||
|
||||
std::shared_ptr<PasteDataRecord> TLVObjectTest::GenRecord(std::uint32_t index)
|
||||
{
|
||||
|
@ -103,8 +103,8 @@ inline double HostToNet(double value)
|
||||
{
|
||||
double to;
|
||||
size_t typeLen = sizeof(double);
|
||||
const uint8_t* fromByte = reinterpret_cast<const uint8_t*>(&value);
|
||||
uint8_t* toByte = reinterpret_cast<uint8_t*>(&to);
|
||||
const uint8_t *fromByte = reinterpret_cast<const uint8_t *>(&value);
|
||||
uint8_t *toByte = reinterpret_cast<uint8_t *>(&to);
|
||||
for (size_t i = 0; i < typeLen; i++) {
|
||||
toByte[i] = fromByte[typeLen - i - 1]; // 1 is for index boundary
|
||||
}
|
||||
|
@ -12,9 +12,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "tlv_object.h"
|
||||
|
||||
#include "securec.h"
|
||||
#include "tlv_object.h"
|
||||
#include "unified_meta.h"
|
||||
#include "want.h"
|
||||
namespace OHOS::MiscServices {
|
||||
@ -27,7 +26,7 @@ bool TLVObject::Write(std::vector<std::uint8_t> &buffer, uint16_t type, std::mon
|
||||
cursor_ += sizeof(TLVHead);
|
||||
return true;
|
||||
}
|
||||
bool TLVObject::Write(std::vector<std::uint8_t> &buffer, uint16_t type, void* value)
|
||||
bool TLVObject::Write(std::vector<std::uint8_t> &buffer, uint16_t type, void *value)
|
||||
{
|
||||
if (!HasExpectBuffer(buffer, sizeof(TLVHead))) {
|
||||
return false;
|
||||
@ -125,7 +124,7 @@ bool TLVObject::Write(std::vector<std::uint8_t> &buffer, uint16_t type, const Ob
|
||||
auto tagCursor = cursor_;
|
||||
cursor_ += sizeof(TLVHead);
|
||||
auto valueCursor = cursor_;
|
||||
for (const auto& [key, val] : value.value_) {
|
||||
for (const auto &[key, val] : value.value_) {
|
||||
if (!Write(buffer, TAG_MAP_KEY, key)) {
|
||||
return false;
|
||||
}
|
||||
@ -157,13 +156,13 @@ bool TLVObject::Write(
|
||||
}
|
||||
|
||||
template<typename _InTp>
|
||||
bool TLVObject::WriteVariant(std::vector<std::uint8_t>& buffer, uint16_t type, uint32_t step, const _InTp &input)
|
||||
bool TLVObject::WriteVariant(std::vector<std::uint8_t> &buffer, uint16_t type, uint32_t step, const _InTp &input)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename _InTp, typename _First, typename... _Rest>
|
||||
bool TLVObject::WriteVariant(std::vector<std::uint8_t>& buffer, uint16_t type, uint32_t step, const _InTp &input)
|
||||
bool TLVObject::WriteVariant(std::vector<std::uint8_t> &buffer, uint16_t type, uint32_t step, const _InTp &input)
|
||||
{
|
||||
if (step == input.index()) {
|
||||
auto val = std::get<_First>(input);
|
||||
@ -173,7 +172,7 @@ bool TLVObject::WriteVariant(std::vector<std::uint8_t>& buffer, uint16_t type, u
|
||||
}
|
||||
|
||||
template<typename... _Types>
|
||||
bool TLVObject::Write(std::vector<std::uint8_t>& buffer, uint16_t type, const std::variant<_Types...> &input)
|
||||
bool TLVObject::Write(std::vector<std::uint8_t> &buffer, uint16_t type, const std::variant<_Types...> &input)
|
||||
{
|
||||
if (!HasExpectBuffer(buffer, sizeof(TLVHead))) {
|
||||
return false;
|
||||
@ -192,7 +191,7 @@ bool TLVObject::Write(std::vector<std::uint8_t>& buffer, uint16_t type, const st
|
||||
}
|
||||
|
||||
template<>
|
||||
bool TLVObject::Write(std::vector<std::uint8_t>& buffer, uint16_t type, const EntryValue& input)
|
||||
bool TLVObject::Write(std::vector<std::uint8_t> &buffer, uint16_t type, const EntryValue &input)
|
||||
{
|
||||
if (!HasExpectBuffer(buffer, sizeof(TLVHead))) {
|
||||
return false;
|
||||
@ -206,13 +205,13 @@ bool TLVObject::Write(std::vector<std::uint8_t>& buffer, uint16_t type, const En
|
||||
return false;
|
||||
}
|
||||
WriteVariant<decltype(input), std::monostate, int32_t, int64_t, double, bool, std::string, std::vector<uint8_t>,
|
||||
std::shared_ptr<OHOS::AAFwk::Want>, std::shared_ptr<OHOS::Media::PixelMap>, std::shared_ptr<Object>,
|
||||
nullptr_t>(buffer, TAG_VARIANT_VALUE, 0, input);
|
||||
std::shared_ptr<OHOS::AAFwk::Want>, std::shared_ptr<OHOS::Media::PixelMap>, std::shared_ptr<Object>, nullptr_t>(
|
||||
buffer, TAG_VARIANT_VALUE, 0, input);
|
||||
WriteHead(buffer, type, tagCursor, cursor_ - valueCursor);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TLVObject::Write(std::vector<std::uint8_t>& buffer, uint16_t type, const Details& value)
|
||||
bool TLVObject::Write(std::vector<std::uint8_t> &buffer, uint16_t type, const Details &value)
|
||||
{
|
||||
if (!HasExpectBuffer(buffer, sizeof(TLVHead))) {
|
||||
return false;
|
||||
@ -373,15 +372,15 @@ bool TLVObject::ReadValue(
|
||||
}
|
||||
|
||||
template<typename _OutTp>
|
||||
bool TLVObject::ReadVariant(const std::vector<std::uint8_t>& buffer, uint32_t step, uint32_t index, _OutTp& output,
|
||||
const TLVHead& head)
|
||||
bool TLVObject::ReadVariant(
|
||||
const std::vector<std::uint8_t> &buffer, uint32_t step, uint32_t index, _OutTp &output, const TLVHead &head)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename _OutTp, typename _First, typename... _Rest>
|
||||
bool TLVObject::ReadVariant(const std::vector<std::uint8_t>& buffer, uint32_t step, uint32_t index, _OutTp& value,
|
||||
const TLVHead& head)
|
||||
bool TLVObject::ReadVariant(
|
||||
const std::vector<std::uint8_t> &buffer, uint32_t step, uint32_t index, _OutTp &value, const TLVHead &head)
|
||||
{
|
||||
if (step == index) {
|
||||
TLVHead valueHead{};
|
||||
@ -395,7 +394,7 @@ bool TLVObject::ReadVariant(const std::vector<std::uint8_t>& buffer, uint32_t st
|
||||
}
|
||||
|
||||
template<typename... _Types>
|
||||
bool TLVObject::ReadValue(const std::vector<std::uint8_t>& buffer, std::variant<_Types...>& value, const TLVHead& head)
|
||||
bool TLVObject::ReadValue(const std::vector<std::uint8_t> &buffer, std::variant<_Types...> &value, const TLVHead &head)
|
||||
{
|
||||
TLVHead valueHead{};
|
||||
ReadHead(buffer, valueHead);
|
||||
@ -407,7 +406,7 @@ bool TLVObject::ReadValue(const std::vector<std::uint8_t>& buffer, std::variant<
|
||||
}
|
||||
|
||||
template<>
|
||||
bool TLVObject::ReadValue(const std::vector<std::uint8_t>& buffer, EntryValue& value, const TLVHead& head)
|
||||
bool TLVObject::ReadValue(const std::vector<std::uint8_t> &buffer, EntryValue &value, const TLVHead &head)
|
||||
{
|
||||
TLVHead valueHead{};
|
||||
ReadHead(buffer, valueHead);
|
||||
@ -415,12 +414,13 @@ bool TLVObject::ReadValue(const std::vector<std::uint8_t>& buffer, EntryValue& v
|
||||
if (!ReadValue(buffer, index, valueHead)) {
|
||||
return false;
|
||||
}
|
||||
return ReadVariant<decltype(value), std::monostate, int32_t, int64_t, double, bool, std::string,
|
||||
std::vector<uint8_t>, std::shared_ptr<OHOS::AAFwk::Want>, std::shared_ptr<OHOS::Media::PixelMap>,
|
||||
std::shared_ptr<Object>, nullptr_t>(buffer, 0, index, value, valueHead);
|
||||
return ReadVariant<decltype(value), std::monostate, int32_t, int64_t, double, bool,
|
||||
std::string, std::vector<uint8_t>, std::shared_ptr<OHOS::AAFwk::Want>,
|
||||
std::shared_ptr<OHOS::Media::PixelMap>, std::shared_ptr<Object>, nullptr_t>(
|
||||
buffer, 0, index, value, valueHead);
|
||||
}
|
||||
|
||||
bool TLVObject::ReadValue(const std::vector<std::uint8_t>& buffer, Details& value, const TLVHead& head)
|
||||
bool TLVObject::ReadValue(const std::vector<std::uint8_t> &buffer, Details &value, const TLVHead &head)
|
||||
{
|
||||
auto mapEnd = cursor_ + head.len;
|
||||
while (cursor_ < mapEnd) {
|
||||
@ -480,8 +480,8 @@ bool TLVObject::ReadValue(const std::vector<std::uint8_t> &buffer, AAFwk::Want &
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TLVObject::ReadValue(const std::vector<std::uint8_t> &buffer, std::shared_ptr<Media::PixelMap> &value,
|
||||
const TLVHead &head)
|
||||
bool TLVObject::ReadValue(
|
||||
const std::vector<std::uint8_t> &buffer, std::shared_ptr<Media::PixelMap> &value, const TLVHead &head)
|
||||
{
|
||||
std::vector<std::uint8_t> u8Value;
|
||||
if (!ReadValue(buffer, u8Value, head)) {
|
||||
@ -513,7 +513,7 @@ std::shared_ptr<Media::PixelMap> TLVObject::Vector2PixelMap(std::vector<std::uin
|
||||
if (value.size() == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::shared_ptr<Media::PixelMap> (Media::PixelMap::DecodeTlv(value));
|
||||
return std::shared_ptr<Media::PixelMap>(Media::PixelMap::DecodeTlv(value));
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> TLVObject::PixelMap2Vector(std::shared_ptr<Media::PixelMap> pixelMap)
|
||||
|
@ -25,9 +25,9 @@
|
||||
#include "api/visibility.h"
|
||||
#include "endian_converter.h"
|
||||
#include "parcel.h"
|
||||
#include "parcel_util.h"
|
||||
#include "securec.h"
|
||||
#include "unified_meta.h"
|
||||
#include "parcel_util.h"
|
||||
namespace OHOS::MiscServices {
|
||||
#pragma pack(1)
|
||||
struct TLVHead {
|
||||
@ -59,9 +59,7 @@ using Object = UDMF::Object;
|
||||
|
||||
struct API_EXPORT TLVObject {
|
||||
public:
|
||||
TLVObject() : total_(0), cursor_(0)
|
||||
{
|
||||
}
|
||||
TLVObject() : total_(0), cursor_(0) {}
|
||||
virtual bool Encode(std::vector<std::uint8_t> &buffer) = 0;
|
||||
virtual bool Decode(const std::vector<std::uint8_t> &buffer) = 0;
|
||||
virtual size_t Count() = 0;
|
||||
@ -145,17 +143,17 @@ public:
|
||||
return expectSize;
|
||||
}
|
||||
|
||||
static inline size_t Count(const Details& value)
|
||||
static inline size_t Count(const Details &value)
|
||||
{
|
||||
size_t expectSize = sizeof(TLVHead);
|
||||
for (auto& item : value) {
|
||||
for (auto &item : value) {
|
||||
expectSize += Count(item.first);
|
||||
expectSize += Count(item.second);
|
||||
}
|
||||
return expectSize;
|
||||
}
|
||||
|
||||
static inline size_t Count(const std::shared_ptr<AAFwk::Want>& value)
|
||||
static inline size_t Count(const std::shared_ptr<AAFwk::Want> &value)
|
||||
{
|
||||
size_t expectSize = sizeof(TLVHead);
|
||||
if (value == nullptr) {
|
||||
@ -173,13 +171,13 @@ public:
|
||||
return expectSize + Count(PixelMap2Vector(value));
|
||||
}
|
||||
|
||||
static inline size_t Count(const std::shared_ptr<Object>& value)
|
||||
static inline size_t Count(const std::shared_ptr<Object> &value)
|
||||
{
|
||||
size_t expectSize = sizeof(TLVHead);
|
||||
if (value == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
for (auto& item : value->value_) {
|
||||
for (auto &item : value->value_) {
|
||||
expectSize += Count(item.first);
|
||||
expectSize += Count(item.second);
|
||||
}
|
||||
@ -200,13 +198,13 @@ public:
|
||||
static std::vector<std::uint8_t> PixelMap2Vector(std::shared_ptr<Media::PixelMap> pixelMap);
|
||||
|
||||
template<typename _InTp>
|
||||
static inline size_t CountVariant(uint32_t step, const _InTp& input)
|
||||
static inline size_t CountVariant(uint32_t step, const _InTp &input)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename _InTp, typename _First, typename... _Rest>
|
||||
static inline size_t CountVariant(uint32_t step, const _InTp& input)
|
||||
static inline size_t CountVariant(uint32_t step, const _InTp &input)
|
||||
{
|
||||
if (step == input.index()) {
|
||||
return Count(step) + Count(std::get<_First>(input));
|
||||
@ -215,14 +213,14 @@ public:
|
||||
}
|
||||
|
||||
template<typename... _Types>
|
||||
static inline size_t Count(const std::variant<_Types...>& input)
|
||||
static inline size_t Count(const std::variant<_Types...> &input)
|
||||
{
|
||||
size_t expectSize = sizeof(TLVHead);
|
||||
return expectSize + CountVariant<decltype(input), _Types...>(0, input);
|
||||
}
|
||||
|
||||
bool Write(std::vector<std::uint8_t> &buffer, uint16_t type, std::monostate value);
|
||||
bool Write(std::vector<std::uint8_t> &buffer, uint16_t type, void* value);
|
||||
bool Write(std::vector<std::uint8_t> &buffer, uint16_t type, void *value);
|
||||
bool Write(std::vector<std::uint8_t> &buffer, uint16_t type, bool value);
|
||||
bool Write(std::vector<std::uint8_t> &buffer, uint16_t type, double value);
|
||||
bool Write(std::vector<std::uint8_t> &buffer, uint16_t type, int8_t value);
|
||||
@ -261,18 +259,18 @@ public:
|
||||
}
|
||||
|
||||
template<typename _InTp>
|
||||
bool WriteVariant(std::vector<std::uint8_t>& buffer, uint16_t type, uint32_t step, const _InTp& input);
|
||||
bool WriteVariant(std::vector<std::uint8_t> &buffer, uint16_t type, uint32_t step, const _InTp &input);
|
||||
|
||||
template<typename _InTp, typename _First, typename... _Rest>
|
||||
bool WriteVariant(std::vector<std::uint8_t>& buffer, uint16_t type, uint32_t step, const _InTp& input);
|
||||
bool WriteVariant(std::vector<std::uint8_t> &buffer, uint16_t type, uint32_t step, const _InTp &input);
|
||||
|
||||
template<typename... _Types>
|
||||
bool Write(std::vector<std::uint8_t>& buffer, uint16_t type, const std::variant<_Types...>& input);
|
||||
bool Write(std::vector<std::uint8_t> &buffer, uint16_t type, const std::variant<_Types...> &input);
|
||||
|
||||
template<>
|
||||
bool Write(std::vector<std::uint8_t>& buffer, uint16_t type, const EntryValue& input);
|
||||
bool Write(std::vector<std::uint8_t> &buffer, uint16_t type, const EntryValue &input);
|
||||
|
||||
bool Write(std::vector<std::uint8_t>& buffer, uint16_t type, const Details& value);
|
||||
bool Write(std::vector<std::uint8_t> &buffer, uint16_t type, const Details &value);
|
||||
|
||||
bool ReadHead(const std::vector<std::uint8_t> &buffer, TLVHead &head);
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, bool &value, const TLVHead &head);
|
||||
@ -288,8 +286,8 @@ public:
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, RawMem &rawMem, const TLVHead &head);
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, Object &value, const TLVHead &head);
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, AAFwk::Want &value, const TLVHead &head);
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, std::shared_ptr<Media::PixelMap> &value,
|
||||
const TLVHead &head);
|
||||
bool ReadValue(
|
||||
const std::vector<std::uint8_t> &buffer, std::shared_ptr<Media::PixelMap> &value, const TLVHead &head);
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, TLVObject &value, const TLVHead &head);
|
||||
template<typename T>
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, std::vector<T> &value, const TLVHead &head)
|
||||
@ -309,23 +307,23 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReadValue(const std::vector<std::uint8_t>& buffer, std::vector<uint8_t>& value, const TLVHead& head);
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, std::vector<uint8_t> &value, const TLVHead &head);
|
||||
|
||||
template<typename _InTp>
|
||||
bool ReadVariant(const std::vector<std::uint8_t>& buffer, uint32_t step, uint32_t index, _InTp& input,
|
||||
const TLVHead& head);
|
||||
bool ReadVariant(
|
||||
const std::vector<std::uint8_t> &buffer, uint32_t step, uint32_t index, _InTp &input, const TLVHead &head);
|
||||
|
||||
template<typename _InTp, typename _First, typename... _Rest>
|
||||
bool ReadVariant(const std::vector<std::uint8_t>& buffer, uint32_t step, uint32_t index, _InTp& input,
|
||||
const TLVHead& head);
|
||||
bool ReadVariant(
|
||||
const std::vector<std::uint8_t> &buffer, uint32_t step, uint32_t index, _InTp &input, const TLVHead &head);
|
||||
|
||||
template<typename... _Types>
|
||||
bool ReadValue(const std::vector<std::uint8_t>& buffer, std::variant<_Types...>& value, const TLVHead& head);
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, std::variant<_Types...> &value, const TLVHead &head);
|
||||
|
||||
template<>
|
||||
bool ReadValue(const std::vector<std::uint8_t>& buffer, EntryValue& value, const TLVHead& head);
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, EntryValue &value, const TLVHead &head);
|
||||
|
||||
bool ReadValue(const std::vector<std::uint8_t>& buffer, Details& value, const TLVHead& head);
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, Details &value, const TLVHead &head);
|
||||
bool ReadValue(const std::vector<std::uint8_t> &buffer, std::map<std::string, std::vector<uint8_t>> &value,
|
||||
const TLVHead &head);
|
||||
|
||||
|
@ -12,11 +12,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "copy_uri_handler.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "copy_uri_handler.h"
|
||||
#include "errors.h"
|
||||
#include "os_account_manager.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
|
@ -20,6 +20,7 @@ class CopyUriHandler : public UriHandler {
|
||||
public:
|
||||
CopyUriHandler();
|
||||
std::string ToUri(int32_t fd) override;
|
||||
|
||||
private:
|
||||
static constexpr int32_t FILE_EXIST = 17;
|
||||
};
|
||||
|
@ -13,7 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "paste_uri_handler.h"
|
||||
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "remote_uri.h"
|
||||
namespace OHOS::MiscServices {
|
||||
|
@ -12,10 +12,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "uri_handler.h"
|
||||
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "paste_data.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "uri_handler.h"
|
||||
|
||||
namespace OHOS::MiscServices {
|
||||
bool UriHandler::GetRealPath(const std::string &inOriPath, std::string &outRealPath)
|
||||
@ -58,7 +57,7 @@ int32_t UriHandler::ToFd(const std::string &uri, bool isClient)
|
||||
PasteData::sharePath.c_str(), fileRealPath.c_str());
|
||||
return INVALID_FD;
|
||||
}
|
||||
|
||||
|
||||
int32_t fd = open(fileRealPath.c_str(), O_RDONLY);
|
||||
if (fd < 0) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "open file failed, maybe its not a legal file path %{public}s",
|
||||
|
@ -15,14 +15,14 @@
|
||||
|
||||
#ifndef PASTE_DATA_IMPL_H
|
||||
#define PASTE_DATA_IMPL_H
|
||||
|
||||
|
||||
#include "ffi_remote_data.h"
|
||||
#include "pixel_map_impl.h"
|
||||
#include "paste_data.h"
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_log.h"
|
||||
#include "paste_data_record_impl.h"
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_error.h"
|
||||
#include "pasteboard_log.h"
|
||||
#include "pixel_map_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServicesCj {
|
||||
@ -32,7 +32,10 @@ public:
|
||||
explicit PasteDataImpl(std::shared_ptr<MiscServices::PasteData> pasteData);
|
||||
PasteDataImpl(std::string mimeType, CJValueType value);
|
||||
std::shared_ptr<MiscServices::PasteData> GetRealPasteData();
|
||||
OHOS::FFI::RuntimeType *GetRuntimeType() override { return GetClassType(); }
|
||||
OHOS::FFI::RuntimeType *GetRuntimeType() override
|
||||
{
|
||||
return GetClassType();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class OHOS::FFI::RuntimeType;
|
||||
@ -49,7 +52,7 @@ private:
|
||||
|
||||
int64_t CreateCjPasteDataObject(std::string mimeType, CJValueType value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace MiscServicesCj
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
@ -15,13 +15,13 @@
|
||||
|
||||
#ifndef PASTE_DATA_RECORD_IMPL_H
|
||||
#define PASTE_DATA_RECORD_IMPL_H
|
||||
|
||||
|
||||
#include "ffi_remote_data.h"
|
||||
#include "pixel_map_impl.h"
|
||||
#include "paste_data.h"
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_log.h"
|
||||
|
||||
#include "pixel_map_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServicesCj {
|
||||
struct CJValueType {
|
||||
@ -38,7 +38,10 @@ public:
|
||||
explicit PasteDataRecordImpl(std::shared_ptr<MiscServices::PasteDataRecord> pasteDataRecord);
|
||||
PasteDataRecordImpl(std::string mimeType, CJValueType value);
|
||||
std::shared_ptr<MiscServices::PasteDataRecord> GetRealPasteDataRecord();
|
||||
OHOS::FFI::RuntimeType *GetRuntimeType() override { return GetClassType(); }
|
||||
OHOS::FFI::RuntimeType *GetRuntimeType() override
|
||||
{
|
||||
return GetClassType();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class OHOS::FFI::RuntimeType;
|
||||
@ -56,10 +59,10 @@ private:
|
||||
int64_t CreateCjPasteDataRecordObject(std::string mimeType, CJValueType value);
|
||||
sptr<PasteDataRecordImpl> getCjPasteDataRecordImpl(std::shared_ptr<MiscServices::PasteDataRecord> record);
|
||||
void removeCjPasteDataRecordImpl(std::shared_ptr<MiscServices::PasteDataRecord> record);
|
||||
void addCjPasteDataRecordImpl(std::shared_ptr<MiscServices::PasteDataRecord> record,
|
||||
sptr<PasteDataRecordImpl> pasteDataRecordImpl);
|
||||
void addCjPasteDataRecordImpl(
|
||||
std::shared_ptr<MiscServices::PasteDataRecord> record, sptr<PasteDataRecordImpl> pasteDataRecordImpl);
|
||||
|
||||
} // namespace MiscServicesCj
|
||||
} // namespace OHOS
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -20,62 +20,62 @@
|
||||
#include "system_pasteboard_impl.h"
|
||||
|
||||
extern "C" {
|
||||
#define OUT_OF_RANGE 12900001
|
||||
#define OUT_OF_RANGE 12900001
|
||||
|
||||
typedef struct {
|
||||
CArrString mimeTypes;
|
||||
char* tag;
|
||||
int64_t timestamp;
|
||||
bool localOnly;
|
||||
int32_t shareOption;
|
||||
} CPasteDataProperty;
|
||||
typedef struct {
|
||||
CArrString mimeTypes;
|
||||
char *tag;
|
||||
int64_t timestamp;
|
||||
bool localOnly;
|
||||
int32_t shareOption;
|
||||
} CPasteDataProperty;
|
||||
|
||||
typedef struct {
|
||||
char* htmlText;
|
||||
char* mimeType;
|
||||
char* plainText;
|
||||
char* uri;
|
||||
int64_t pixelMap;
|
||||
} CPasteDataRecord;
|
||||
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreateStringPasteData(const char* mimeType, const char* value);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreatePixelMapPasteData(const char* mimeType, int64_t pixelMapId);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreateArrayBufPasteData(const char* mimeType, uint8_t *buffPtr, int64_t bufferSize);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreateStringPasteDataRecord(const char* mimeType, const char* value,
|
||||
CPasteDataRecord *retPtr);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreatePixelMapPasteDataRecord(const char* mimeType, int64_t pixelMapId,
|
||||
CPasteDataRecord *retPtr);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreateArrayBufPasteDataRecord(const char* mimeType, uint8_t *buffPtr,
|
||||
int64_t bufferSize, CPasteDataRecord *retPtr);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataRecordToPlainText(int64_t id);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataGetPrimaryText(int64_t id);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataGetPrimaryHtml(int64_t id);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataGetPrimaryUri(int64_t id);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSPasteDataGetPrimaryPixelMap(int64_t id);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataGetPrimaryMimeType(int64_t id);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataGetProperty(int64_t id, CPasteDataProperty *retPtr);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataSetProperty(int64_t id, CArrString mimeTypes, const char* tag,
|
||||
int64_t timestamp, bool localOnly, int32_t shareOption);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataGetTag(int64_t id);
|
||||
FFI_EXPORT RetDataBool FfiOHOSPasteDataHasType(int64_t id, const char* mimeTypes);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataAddRecord(int64_t id, int64_t recordId);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataAddMimeTypeRecord(int64_t id, const char* mimeType, const char* value);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataAddPixelMapRecord(int64_t id, const char* mimeType, int64_t pixelMapId);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataAddArrayRecord(int64_t id, const char* mimeType, uint8_t *buffPtr,
|
||||
int64_t bufferSize);
|
||||
FFI_EXPORT RetDataCArrString FfiOHOSPasteDataGetMimeTypes(int64_t id);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSPasteDataGetRecord(int64_t id, int32_t index, CPasteDataRecord *retPtr);
|
||||
FFI_EXPORT RetDataUI FfiOHOSPasteDataGetRecordCount(int64_t id);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataRemoveRecord(int64_t id, int32_t index);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataReplaceRecord(int64_t id, int64_t recordId, int32_t index);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSGetSystemPasteboard();
|
||||
FFI_EXPORT int32_t FfiOHOSSystemPasteboardSetData(int64_t id, int64_t pasteDataId);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSSystemPasteboardGetData(int64_t id);
|
||||
FFI_EXPORT RetDataBool FfiOHOSSystemPasteboardHasData(int64_t id);
|
||||
FFI_EXPORT void FfiOHOSSystemPasteboardClearData(int64_t id);
|
||||
FFI_EXPORT RetDataBool FfiOHOSSystemPasteboardIsRemoteData(int64_t id);
|
||||
FFI_EXPORT RetDataBool FfiOHOSSystemPasteboardHasDataType(int64_t id, const char* mimeType);
|
||||
FFI_EXPORT RetDataCString FfiOHOSSystemPasteboardGetDataSource(int64_t id);
|
||||
typedef struct {
|
||||
char *htmlText;
|
||||
char *mimeType;
|
||||
char *plainText;
|
||||
char *uri;
|
||||
int64_t pixelMap;
|
||||
} CPasteDataRecord;
|
||||
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreateStringPasteData(const char *mimeType, const char *value);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreatePixelMapPasteData(const char *mimeType, int64_t pixelMapId);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreateArrayBufPasteData(const char *mimeType, uint8_t *buffPtr, int64_t bufferSize);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreateStringPasteDataRecord(
|
||||
const char *mimeType, const char *value, CPasteDataRecord *retPtr);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreatePixelMapPasteDataRecord(
|
||||
const char *mimeType, int64_t pixelMapId, CPasteDataRecord *retPtr);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSCreateArrayBufPasteDataRecord(
|
||||
const char *mimeType, uint8_t *buffPtr, int64_t bufferSize, CPasteDataRecord *retPtr);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataRecordToPlainText(int64_t id);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataGetPrimaryText(int64_t id);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataGetPrimaryHtml(int64_t id);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataGetPrimaryUri(int64_t id);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSPasteDataGetPrimaryPixelMap(int64_t id);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataGetPrimaryMimeType(int64_t id);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataGetProperty(int64_t id, CPasteDataProperty *retPtr);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataSetProperty(
|
||||
int64_t id, CArrString mimeTypes, const char *tag, int64_t timestamp, bool localOnly, int32_t shareOption);
|
||||
FFI_EXPORT RetDataCString FfiOHOSPasteDataGetTag(int64_t id);
|
||||
FFI_EXPORT RetDataBool FfiOHOSPasteDataHasType(int64_t id, const char *mimeTypes);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataAddRecord(int64_t id, int64_t recordId);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataAddMimeTypeRecord(int64_t id, const char *mimeType, const char *value);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataAddPixelMapRecord(int64_t id, const char *mimeType, int64_t pixelMapId);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataAddArrayRecord(
|
||||
int64_t id, const char *mimeType, uint8_t *buffPtr, int64_t bufferSize);
|
||||
FFI_EXPORT RetDataCArrString FfiOHOSPasteDataGetMimeTypes(int64_t id);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSPasteDataGetRecord(int64_t id, int32_t index, CPasteDataRecord *retPtr);
|
||||
FFI_EXPORT RetDataUI FfiOHOSPasteDataGetRecordCount(int64_t id);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataRemoveRecord(int64_t id, int32_t index);
|
||||
FFI_EXPORT int32_t FfiOHOSPasteDataReplaceRecord(int64_t id, int64_t recordId, int32_t index);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSGetSystemPasteboard();
|
||||
FFI_EXPORT int32_t FfiOHOSSystemPasteboardSetData(int64_t id, int64_t pasteDataId);
|
||||
FFI_EXPORT RetDataI64 FfiOHOSSystemPasteboardGetData(int64_t id);
|
||||
FFI_EXPORT RetDataBool FfiOHOSSystemPasteboardHasData(int64_t id);
|
||||
FFI_EXPORT void FfiOHOSSystemPasteboardClearData(int64_t id);
|
||||
FFI_EXPORT RetDataBool FfiOHOSSystemPasteboardIsRemoteData(int64_t id);
|
||||
FFI_EXPORT RetDataBool FfiOHOSSystemPasteboardHasDataType(int64_t id, const char *mimeType);
|
||||
FFI_EXPORT RetDataCString FfiOHOSSystemPasteboardGetDataSource(int64_t id);
|
||||
}
|
||||
|
||||
#endif
|
@ -12,28 +12,28 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PASTEBOARD_LOG_H
|
||||
|
||||
#define PASTEBOARD_LOG_H
|
||||
|
||||
|
||||
#include "hilog/log.h"
|
||||
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#undef LOG_TAG
|
||||
#define LOG_DOMAIN 0xD001650
|
||||
#define LOG_TAG "PasteboardFFI"
|
||||
|
||||
|
||||
#undef LOGI
|
||||
#undef LOGE
|
||||
#define LOGI(...) \
|
||||
if (HiLogIsLoggable(LOG_DOMAIN, LOG_TAG, LOG_INFO)) { \
|
||||
HILOG_INFO(LOG_CORE, ##__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define LOGE(...) \
|
||||
if (HiLogIsLoggable(LOG_DOMAIN, LOG_TAG, LOG_ERROR)) { \
|
||||
HILOG_ERROR(LOG_CORE, ##__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define LOGI(...) \
|
||||
if (HiLogIsLoggable(LOG_DOMAIN, LOG_TAG, LOG_INFO)) { \
|
||||
HILOG_INFO(LOG_CORE, ##__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define LOGE(...) \
|
||||
if (HiLogIsLoggable(LOG_DOMAIN, LOG_TAG, LOG_ERROR)) { \
|
||||
HILOG_ERROR(LOG_CORE, ##__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#endif
|
@ -12,13 +12,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SYSTEM_PASTEBOARD_IMPL_H
|
||||
#define SYSTEM_PASTEBOARD_IMPL_H
|
||||
|
||||
|
||||
#include "ffi_remote_data.h"
|
||||
#include "paste_data_impl.h"
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServicesCj {
|
||||
#define PASTEBOARD_SUCCESS 0
|
||||
@ -38,7 +38,10 @@ public:
|
||||
bool IsRemoteData();
|
||||
bool HasDataType(std::string mimeType);
|
||||
std::string GetDataSource();
|
||||
OHOS::FFI::RuntimeType *GetRuntimeType() override { return GetClassType(); }
|
||||
OHOS::FFI::RuntimeType *GetRuntimeType() override
|
||||
{
|
||||
return GetClassType();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class OHOS::FFI::RuntimeType;
|
||||
@ -47,8 +50,8 @@ private:
|
||||
sptr<PasteDataImpl> value_;
|
||||
std::shared_ptr<MiscServices::PasteData> pasteData_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace MiscServicesCj
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
@ -21,8 +21,7 @@ namespace MiscServicesCj {
|
||||
|
||||
OHOS::FFI::RuntimeType *PasteDataImpl::GetClassType()
|
||||
{
|
||||
static OHOS::FFI::RuntimeType runtimeType =
|
||||
OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("PasteDataImpl");
|
||||
static OHOS::FFI::RuntimeType runtimeType = OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("PasteDataImpl");
|
||||
return &runtimeType;
|
||||
}
|
||||
|
||||
@ -86,9 +85,7 @@ void PasteDataImpl::CreatePixelMapData(std::string mimeType, CJValueType value)
|
||||
value_ = PasteboardClient::GetInstance()->CreatePixelMapData(value.pixelMap);
|
||||
}
|
||||
|
||||
void PasteDataImpl::CreateWantData(std::string mimeType, CJValueType value)
|
||||
{
|
||||
}
|
||||
void PasteDataImpl::CreateWantData(std::string mimeType, CJValueType value) {}
|
||||
|
||||
}
|
||||
} // namespace MiscServicesCj
|
||||
}
|
@ -25,8 +25,8 @@ std::recursive_mutex g_PasteDataMutex;
|
||||
|
||||
OHOS::FFI::RuntimeType *PasteDataRecordImpl::GetClassType()
|
||||
{
|
||||
static OHOS::FFI::RuntimeType runtimeType =
|
||||
OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("PasteDataRecordImpl");
|
||||
static OHOS::FFI::RuntimeType runtimeType = OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("PasteDataRecordImp"
|
||||
"l");
|
||||
return &runtimeType;
|
||||
}
|
||||
|
||||
@ -61,8 +61,8 @@ void removeCjPasteDataRecordImpl(std::shared_ptr<MiscServices::PasteDataRecord>
|
||||
g_cjPasteDataRecordMap.erase(record);
|
||||
}
|
||||
|
||||
void addCjPasteDataRecordImpl(std::shared_ptr<MiscServices::PasteDataRecord> record,
|
||||
sptr<PasteDataRecordImpl> pasteDataRecordImpl)
|
||||
void addCjPasteDataRecordImpl(
|
||||
std::shared_ptr<MiscServices::PasteDataRecord> record, sptr<PasteDataRecordImpl> pasteDataRecordImpl)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(g_PasteDataMutex);
|
||||
g_cjPasteDataRecordMap.try_emplace(record, pasteDataRecordImpl);
|
||||
@ -126,9 +126,7 @@ void PasteDataRecordImpl::CreatePixelMapDataRecord(std::string mimeType, CJValue
|
||||
value_ = PasteboardClient::GetInstance()->CreatePixelMapRecord(value.pixelMap);
|
||||
}
|
||||
|
||||
void PasteDataRecordImpl::CreateWantDataRecord(std::string mimeType, CJValueType value)
|
||||
{
|
||||
}
|
||||
void PasteDataRecordImpl::CreateWantDataRecord(std::string mimeType, CJValueType value) {}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace MiscServicesCj
|
||||
} // namespace OHOS
|
@ -13,9 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "pasteboard_ffi.h"
|
||||
#include <securec.h>
|
||||
|
||||
#include "pasteboard_ffi.h"
|
||||
|
||||
using namespace OHOS::FFI;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::MiscServices;
|
||||
@ -24,7 +25,7 @@ using namespace OHOS::MiscServicesCj;
|
||||
namespace OHOS {
|
||||
namespace CJSystemapi {
|
||||
extern "C" {
|
||||
RetDataI64 FfiOHOSCreateStringPasteData(const char* mimeType, const char* value)
|
||||
RetDataI64 FfiOHOSCreateStringPasteData(const char *mimeType, const char *value)
|
||||
{
|
||||
LOGI("[PasteData] FfiOHOSCreateStringPasteData");
|
||||
RetDataI64 ret;
|
||||
@ -39,7 +40,7 @@ RetDataI64 FfiOHOSCreateStringPasteData(const char* mimeType, const char* value)
|
||||
return ret;
|
||||
}
|
||||
|
||||
RetDataI64 FfiOHOSCreatePixelMapPasteData(const char* mimeType, int64_t pixelMapId)
|
||||
RetDataI64 FfiOHOSCreatePixelMapPasteData(const char *mimeType, int64_t pixelMapId)
|
||||
{
|
||||
LOGI("[PasteData] FfiOHOSCreatePixelMapPasteData");
|
||||
RetDataI64 ret = { .code = ERR_INVALID_INSTANCE_CODE, .data = 0 };
|
||||
@ -58,7 +59,7 @@ RetDataI64 FfiOHOSCreatePixelMapPasteData(const char* mimeType, int64_t pixelMap
|
||||
return ret;
|
||||
}
|
||||
|
||||
RetDataI64 FfiOHOSCreateArrayBufPasteData(const char* mimeType, uint8_t *buffPtr, int64_t bufferSize)
|
||||
RetDataI64 FfiOHOSCreateArrayBufPasteData(const char *mimeType, uint8_t *buffPtr, int64_t bufferSize)
|
||||
{
|
||||
LOGI("[PasteData] FfiOHOSCreateArrayBufPasteData");
|
||||
RetDataI64 ret;
|
||||
@ -74,10 +75,10 @@ RetDataI64 FfiOHOSCreateArrayBufPasteData(const char* mimeType, uint8_t *buffPtr
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *PasteBoardMallocCString(const std::string& origin)
|
||||
char *PasteBoardMallocCString(const std::string &origin)
|
||||
{
|
||||
auto len = origin.length() + 1;
|
||||
char* res = static_cast<char*>(malloc(sizeof(char) * len));
|
||||
char *res = static_cast<char *>(malloc(sizeof(char) * len));
|
||||
if (res == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -102,15 +103,15 @@ void FillCPasteDataRecord(CPasteDataRecord *retPtr, std::shared_ptr<PasteDataRec
|
||||
retPtr->pixelMap = ERR_INVALID_INSTANCE_CODE;
|
||||
if (record->GetHtmlText() != nullptr) {
|
||||
std::string resHtmlText = *(record->GetHtmlText());
|
||||
retPtr->htmlText = PasteBoardMallocCString(resHtmlText);
|
||||
retPtr->htmlText = PasteBoardMallocCString(resHtmlText);
|
||||
}
|
||||
if (!record->GetMimeType().empty()) {
|
||||
std::string resMimeType = record->GetMimeType();
|
||||
retPtr->mimeType = PasteBoardMallocCString(resMimeType);
|
||||
retPtr->mimeType = PasteBoardMallocCString(resMimeType);
|
||||
}
|
||||
if (record->GetPlainText() != nullptr) {
|
||||
std::string resPlainText = *(record->GetPlainText());
|
||||
retPtr->plainText = PasteBoardMallocCString(resPlainText);
|
||||
retPtr->plainText = PasteBoardMallocCString(resPlainText);
|
||||
}
|
||||
if (record->GetUri() != nullptr) {
|
||||
std::string resUri = record->GetUri()->ToString();
|
||||
@ -125,7 +126,7 @@ void FillCPasteDataRecord(CPasteDataRecord *retPtr, std::shared_ptr<PasteDataRec
|
||||
retPtr->pixelMap = nativeImage->GetID();
|
||||
}
|
||||
|
||||
RetDataI64 FfiOHOSCreateStringPasteDataRecord(const char* mimeType, const char* value, CPasteDataRecord *retPtr)
|
||||
RetDataI64 FfiOHOSCreateStringPasteDataRecord(const char *mimeType, const char *value, CPasteDataRecord *retPtr)
|
||||
{
|
||||
LOGI("[PasteDataRecord] FfiOHOSCreateStringPasteDataRecord");
|
||||
RetDataI64 ret = { .code = ERR_INVALID_INSTANCE_CODE, .data = 0 };
|
||||
@ -150,7 +151,7 @@ RetDataI64 FfiOHOSCreateStringPasteDataRecord(const char* mimeType, const char*
|
||||
return ret;
|
||||
}
|
||||
|
||||
RetDataI64 FfiOHOSCreatePixelMapPasteDataRecord(const char* mimeType, int64_t pixelMapId, CPasteDataRecord *retPtr)
|
||||
RetDataI64 FfiOHOSCreatePixelMapPasteDataRecord(const char *mimeType, int64_t pixelMapId, CPasteDataRecord *retPtr)
|
||||
{
|
||||
LOGI("[PasteDataRecord] FfiOHOSCreateStringPasteDataRecord");
|
||||
RetDataI64 ret = { .code = ERR_INVALID_INSTANCE_CODE, .data = 0 };
|
||||
@ -180,8 +181,8 @@ RetDataI64 FfiOHOSCreatePixelMapPasteDataRecord(const char* mimeType, int64_t pi
|
||||
return ret;
|
||||
}
|
||||
|
||||
RetDataI64 FfiOHOSCreateArrayBufPasteDataRecord(const char* mimeType, uint8_t *buffPtr, int64_t bufferSize,
|
||||
CPasteDataRecord *retPtr)
|
||||
RetDataI64 FfiOHOSCreateArrayBufPasteDataRecord(
|
||||
const char *mimeType, uint8_t *buffPtr, int64_t bufferSize, CPasteDataRecord *retPtr)
|
||||
{
|
||||
LOGI("[PasteDataRecord] FfiOHOSCreateArrayBufPasteDataRecord");
|
||||
RetDataI64 ret = { .code = ERR_INVALID_INSTANCE_CODE, .data = 0 };
|
||||
@ -222,7 +223,7 @@ RetDataCString FfiOHOSPasteDataGetPrimaryText(int64_t id)
|
||||
LOGE("[PasteData] GetPrimaryText: pasteData not exist");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<std::string> p = pasteData->GetPrimaryText();
|
||||
if (p != nullptr) {
|
||||
ret.data = PasteBoardMallocCString(*p);
|
||||
@ -383,9 +384,9 @@ RetDataCString FfiOHOSPasteDataGetPrimaryMimeType(int64_t id)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char** VectorToCArrString(std::vector<std::string> &vec)
|
||||
static char **VectorToCArrString(std::vector<std::string> &vec)
|
||||
{
|
||||
char** result = new char* [vec.size()];
|
||||
char **result = new char *[vec.size()];
|
||||
if (result == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -458,8 +459,8 @@ static std::vector<std::string> CArrStringToVector(CArrString src)
|
||||
return res;
|
||||
}
|
||||
|
||||
int32_t FfiOHOSPasteDataSetProperty(int64_t id, CArrString mimeTypes, const char* tag,
|
||||
int64_t timestamp, bool localOnly, int32_t shareOption)
|
||||
int32_t FfiOHOSPasteDataSetProperty(
|
||||
int64_t id, CArrString mimeTypes, const char *tag, int64_t timestamp, bool localOnly, int32_t shareOption)
|
||||
{
|
||||
LOGI("[PasteData] FfiOHOSPasteDataSetProperty start");
|
||||
auto instance = FFIData::GetData<PasteDataImpl>(id);
|
||||
@ -516,7 +517,7 @@ RetDataCString FfiOHOSPasteDataGetTag(int64_t id)
|
||||
return ret;
|
||||
}
|
||||
|
||||
RetDataBool FfiOHOSPasteDataHasType(int64_t id, const char* mimeTypes)
|
||||
RetDataBool FfiOHOSPasteDataHasType(int64_t id, const char *mimeTypes)
|
||||
{
|
||||
LOGI("[PasteData] FfiOHOSPasteDataHasType start");
|
||||
RetDataBool ret = { .code = ERR_INVALID_INSTANCE_CODE, .data = false };
|
||||
@ -569,8 +570,7 @@ int32_t FfiOHOSPasteDataAddRecord(int64_t id, int64_t recordId)
|
||||
return SUCCESS_CODE;
|
||||
}
|
||||
|
||||
|
||||
int32_t FfiOHOSPasteDataAddMimeTypeRecord(int64_t id, const char* mimeType, const char* value)
|
||||
int32_t FfiOHOSPasteDataAddMimeTypeRecord(int64_t id, const char *mimeType, const char *value)
|
||||
{
|
||||
LOGI("[PasteData] FfiOHOSPasteDataAddMimeTypeRecord start");
|
||||
auto instance = FFIData::GetData<PasteDataImpl>(id);
|
||||
@ -600,7 +600,7 @@ int32_t FfiOHOSPasteDataAddMimeTypeRecord(int64_t id, const char* mimeType, cons
|
||||
return SUCCESS_CODE;
|
||||
}
|
||||
|
||||
int32_t FfiOHOSPasteDataAddPixelMapRecord(int64_t id, const char* mimeType, int64_t pixelMapId)
|
||||
int32_t FfiOHOSPasteDataAddPixelMapRecord(int64_t id, const char *mimeType, int64_t pixelMapId)
|
||||
{
|
||||
LOGI("[PasteData] FfiOHOSPasteDataAddPixelMapRecord start");
|
||||
auto instance = FFIData::GetData<PasteDataImpl>(id);
|
||||
@ -631,7 +631,7 @@ int32_t FfiOHOSPasteDataAddPixelMapRecord(int64_t id, const char* mimeType, int6
|
||||
return SUCCESS_CODE;
|
||||
}
|
||||
|
||||
int32_t FfiOHOSPasteDataAddArrayRecord(int64_t id, const char* mimeType, uint8_t *buffPtr, int64_t bufferSize)
|
||||
int32_t FfiOHOSPasteDataAddArrayRecord(int64_t id, const char *mimeType, uint8_t *buffPtr, int64_t bufferSize)
|
||||
{
|
||||
LOGI("[PasteData] FfiOHOSPasteDataAddArrayRecord start");
|
||||
auto instance = FFIData::GetData<PasteDataImpl>(id);
|
||||
@ -650,8 +650,8 @@ int32_t FfiOHOSPasteDataAddArrayRecord(int64_t id, const char* mimeType, uint8_t
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
|
||||
pasteData->AddKvRecord(types,
|
||||
std::vector<uint8_t>(reinterpret_cast<uint8_t *>(data), reinterpret_cast<uint8_t *>(data) + dataLen));
|
||||
pasteData->AddKvRecord(
|
||||
types, std::vector<uint8_t>(reinterpret_cast<uint8_t *>(data), reinterpret_cast<uint8_t *>(data) + dataLen));
|
||||
LOGI("[PasteData] FfiOHOSPasteDataAddArrayRecord success");
|
||||
|
||||
return SUCCESS_CODE;
|
||||
@ -747,7 +747,7 @@ RetDataUI FfiOHOSPasteDataGetRecordCount(int64_t id)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret.data = pasteData ->GetRecordCount();
|
||||
ret.data = pasteData->GetRecordCount();
|
||||
ret.code = SUCCESS_CODE;
|
||||
LOGI("[PasteData] FfiOHOSPasteDataGetRecordCount success");
|
||||
|
||||
@ -930,7 +930,7 @@ RetDataBool FfiOHOSSystemPasteboardIsRemoteData(int64_t id)
|
||||
return ret;
|
||||
}
|
||||
|
||||
RetDataBool FfiOHOSSystemPasteboardHasDataType(int64_t id, const char* mimeType)
|
||||
RetDataBool FfiOHOSSystemPasteboardHasDataType(int64_t id, const char *mimeType)
|
||||
{
|
||||
RetDataBool ret = { .code = ERR_INVALID_INSTANCE_CODE, .data = false };
|
||||
LOGI("[SystemPasteboard] FfiOHOSSystemPasteboardHasDataType start");
|
||||
@ -968,5 +968,5 @@ RetDataCString FfiOHOSSystemPasteboardGetDataSource(int64_t id)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace CJSystemapi
|
||||
} // namespace OHOS
|
||||
|
@ -12,25 +12,25 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "system_pasteboard_impl.h"
|
||||
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_error.h"
|
||||
|
||||
#include "system_pasteboard_impl.h"
|
||||
|
||||
using namespace OHOS::MiscServices;
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServicesCj {
|
||||
|
||||
|
||||
static sptr<SystemPasteboardImpl> g_systemPasteboard_instance = nullptr;
|
||||
|
||||
OHOS::FFI::RuntimeType *SystemPasteboardImpl::GetClassType()
|
||||
{
|
||||
static OHOS::FFI::RuntimeType runtimeType =
|
||||
OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("SystemPasteboardImpl");
|
||||
static OHOS::FFI::RuntimeType runtimeType = OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("SystemPasteboardIm"
|
||||
"pl");
|
||||
return &runtimeType;
|
||||
}
|
||||
|
||||
|
||||
SystemPasteboardImpl::SystemPasteboardImpl()
|
||||
{
|
||||
value_ = nullptr;
|
||||
@ -130,5 +130,5 @@ std::string SystemPasteboardImpl::GetDataSource()
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace MiscServicesCj
|
||||
}
|
@ -116,3 +116,4 @@ private:
|
||||
} // namespace OHOS::MiscServicesNapi
|
||||
|
||||
#endif // PASTEBOARD_ASYNC_CALL_H
|
||||
// namespace OHOS
|
@ -26,9 +26,9 @@
|
||||
#include "pastedata_napi.h"
|
||||
#include "pastedata_record_napi.h"
|
||||
#include "pixel_map_napi.h"
|
||||
#include "uri.h"
|
||||
#include "unified_data.h"
|
||||
#include "unified_data_napi.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServicesNapi {
|
||||
@ -72,6 +72,7 @@ public:
|
||||
void GetPasteData(const std::string &type, MiscServices::PasteData &data) override;
|
||||
void GetUnifiedData(const std::string &type, UDMF::UnifiedData &data) override;
|
||||
void SetDelayGetterWrapper(const std::shared_ptr<PasteboardDelayGetterInstance> observerInstance);
|
||||
|
||||
private:
|
||||
std::weak_ptr<PasteboardDelayGetterInstance> wrapper_;
|
||||
};
|
||||
|
@ -14,7 +14,6 @@
|
||||
*/
|
||||
#define LOG_TAG "PasteBoardAsyncCall"
|
||||
#include "async_call.h"
|
||||
|
||||
#include "pasteboard_hilog.h"
|
||||
|
||||
using namespace OHOS::MiscServices;
|
||||
|
@ -13,7 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "napi_init.h"
|
||||
|
||||
#include "pasteboard_napi.h"
|
||||
#include "pastedata_napi.h"
|
||||
#include "pastedata_record_napi.h"
|
||||
@ -28,8 +27,8 @@ EXTERN_C_START
|
||||
static napi_value NapiInit(napi_env env, napi_value exports)
|
||||
{
|
||||
/*
|
||||
* Propertise define
|
||||
*/
|
||||
* Propertise define
|
||||
*/
|
||||
PasteDataRecordNapi::PasteDataRecordInit(env, exports);
|
||||
PasteDataNapi::PasteDataInit(env, exports);
|
||||
SystemPasteboardNapi::SystemPasteboardInit(env, exports);
|
||||
|
@ -266,7 +266,7 @@ napi_value PasteboardNapi::JScreatePattern(napi_env env, napi_callback_info info
|
||||
|
||||
napi_value jsEmailAddress = CreateNapiNumber(env, static_cast<uint32_t>(Pattern::EmailAddress));
|
||||
NAPI_CALL(env, napi_set_named_property(env, jsPattern, "EMAIL_ADDRESS", jsEmailAddress));
|
||||
|
||||
|
||||
return jsPattern;
|
||||
}
|
||||
|
||||
@ -464,8 +464,7 @@ napi_value PasteboardNapi::PasteBoardInit(napi_env env, napi_value exports)
|
||||
DECLARE_NAPI_FUNCTION("createWantData", JScreateWantData),
|
||||
DECLARE_NAPI_FUNCTION("createPlainTextData", JScreatePlainTextData),
|
||||
DECLARE_NAPI_FUNCTION("createPixelMapData", JScreatePixelMapData),
|
||||
DECLARE_NAPI_FUNCTION("createUriData", JScreateUriData),
|
||||
DECLARE_NAPI_FUNCTION("createData", JSCreateData),
|
||||
DECLARE_NAPI_FUNCTION("createUriData", JScreateUriData), DECLARE_NAPI_FUNCTION("createData", JSCreateData),
|
||||
DECLARE_NAPI_FUNCTION("createHtmlTextRecord", JScreateHtmlTextRecord),
|
||||
DECLARE_NAPI_FUNCTION("createWantRecord", JScreateWantRecord),
|
||||
DECLARE_NAPI_FUNCTION("createPlainTextRecord", JScreatePlainTextRecord),
|
||||
@ -473,8 +472,7 @@ napi_value PasteboardNapi::PasteBoardInit(napi_env env, napi_value exports)
|
||||
DECLARE_NAPI_FUNCTION("createUriRecord", JScreateUriRecord),
|
||||
DECLARE_NAPI_FUNCTION("createRecord", JSCreateRecord),
|
||||
DECLARE_NAPI_FUNCTION("getSystemPasteboard", JSgetSystemPasteboard),
|
||||
DECLARE_NAPI_GETTER("ShareOption", JScreateShareOption),
|
||||
DECLARE_NAPI_GETTER("Pattern", JScreatePattern),
|
||||
DECLARE_NAPI_GETTER("ShareOption", JScreateShareOption), DECLARE_NAPI_GETTER("Pattern", JScreatePattern),
|
||||
DECLARE_NAPI_PROPERTY("MAX_RECORD_NUM", CreateNapiNumber(env, PasteData::MAX_RECORD_NUM)),
|
||||
DECLARE_NAPI_PROPERTY("MIMETYPE_PIXELMAP", CreateNapiString(env, MIMETYPE_PIXELMAP)),
|
||||
DECLARE_NAPI_PROPERTY("MIMETYPE_TEXT_HTML", CreateNapiString(env, MIMETYPE_TEXT_HTML)),
|
||||
|
@ -41,9 +41,7 @@ PasteDataNapi::PasteDataNapi() : env_(nullptr)
|
||||
value_ = std::make_shared<PasteData>();
|
||||
}
|
||||
|
||||
PasteDataNapi::~PasteDataNapi()
|
||||
{
|
||||
}
|
||||
PasteDataNapi::~PasteDataNapi() {}
|
||||
|
||||
napi_value PasteDataNapi::AddHtmlRecord(napi_env env, napi_callback_info info)
|
||||
{
|
||||
@ -348,8 +346,8 @@ napi_value PasteDataNapi::RemoveRecord(napi_env env, napi_callback_info info)
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "RemoveRecord is called!");
|
||||
uint32_t index = 0;
|
||||
PasteDataNapi *obj = RemoveAndGetRecordCommon(env, info, index);
|
||||
if (obj == nullptr || !CheckExpression(env, index < obj->value_->GetRecordCount(),
|
||||
JSErrorCode::OUT_OF_RANGE, "index out of range.")) {
|
||||
if (obj == nullptr || !CheckExpression(env, index < obj->value_->GetRecordCount(), JSErrorCode::OUT_OF_RANGE,
|
||||
"index out of range.")) {
|
||||
return nullptr;
|
||||
}
|
||||
obj->value_->RemoveRecordAt(index);
|
||||
@ -674,8 +672,8 @@ napi_value PasteDataNapi::ReplaceRecord(napi_env env, napi_callback_info info)
|
||||
}
|
||||
uint32_t index = 0;
|
||||
NAPI_CALL(env, napi_get_value_uint32(env, argv[0], &index));
|
||||
if (!CheckExpression(env, index < obj->value_->GetRecordCount(),
|
||||
JSErrorCode::OUT_OF_RANGE, "index out of range.")) {
|
||||
if (!CheckExpression(env, index < obj->value_->GetRecordCount(), JSErrorCode::OUT_OF_RANGE,
|
||||
"index out of range.")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -825,8 +823,8 @@ napi_value PasteDataNapi::GetRecord(napi_env env, napi_callback_info info)
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_JS_NAPI, "GetRecord is called!");
|
||||
uint32_t index = 0;
|
||||
PasteDataNapi *obj = RemoveAndGetRecordCommon(env, info, index);
|
||||
if (obj == nullptr || !CheckExpression(env, index < obj->value_->GetRecordCount(),
|
||||
JSErrorCode::OUT_OF_RANGE, "index out of range.")) {
|
||||
if (obj == nullptr || !CheckExpression(env, index < obj->value_->GetRecordCount(), JSErrorCode::OUT_OF_RANGE,
|
||||
"index out of range.")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -864,8 +862,8 @@ void PasteDataNapi::SetProperty(napi_env env, napi_value in, PasteDataNapi *obj)
|
||||
if (propertyName == "tag") {
|
||||
char tagValue[STR_MAX_SIZE] = { 0 };
|
||||
size_t tagValueLen = 0;
|
||||
NAPI_CALL_RETURN_VOID(env,
|
||||
napi_get_value_string_utf8(env, propertyNameValueNapi, tagValue, STR_MAX_SIZE, &tagValueLen));
|
||||
NAPI_CALL_RETURN_VOID(
|
||||
env, napi_get_value_string_utf8(env, propertyNameValueNapi, tagValue, STR_MAX_SIZE, &tagValueLen));
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "tagValue = %{public}s", tagValue);
|
||||
std::string tagValueStr = tagValue;
|
||||
obj->value_->SetTag(tagValueStr);
|
||||
@ -931,7 +929,7 @@ napi_value PasteDataNapi::SetProperty(napi_env env, napi_callback_info info)
|
||||
if (!CheckExpression(env, argc > ARGC_TYPE_SET0, JSErrorCode::INVALID_PARAMETERS,
|
||||
"Parameter error. The number of arguments must be greater than zero.") ||
|
||||
!CheckExpression(env, IsProperty(env, argv[0]), JSErrorCode::INVALID_PARAMETERS,
|
||||
"Parameter error. The type of property must be PasteDataProperty.")) {
|
||||
"Parameter error. The type of property must be PasteDataProperty.")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -963,7 +961,7 @@ napi_value PasteDataNapi::PasteDataInit(napi_env env, napi_value exports)
|
||||
DECLARE_NAPI_FUNCTION("hasType", HasType), DECLARE_NAPI_FUNCTION("removeRecordAt", RemoveRecordAt),
|
||||
DECLARE_NAPI_FUNCTION("removeRecord", RemoveRecord), DECLARE_NAPI_FUNCTION("replaceRecordAt", ReplaceRecordAt),
|
||||
DECLARE_NAPI_FUNCTION("replaceRecord", ReplaceRecord), DECLARE_NAPI_FUNCTION("setProperty", SetProperty),
|
||||
DECLARE_NAPI_FUNCTION("pasteStart", PasteStart), DECLARE_NAPI_FUNCTION("pasteComplete", PasteComplete)};
|
||||
DECLARE_NAPI_FUNCTION("pasteStart", PasteStart), DECLARE_NAPI_FUNCTION("pasteComplete", PasteComplete) };
|
||||
|
||||
napi_value constructor;
|
||||
napi_define_class(env, "PasteData", NAPI_AUTO_LENGTH, New, nullptr,
|
||||
|
@ -31,13 +31,9 @@ const int ARGC_TYPE_SET0 = 0;
|
||||
const int ARGC_TYPE_SET1 = 1;
|
||||
constexpr int32_t MIMETYPE_MAX_SIZE = 1024;
|
||||
|
||||
PasteDataRecordNapi::PasteDataRecordNapi() : env_(nullptr)
|
||||
{
|
||||
}
|
||||
PasteDataRecordNapi::PasteDataRecordNapi() : env_(nullptr) {}
|
||||
|
||||
PasteDataRecordNapi::~PasteDataRecordNapi()
|
||||
{
|
||||
}
|
||||
PasteDataRecordNapi::~PasteDataRecordNapi() {}
|
||||
|
||||
bool PasteDataRecordNapi::NewInstanceByRecord(
|
||||
napi_env env, napi_value &instance, const std::shared_ptr<MiscServices::PasteDataRecord> &record)
|
||||
@ -336,11 +332,8 @@ napi_value PasteDataRecordNapi::ToPlainText(napi_env env, napi_callback_info inf
|
||||
|
||||
napi_value PasteDataRecordNapi::PasteDataRecordInit(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor properties[] = {
|
||||
DECLARE_NAPI_FUNCTION("convertToText", ConvertToText),
|
||||
DECLARE_NAPI_FUNCTION("convertToTextV9", ConvertToTextV9),
|
||||
DECLARE_NAPI_FUNCTION("toPlainText", ToPlainText)
|
||||
};
|
||||
napi_property_descriptor properties[] = { DECLARE_NAPI_FUNCTION("convertToText", ConvertToText),
|
||||
DECLARE_NAPI_FUNCTION("convertToTextV9", ConvertToTextV9), DECLARE_NAPI_FUNCTION("toPlainText", ToPlainText) };
|
||||
|
||||
napi_status status = napi_ok;
|
||||
|
||||
|
@ -12,10 +12,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "pasteboard_common.h"
|
||||
|
||||
#include "napi_common_want.h"
|
||||
#include "paste_data_record.h"
|
||||
#include "pasteboard_common.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "pasteboard_js_err.h"
|
||||
#include "pixel_map_napi.h"
|
||||
@ -99,12 +98,12 @@ bool GetValue(napi_env env, napi_value in, std::set<MiscServices::Pattern> &out)
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "Wrong argument type. pattern/uint32 array expected.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uint32_t len = 0;
|
||||
napi_status status = napi_get_array_length(env, in, &len);
|
||||
if (status != napi_ok || len == 0) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "napi_get_array_length status = %{public}d, len = %{public}d",
|
||||
status, len);
|
||||
PASTEBOARD_HILOGE(
|
||||
PASTEBOARD_MODULE_JS_NAPI, "napi_get_array_length status = %{public}d, len = %{public}d", status, len);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -119,13 +118,11 @@ bool GetValue(napi_env env, napi_value in, std::set<MiscServices::Pattern> &out)
|
||||
uint32_t pattern;
|
||||
status = napi_get_value_uint32(env, element, &pattern);
|
||||
if (status != napi_ok) {
|
||||
PASTEBOARD_HILOGE(
|
||||
PASTEBOARD_MODULE_JS_NAPI, "napi_get_value_uint32 err status = %{public}d", status);
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "napi_get_value_uint32 err status = %{public}d", status);
|
||||
return false;
|
||||
}
|
||||
if (pattern >= static_cast<uint32_t>(Pattern::PatternCount)) {
|
||||
PASTEBOARD_HILOGE(
|
||||
PASTEBOARD_MODULE_JS_NAPI, "Unsurportted pattern value: %{public}d", pattern);
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_JS_NAPI, "Unsurportted pattern value: %{public}d", pattern);
|
||||
return false;
|
||||
}
|
||||
out.insert(static_cast<Pattern>(pattern));
|
||||
@ -200,7 +197,7 @@ bool CheckArgs(napi_env env, napi_value *argv, size_t argc, std::string &mimeTyp
|
||||
if (!CheckExpression(
|
||||
env, mimeType != "", JSErrorCode::INVALID_PARAMETERS, "Parameter error. mimeType cannot be empty.") ||
|
||||
!CheckExpression(env, mimeType.size() <= MIMETYPE_MAX_SIZE, JSErrorCode::INVALID_PARAMETERS,
|
||||
"Parameter error. The length of mimeType cannot be greater than 1024 bytes.")) {
|
||||
"Parameter error. The length of mimeType cannot be greater than 1024 bytes.")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -210,7 +207,7 @@ bool CheckArgs(napi_env env, napi_value *argv, size_t argc, std::string &mimeTyp
|
||||
}
|
||||
} else if (mimeType == MIMETYPE_PIXELMAP) {
|
||||
if (!CheckExpression(env, Media::PixelMapNapi::GetPixelMap(env, argv[1]) != nullptr,
|
||||
JSErrorCode::INVALID_PARAMETERS, "Parameter error. Actual mimeType is not mimetype_pixelmap.")) {
|
||||
JSErrorCode::INVALID_PARAMETERS, "Parameter error. Actual mimeType is not mimetype_pixelmap.")) {
|
||||
return false;
|
||||
}
|
||||
} else if (mimeType == MIMETYPE_TEXT_WANT) {
|
||||
|
@ -16,22 +16,23 @@
|
||||
#define OH_PASTEBOARD_COMMON_H
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "pasteboard_observer.h"
|
||||
|
||||
#include "oh_pasteboard.h"
|
||||
#include "pasteboard_error.h"
|
||||
#include "oh_pasteboard_err_code.h"
|
||||
#include "pasteboard_error.h"
|
||||
#include "pasteboard_observer.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
const std::map<PasteboardError, PASTEBOARD_ErrCode> errCodeMap = {
|
||||
{PasteboardError::PERMISSION_VERIFICATION_ERROR, ERR_PERMISSION_ERROR},
|
||||
{PasteboardError::INVALID_PARAM_ERROR, ERR_INVALID_PARAMETER},
|
||||
{PasteboardError::TASK_PROCESSING, ERR_BUSY},
|
||||
{ PasteboardError::PERMISSION_VERIFICATION_ERROR, ERR_PERMISSION_ERROR },
|
||||
{ PasteboardError::INVALID_PARAM_ERROR, ERR_INVALID_PARAMETER },
|
||||
{ PasteboardError::TASK_PROCESSING, ERR_BUSY },
|
||||
};
|
||||
|
||||
class PasteboardObserverCapiImpl;
|
||||
}
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
enum PasteboardNdkStructId : std::int64_t {
|
||||
SUBSCRIBER_STRUCT_ID = 1002950,
|
||||
@ -41,7 +42,7 @@ enum PasteboardNdkStructId : std::int64_t {
|
||||
struct OH_Pasteboard {
|
||||
const int64_t cid = PASTEBOARD_STRUCT_ID;
|
||||
std::mutex mutex;
|
||||
std::map<const OH_PasteboardObserver*, OHOS::sptr<OHOS::MiscServices::PasteboardObserverCapiImpl>> observers_;
|
||||
std::map<const OH_PasteboardObserver *, OHOS::sptr<OHOS::MiscServices::PasteboardObserverCapiImpl>> observers_;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
@ -36,7 +36,6 @@
|
||||
* @since 13
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OH_PASTEBOARD_ERR_CODE_H
|
||||
#define OH_PASTEBOARD_ERR_CODE_H
|
||||
|
||||
|
@ -16,14 +16,15 @@
|
||||
#define OH_PASTEBOARD_OBSERVER_IMPL_H
|
||||
|
||||
#include <memory>
|
||||
#include "pasteboard_observer.h"
|
||||
|
||||
#include "oh_pasteboard_common.h"
|
||||
#include "pasteboard_observer.h"
|
||||
|
||||
struct OH_PasteboardObserver {
|
||||
const int64_t cid = SUBSCRIBER_STRUCT_ID;
|
||||
Pasteboard_Notify callback { nullptr };
|
||||
void* context { nullptr };
|
||||
Pasteboard_Finalize finalize { nullptr };
|
||||
Pasteboard_Notify callback{ nullptr };
|
||||
void *context{ nullptr };
|
||||
Pasteboard_Finalize finalize{ nullptr };
|
||||
};
|
||||
|
||||
namespace OHOS {
|
||||
@ -33,13 +34,14 @@ public:
|
||||
void OnPasteboardChanged() override;
|
||||
void SetType(Pasteboard_NotifyType type);
|
||||
Pasteboard_NotifyType GetType();
|
||||
void SetInnerObserver(const OH_PasteboardObserver* observer);
|
||||
void SetInnerObserver(const OH_PasteboardObserver *observer);
|
||||
|
||||
private:
|
||||
const OH_PasteboardObserver* innerObserver_;
|
||||
const OH_PasteboardObserver *innerObserver_;
|
||||
Pasteboard_NotifyType type_;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
/** @} */
|
||||
#endif
|
@ -15,27 +15,28 @@
|
||||
|
||||
#define LOG_TAG "Pasteboard_Capi"
|
||||
|
||||
#include "oh_pasteboard.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
#include "udmf.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "i_pasteboard_observer.h"
|
||||
#include "oh_pasteboard.h"
|
||||
#include "oh_pasteboard_err_code.h"
|
||||
#include "oh_pasteboard_observer_impl.h"
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "pasteboard_error.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "udmf.h"
|
||||
#include "udmf_capi_common.h"
|
||||
#include "i_pasteboard_observer.h"
|
||||
|
||||
using namespace OHOS::MiscServices;
|
||||
static bool IsPasteboardValid(OH_Pasteboard* pasteboard)
|
||||
static bool IsPasteboardValid(OH_Pasteboard *pasteboard)
|
||||
{
|
||||
return pasteboard != nullptr && pasteboard->cid == PASTEBOARD_STRUCT_ID;
|
||||
}
|
||||
|
||||
static bool IsSubscriberValid(OH_PasteboardObserver* observer)
|
||||
static bool IsSubscriberValid(OH_PasteboardObserver *observer)
|
||||
{
|
||||
return observer != nullptr && observer->cid == SUBSCRIBER_STRUCT_ID;
|
||||
}
|
||||
@ -49,9 +50,9 @@ static PASTEBOARD_ErrCode GetMappedCode(int32_t code)
|
||||
return ERR_INNER_ERROR;
|
||||
}
|
||||
|
||||
OH_PasteboardObserver* OH_PasteboardObserver_Create()
|
||||
OH_PasteboardObserver *OH_PasteboardObserver_Create()
|
||||
{
|
||||
OH_PasteboardObserver* observer = new(std::nothrow) OH_PasteboardObserver();
|
||||
OH_PasteboardObserver *observer = new (std::nothrow) OH_PasteboardObserver();
|
||||
if (observer == nullptr) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CAPI, "allocate memory fail.");
|
||||
return nullptr;
|
||||
@ -59,7 +60,7 @@ OH_PasteboardObserver* OH_PasteboardObserver_Create()
|
||||
return observer;
|
||||
}
|
||||
|
||||
int OH_PasteboardObserver_Destroy(OH_PasteboardObserver* observer)
|
||||
int OH_PasteboardObserver_Destroy(OH_PasteboardObserver *observer)
|
||||
{
|
||||
if (!IsSubscriberValid(observer)) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
@ -72,8 +73,8 @@ int OH_PasteboardObserver_Destroy(OH_PasteboardObserver* observer)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int OH_PasteboardObserver_SetData(OH_PasteboardObserver* observer, void* context,
|
||||
const Pasteboard_Notify callback, const Pasteboard_Finalize finalize)
|
||||
int OH_PasteboardObserver_SetData(OH_PasteboardObserver *observer, void *context, const Pasteboard_Notify callback,
|
||||
const Pasteboard_Finalize finalize)
|
||||
{
|
||||
if (observer == nullptr || callback == nullptr) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
@ -88,9 +89,9 @@ int OH_PasteboardObserver_SetData(OH_PasteboardObserver* observer, void* context
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
OH_Pasteboard* OH_Pasteboard_Create()
|
||||
OH_Pasteboard *OH_Pasteboard_Create()
|
||||
{
|
||||
OH_Pasteboard* pasteboard = new (std::nothrow) OH_Pasteboard();
|
||||
OH_Pasteboard *pasteboard = new (std::nothrow) OH_Pasteboard();
|
||||
if (pasteboard == nullptr) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CAPI, "allocate memory fail.");
|
||||
return nullptr;
|
||||
@ -98,7 +99,7 @@ OH_Pasteboard* OH_Pasteboard_Create()
|
||||
return pasteboard;
|
||||
}
|
||||
|
||||
void OH_Pasteboard_Destroy(OH_Pasteboard* pasteboard)
|
||||
void OH_Pasteboard_Destroy(OH_Pasteboard *pasteboard)
|
||||
{
|
||||
if (!IsPasteboardValid(pasteboard)) {
|
||||
return;
|
||||
@ -114,10 +115,10 @@ void OH_Pasteboard_Destroy(OH_Pasteboard* pasteboard)
|
||||
delete pasteboard;
|
||||
}
|
||||
|
||||
int OH_Pasteboard_Subscribe(OH_Pasteboard* pasteboard, int type, const OH_PasteboardObserver* observer)
|
||||
int OH_Pasteboard_Subscribe(OH_Pasteboard *pasteboard, int type, const OH_PasteboardObserver *observer)
|
||||
{
|
||||
if (!IsPasteboardValid(pasteboard) || observer == nullptr || type < NOTIFY_LOCAL_DATA_CHANGE
|
||||
|| type > NOTIFY_REMOTE_DATA_CHANGE) {
|
||||
if (!IsPasteboardValid(pasteboard) || observer == nullptr || type < NOTIFY_LOCAL_DATA_CHANGE ||
|
||||
type > NOTIFY_REMOTE_DATA_CHANGE) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(pasteboard->mutex);
|
||||
@ -137,10 +138,10 @@ int OH_Pasteboard_Subscribe(OH_Pasteboard* pasteboard, int type, const OH_Pasteb
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int OH_Pasteboard_Unsubscribe(OH_Pasteboard* pasteboard, int type, const OH_PasteboardObserver* observer)
|
||||
int OH_Pasteboard_Unsubscribe(OH_Pasteboard *pasteboard, int type, const OH_PasteboardObserver *observer)
|
||||
{
|
||||
if (!IsPasteboardValid(pasteboard) || observer == nullptr || type < NOTIFY_LOCAL_DATA_CHANGE
|
||||
|| type > NOTIFY_REMOTE_DATA_CHANGE) {
|
||||
if (!IsPasteboardValid(pasteboard) || observer == nullptr || type < NOTIFY_LOCAL_DATA_CHANGE ||
|
||||
type > NOTIFY_REMOTE_DATA_CHANGE) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(pasteboard->mutex);
|
||||
@ -154,7 +155,7 @@ int OH_Pasteboard_Unsubscribe(OH_Pasteboard* pasteboard, int type, const OH_Past
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
bool OH_Pasteboard_IsRemoteData(OH_Pasteboard* pasteboard)
|
||||
bool OH_Pasteboard_IsRemoteData(OH_Pasteboard *pasteboard)
|
||||
{
|
||||
if (!IsPasteboardValid(pasteboard)) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
@ -162,7 +163,7 @@ bool OH_Pasteboard_IsRemoteData(OH_Pasteboard* pasteboard)
|
||||
return PasteboardClient::GetInstance()->IsRemoteData();
|
||||
}
|
||||
|
||||
int OH_Pasteboard_GetDataSource(OH_Pasteboard* pasteboard, char* source, unsigned int len)
|
||||
int OH_Pasteboard_GetDataSource(OH_Pasteboard *pasteboard, char *source, unsigned int len)
|
||||
{
|
||||
if (!IsPasteboardValid(pasteboard) || source == nullptr || len == 0) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
@ -170,8 +171,7 @@ int OH_Pasteboard_GetDataSource(OH_Pasteboard* pasteboard, char* source, unsigne
|
||||
std::string bundleName;
|
||||
auto ret = PasteboardClient::GetInstance()->GetDataSource(bundleName);
|
||||
if (ret != static_cast<int32_t>(PasteboardError::E_OK)) {
|
||||
PASTEBOARD_HILOGE(
|
||||
PASTEBOARD_MODULE_CAPI, "client getDataSource return invalid, result is %{public}d", ret);
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CAPI, "client getDataSource return invalid, result is %{public}d", ret);
|
||||
return GetMappedCode(ret);
|
||||
}
|
||||
if (strcpy_s(source, len, bundleName.c_str()) != EOK) {
|
||||
@ -181,7 +181,7 @@ int OH_Pasteboard_GetDataSource(OH_Pasteboard* pasteboard, char* source, unsigne
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
bool OH_Pasteboard_HasType(OH_Pasteboard* pasteboard, const char* type)
|
||||
bool OH_Pasteboard_HasType(OH_Pasteboard *pasteboard, const char *type)
|
||||
{
|
||||
if (!IsPasteboardValid(pasteboard) || type == nullptr) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
@ -189,7 +189,7 @@ bool OH_Pasteboard_HasType(OH_Pasteboard* pasteboard, const char* type)
|
||||
return PasteboardClient::GetInstance()->HasDataType(std::string(type));
|
||||
}
|
||||
|
||||
bool OH_Pasteboard_HasData(OH_Pasteboard* pasteboard)
|
||||
bool OH_Pasteboard_HasData(OH_Pasteboard *pasteboard)
|
||||
{
|
||||
if (!IsPasteboardValid(pasteboard)) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
@ -197,7 +197,7 @@ bool OH_Pasteboard_HasData(OH_Pasteboard* pasteboard)
|
||||
return PasteboardClient::GetInstance()->HasPasteData();
|
||||
}
|
||||
|
||||
OH_UdmfData* OH_Pasteboard_GetData(OH_Pasteboard* pasteboard, int* status)
|
||||
OH_UdmfData *OH_Pasteboard_GetData(OH_Pasteboard *pasteboard, int *status)
|
||||
{
|
||||
if (!IsPasteboardValid(pasteboard) || status == nullptr) {
|
||||
return nullptr;
|
||||
@ -210,13 +210,13 @@ OH_UdmfData* OH_Pasteboard_GetData(OH_Pasteboard* pasteboard, int* status)
|
||||
*status = GetMappedCode(ret);
|
||||
return nullptr;
|
||||
}
|
||||
OH_UdmfData* data = OH_UdmfData_Create();
|
||||
OH_UdmfData *data = OH_UdmfData_Create();
|
||||
data->unifiedData_ = std::move(unifiedData);
|
||||
*status = ERR_OK;
|
||||
return data;
|
||||
}
|
||||
|
||||
int OH_Pasteboard_SetData(OH_Pasteboard* pasteboard, OH_UdmfData* data)
|
||||
int OH_Pasteboard_SetData(OH_Pasteboard *pasteboard, OH_UdmfData *data)
|
||||
{
|
||||
if (!IsPasteboardValid(pasteboard) || data == nullptr) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
@ -230,11 +230,11 @@ int OH_Pasteboard_SetData(OH_Pasteboard* pasteboard, OH_UdmfData* data)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int OH_Pasteboard_ClearData(OH_Pasteboard* pasteboard)
|
||||
int OH_Pasteboard_ClearData(OH_Pasteboard *pasteboard)
|
||||
{
|
||||
if (!IsPasteboardValid(pasteboard)) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
}
|
||||
PasteboardClient::GetInstance()->Clear();
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace OHOS
|
@ -15,9 +15,9 @@
|
||||
|
||||
#define LOG_TAG "Pasteboard_Observer_Impl"
|
||||
|
||||
#include "oh_pasteboard_common.h"
|
||||
#include "oh_pasteboard_observer_impl.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "oh_pasteboard_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -40,9 +40,9 @@ Pasteboard_NotifyType PasteboardObserverCapiImpl::GetType()
|
||||
return type_;
|
||||
}
|
||||
|
||||
void PasteboardObserverCapiImpl::SetInnerObserver(const OH_PasteboardObserver* innerObserver)
|
||||
void PasteboardObserverCapiImpl::SetInnerObserver(const OH_PasteboardObserver *innerObserver)
|
||||
{
|
||||
innerObserver_ = innerObserver;
|
||||
}
|
||||
}
|
||||
} // namespace MiscServices
|
||||
}
|
@ -24,7 +24,7 @@ namespace MiscServices {
|
||||
class IPasteboardEntryGetter : public IRemoteBroker {
|
||||
public:
|
||||
virtual ~IPasteboardEntryGetter() = default;
|
||||
virtual int32_t GetRecordValueByType(uint32_t recordId, PasteDataEntry& value) = 0;
|
||||
virtual int32_t GetRecordValueByType(uint32_t recordId, PasteDataEntry &value) = 0;
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.misc.services.pasteboard.IPasteboardEntryGetter");
|
||||
};
|
||||
} // namespace MiscServices
|
||||
|
@ -20,17 +20,8 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
enum class PasteboardEventStatus {
|
||||
PASTEBOARD_CLEAR = 1,
|
||||
PASTEBOARD_READ = 2,
|
||||
PASTEBOARD_WRITE = 3
|
||||
};
|
||||
enum class PasteboardObserverType {
|
||||
OBSERVER_LOCAL = 1,
|
||||
OBSERVER_REMOTE = 2,
|
||||
OBSERVER_ALL = 3,
|
||||
OBSERVER_EVENT = 4
|
||||
};
|
||||
enum class PasteboardEventStatus { PASTEBOARD_CLEAR = 1, PASTEBOARD_READ = 2, PASTEBOARD_WRITE = 3 };
|
||||
enum class PasteboardObserverType { OBSERVER_LOCAL = 1, OBSERVER_REMOTE = 2, OBSERVER_ALL = 3, OBSERVER_EVENT = 4 };
|
||||
class IPasteboardChangedObserver : public IRemoteBroker {
|
||||
public:
|
||||
virtual void OnPasteboardChanged() = 0;
|
||||
|
@ -16,8 +16,8 @@
|
||||
#ifndef PASTE_BOARD_SERVICE_INTERFACE_H
|
||||
#define PASTE_BOARD_SERVICE_INTERFACE_H
|
||||
|
||||
#include "i_pasteboard_entry_getter.h"
|
||||
#include "i_pasteboard_delay_getter.h"
|
||||
#include "i_pasteboard_entry_getter.h"
|
||||
#include "i_pasteboard_observer.h"
|
||||
#include "iremote_broker.h"
|
||||
#include "paste_data.h"
|
||||
@ -38,8 +38,7 @@ public:
|
||||
virtual bool HasDataType(const std::string &mimeType) = 0;
|
||||
virtual std::set<Pattern> DetectPatterns(const std::set<Pattern> &patternsToCheck) = 0;
|
||||
virtual void SubscribeObserver(PasteboardObserverType type, const sptr<IPasteboardChangedObserver> &observer) = 0;
|
||||
virtual void UnsubscribeObserver(PasteboardObserverType type,
|
||||
const sptr<IPasteboardChangedObserver> &observer) = 0;
|
||||
virtual void UnsubscribeObserver(PasteboardObserverType type, const sptr<IPasteboardChangedObserver> &observer) = 0;
|
||||
virtual void UnsubscribeAllObserver(PasteboardObserverType type) = 0;
|
||||
virtual int32_t SetGlobalShareOption(const std::map<uint32_t, ShareOption> &globalShareOptions) = 0;
|
||||
virtual int32_t RemoveGlobalShareOption(const std::vector<uint32_t> &tokenIds) = 0;
|
||||
|
@ -24,9 +24,11 @@ class PasteBoardCommonEventSubscriber : public EventFwk::CommonEventSubscriber {
|
||||
public:
|
||||
PasteBoardCommonEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
|
||||
: EventFwk::CommonEventSubscriber(subscribeInfo)
|
||||
{}
|
||||
{
|
||||
}
|
||||
~PasteBoardCommonEventSubscriber() = default;
|
||||
void OnReceiveEvent(const EventFwk::CommonEventData &data) override;
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
@ -29,9 +29,9 @@ public:
|
||||
struct ToastMessageInfo {
|
||||
std::string appName{ DEFAULT_LABEL };
|
||||
};
|
||||
static constexpr uint32_t POPUP_INTERVAL = 1000; // milliseconds
|
||||
static constexpr uint32_t POPUP_INTERVAL = 1000; // milliseconds
|
||||
static constexpr uint32_t MAX_LIFE_TIME = 300 * 1000; // milliseconds
|
||||
static constexpr uint32_t SHOW_TOAST_TIME = 3000; // milliseconds
|
||||
static constexpr uint32_t SHOW_TOAST_TIME = 3000; // milliseconds
|
||||
static constexpr const char *DEFAULT_LABEL = "unknown";
|
||||
using Cancel = std::function<void()>;
|
||||
static PasteBoardDialog &GetInstance();
|
||||
|
@ -16,9 +16,9 @@
|
||||
#ifndef PASTE_BOARD_PATTERN_H
|
||||
#define PASTE_BOARD_PATTERN_H
|
||||
|
||||
#include <map>
|
||||
#include <regex>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
#include "paste_data.h"
|
||||
|
||||
@ -26,13 +26,14 @@ namespace OHOS::MiscServices {
|
||||
enum class Pattern : uint32_t { URL = 0, Number, EmailAddress, PatternCount };
|
||||
class PatternDetection {
|
||||
public:
|
||||
static const std::set<Pattern> Detect(const std::set<Pattern> &patternsToCheck,
|
||||
const PasteData &pasteData, bool hasHTML, bool hasPlain);
|
||||
static const std::set<Pattern> Detect(
|
||||
const std::set<Pattern> &patternsToCheck, const PasteData &pasteData, bool hasHTML, bool hasPlain);
|
||||
static bool IsValid(const std::set<Pattern> &patterns);
|
||||
|
||||
private:
|
||||
static std::string ExtractHtmlContent(const std::string &html_str);
|
||||
static void DetectPlainText(std::set<Pattern> &patternsOut, const std::set<Pattern> &PatternsIn,
|
||||
const std::string &plainText);
|
||||
static void DetectPlainText(
|
||||
std::set<Pattern> &patternsOut, const std::set<Pattern> &PatternsIn, const std::string &plainText);
|
||||
|
||||
static std::map<uint32_t, std::string> patterns_;
|
||||
};
|
||||
|
@ -35,21 +35,21 @@
|
||||
#include "common/block_object.h"
|
||||
#include "common/concurrent_map.h"
|
||||
#include "distributed_module_config.h"
|
||||
#include "eventcenter/event_center.h"
|
||||
#include "pasteboard_switch.h"
|
||||
#include "event_handler.h"
|
||||
#include "iremote_object.h"
|
||||
#include "eventcenter/event_center.h"
|
||||
#include "ffrt_utils.h"
|
||||
#include "i_pasteboard_delay_getter.h"
|
||||
#include "i_pasteboard_observer.h"
|
||||
#include "pasteboard_common_event_subscriber.h"
|
||||
#include "input_manager.h"
|
||||
#include "iremote_object.h"
|
||||
#include "paste_data.h"
|
||||
#include "pasteboard_common_event_subscriber.h"
|
||||
#include "pasteboard_dump_helper.h"
|
||||
#include "pasteboard_service_stub.h"
|
||||
#include "system_ability.h"
|
||||
#include "pasteboard_switch.h"
|
||||
#include "privacy_kit.h"
|
||||
#include "input_manager.h"
|
||||
#include "ffrt_utils.h"
|
||||
#include "security_level.h"
|
||||
#include "system_ability.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@ -87,6 +87,7 @@ public:
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
|
||||
bool IsCtrlVProcess(uint32_t callingPid, bool isFocused);
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
static constexpr uint32_t EVENT_TIME_OUT = 2000;
|
||||
mutable int32_t windowPid_;
|
||||
@ -110,10 +111,10 @@ public:
|
||||
virtual bool HasDataType(const std::string &mimeType) override;
|
||||
virtual std::set<Pattern> DetectPatterns(const std::set<Pattern> &patternsToCheck) override;
|
||||
virtual int32_t GetDataSource(std::string &bundleNme) override;
|
||||
virtual void SubscribeObserver(PasteboardObserverType type,
|
||||
const sptr<IPasteboardChangedObserver> &observer) override;
|
||||
virtual void UnsubscribeObserver(PasteboardObserverType type,
|
||||
const sptr<IPasteboardChangedObserver> &observer) override;
|
||||
virtual void SubscribeObserver(
|
||||
PasteboardObserverType type, const sptr<IPasteboardChangedObserver> &observer) override;
|
||||
virtual void UnsubscribeObserver(
|
||||
PasteboardObserverType type, const sptr<IPasteboardChangedObserver> &observer) override;
|
||||
virtual void UnsubscribeAllObserver(PasteboardObserverType type) override;
|
||||
virtual int32_t SetGlobalShareOption(const std::map<uint32_t, ShareOption> &globalShareOptions) override;
|
||||
virtual int32_t RemoveGlobalShareOption(const std::vector<uint32_t> &tokenIds) override;
|
||||
@ -156,7 +157,8 @@ private:
|
||||
public:
|
||||
explicit DelayGetterDeathRecipient(int32_t userId, PasteboardService &service);
|
||||
virtual ~DelayGetterDeathRecipient() = default;
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
|
||||
|
||||
private:
|
||||
int32_t userId_ = ERROR_USERID;
|
||||
PasteboardService &service_;
|
||||
@ -166,7 +168,8 @@ private:
|
||||
public:
|
||||
explicit EntryGetterDeathRecipient(int32_t userId, PasteboardService &service);
|
||||
virtual ~EntryGetterDeathRecipient() = default;
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
|
||||
|
||||
private:
|
||||
int32_t userId_ = ERROR_USERID;
|
||||
PasteboardService &service_;
|
||||
@ -176,14 +179,15 @@ private:
|
||||
public:
|
||||
struct TaskContext {
|
||||
std::atomic<bool> pasting_ = false;
|
||||
ConcurrentMap<uint32_t, std::shared_ptr<BlockObject<bool>>> getDataBlocks_;
|
||||
std::shared_ptr<PasteDateTime> data_;
|
||||
ConcurrentMap<uint32_t, std::shared_ptr<BlockObject<bool>>> getDataBlocks_;
|
||||
std::shared_ptr<PasteDateTime> data_;
|
||||
};
|
||||
using DataTask = std::pair<std::shared_ptr<PasteboardService::RemoteDataTaskManager::TaskContext>, bool>;
|
||||
DataTask GetRemoteDataTask(const Event &event);
|
||||
void Notify(const Event &event, std::shared_ptr<PasteDateTime> data);
|
||||
void ClearRemoteDataTask(const Event &event);
|
||||
std::shared_ptr<PasteDateTime> WaitRemoteData(const Event &event);
|
||||
|
||||
private:
|
||||
std::atomic<uint32_t> mapKey_ = 0;
|
||||
std::mutex mutex_;
|
||||
@ -208,20 +212,18 @@ private:
|
||||
void InitServiceHandler();
|
||||
bool IsCopyable(uint32_t tokenId) const;
|
||||
|
||||
int32_t SavePasteData(std::shared_ptr<PasteData> &pasteData,
|
||||
sptr<IPasteboardDelayGetter> delayGetter = nullptr,
|
||||
int32_t SavePasteData(std::shared_ptr<PasteData> &pasteData, sptr<IPasteboardDelayGetter> delayGetter = nullptr,
|
||||
sptr<IPasteboardEntryGetter> entryGetter = nullptr) override;
|
||||
int32_t SaveData(std::shared_ptr<PasteData>& pasteData,
|
||||
sptr<IPasteboardDelayGetter> delayGetter = nullptr,
|
||||
int32_t SaveData(std::shared_ptr<PasteData> &pasteData, sptr<IPasteboardDelayGetter> delayGetter = nullptr,
|
||||
sptr<IPasteboardEntryGetter> entryGetter = nullptr);
|
||||
void HandleDelayDataAndRecord(std::shared_ptr<PasteData> &pasteData,
|
||||
sptr<IPasteboardDelayGetter> delayGetter, sptr<IPasteboardEntryGetter> entryGetter, const AppInfo& appInfo);
|
||||
void HandleDelayDataAndRecord(std::shared_ptr<PasteData> &pasteData, sptr<IPasteboardDelayGetter> delayGetter,
|
||||
sptr<IPasteboardEntryGetter> entryGetter, const AppInfo &appInfo);
|
||||
int32_t PreParePasteData(std::shared_ptr<PasteData> &pasteData, const AppInfo &appInfo);
|
||||
void RemovePasteData(const AppInfo &appInfo);
|
||||
void SetPasteDataDot(PasteData &pasteData);
|
||||
std::pair<bool, ClipPlugin::GlobalEvent> GetValidDistributeEvent(int32_t user);
|
||||
int32_t GetSdkVersion(uint32_t tokenId);
|
||||
bool IsPermissionGranted(const std::string& perm, uint32_t tokenId);
|
||||
bool IsPermissionGranted(const std::string &perm, uint32_t tokenId);
|
||||
int32_t GetData(uint32_t tokenId, PasteData &data, int32_t &syncTime);
|
||||
|
||||
void GetPasteDataDot(PasteData &pasteData, const std::string &bundleName);
|
||||
@ -239,8 +241,8 @@ private:
|
||||
void CheckAppUriPermission(PasteData &data);
|
||||
std::string GetAppLabel(uint32_t tokenId);
|
||||
sptr<OHOS::AppExecFwk::IBundleMgr> GetAppBundleManager();
|
||||
void EstablishP2PLink(const std::string& networkId, const std::string &pasteId);
|
||||
void CloseP2PLink(const std::string& networkId);
|
||||
void EstablishP2PLink(const std::string &networkId, const std::string &pasteId);
|
||||
void CloseP2PLink(const std::string &networkId);
|
||||
uint8_t GenerateDataType(PasteData &data);
|
||||
bool HasDistributedDataType(const std::string &mimeType);
|
||||
|
||||
@ -293,13 +295,8 @@ private:
|
||||
static std::shared_ptr<Command> copyData;
|
||||
std::atomic<bool> setting_ = false;
|
||||
std::map<int32_t, ServiceListenerFunc> ServiceListenerFunc_;
|
||||
std::map<std::string, int> typeMap_ = {
|
||||
{ MIMETYPE_TEXT_PLAIN, PLAIN_INDEX },
|
||||
{ MIMETYPE_TEXT_HTML, HTML_INDEX },
|
||||
{ MIMETYPE_TEXT_URI, URI_INDEX },
|
||||
{ MIMETYPE_TEXT_WANT, WANT_INDEX },
|
||||
{ MIMETYPE_PIXELMAP, PIXELMAP_INDEX }
|
||||
};
|
||||
std::map<std::string, int> typeMap_ = { { MIMETYPE_TEXT_PLAIN, PLAIN_INDEX }, { MIMETYPE_TEXT_HTML, HTML_INDEX },
|
||||
{ MIMETYPE_TEXT_URI, URI_INDEX }, { MIMETYPE_TEXT_WANT, WANT_INDEX }, { MIMETYPE_PIXELMAP, PIXELMAP_INDEX } };
|
||||
|
||||
std::shared_ptr<FFRTTimer> ffrtTimer_;
|
||||
ConcurrentMap<std::string, ConcurrentMap<std::string, int32_t>> p2pMap_;
|
||||
@ -307,8 +304,8 @@ private:
|
||||
PastedSwitch switch_;
|
||||
|
||||
void AddObserver(int32_t userId, const sptr<IPasteboardChangedObserver> &observer, ObserverMap &observerMap);
|
||||
void RemoveSingleObserver(int32_t userId, const sptr<IPasteboardChangedObserver> &observer,
|
||||
ObserverMap &observerMap);
|
||||
void RemoveSingleObserver(
|
||||
int32_t userId, const sptr<IPasteboardChangedObserver> &observer, ObserverMap &observerMap);
|
||||
void RemoveAllObserver(int32_t userId, ObserverMap &observerMap);
|
||||
inline bool IsCallerUidValid();
|
||||
bool HasLocalDataType(const std::string &mimeType);
|
||||
@ -324,7 +321,7 @@ private:
|
||||
DistributedModuleConfig moduleConfig_;
|
||||
std::vector<std::string> bundles_;
|
||||
int32_t uid_ = -1;
|
||||
RemoteDataTaskManager taskMgr_;
|
||||
RemoteDataTaskManager taskMgr_;
|
||||
pid_t setPasteDataUId_ = 0;
|
||||
static constexpr const pid_t TESE_SERVER_UID = 3500;
|
||||
std::mutex eventMutex_;
|
||||
|
@ -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);
|
||||
|
@ -13,28 +13,28 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "pasteboard_pattern.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <libxml/HTMLparser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "pasteboard_pattern.h"
|
||||
|
||||
namespace OHOS::MiscServices {
|
||||
std::map<uint32_t, std::string> PatternDetection::patterns_{
|
||||
{ static_cast<uint32_t>(Pattern::URL), std::string("[a-zA-Z0-9+.-]+://[-a-zA-Z0-9+&@#/%?"
|
||||
"=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_]")},
|
||||
{ static_cast<uint32_t>(Pattern::Number), std::string("[-+]?[0-9]*\\.?[0-9]+")},
|
||||
"=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_]") },
|
||||
{ static_cast<uint32_t>(Pattern::Number), std::string("[-+]?[0-9]*\\.?[0-9]+") },
|
||||
{ static_cast<uint32_t>(Pattern::EmailAddress), std::string("(([a-zA-Z0-9_\\-\\.]+)@"
|
||||
"((?:\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\])|"
|
||||
"([a-zA-Z0-9\\-]+(?:\\.[a-zA-Z0-9\\-]+)*))"
|
||||
"([a-zA-Z]{2,}|[0-9]{1,3}))")},
|
||||
"((?:\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\])|"
|
||||
"([a-zA-Z0-9\\-]+(?:\\.[a-zA-Z0-9\\-]+)*))"
|
||||
"([a-zA-Z]{2,}|[0-9]{1,3}))") },
|
||||
};
|
||||
|
||||
const std::set<Pattern> PatternDetection::Detect(const std::set<Pattern> &patternsToCheck,
|
||||
const PasteData &pasteData, bool hasHTML, bool hasPlain)
|
||||
const std::set<Pattern> PatternDetection::Detect(
|
||||
const std::set<Pattern> &patternsToCheck, const PasteData &pasteData, bool hasHTML, bool hasPlain)
|
||||
{
|
||||
std::set<Pattern> existedPatterns;
|
||||
for (auto& record : pasteData.AllRecords()) {
|
||||
for (auto &record : pasteData.AllRecords()) {
|
||||
if (patternsToCheck == existedPatterns) {
|
||||
break;
|
||||
}
|
||||
@ -60,8 +60,8 @@ bool PatternDetection::IsValid(const std::set<Pattern> &patterns)
|
||||
return true;
|
||||
}
|
||||
|
||||
void PatternDetection::DetectPlainText(std::set<Pattern> &patternsOut,
|
||||
const std::set<Pattern> &patternsIn, const std::string &plainText)
|
||||
void PatternDetection::DetectPlainText(
|
||||
std::set<Pattern> &patternsOut, const std::set<Pattern> &patternsIn, const std::string &plainText)
|
||||
{
|
||||
for (Pattern pattern : patternsIn) {
|
||||
if (patternsOut.find(pattern) != patternsOut.end()) {
|
||||
@ -99,7 +99,7 @@ std::string PatternDetection::ExtractHtmlContent(const std::string &html_str)
|
||||
xmlFreeDoc(doc);
|
||||
return "";
|
||||
}
|
||||
std::string result(reinterpret_cast<const char*>(xmlStr));
|
||||
std::string result(reinterpret_cast<const char *>(xmlStr));
|
||||
xmlFree(xmlStr);
|
||||
xmlFreeDoc(doc);
|
||||
return result;
|
||||
|
@ -12,13 +12,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "pasteboard_service.h"
|
||||
|
||||
#include <bitset>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "tokenid_kit.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "account_manager.h"
|
||||
#include "calculate_time_consuming.h"
|
||||
@ -28,22 +25,23 @@
|
||||
#include "dfx_code_constant.h"
|
||||
#include "dfx_types.h"
|
||||
#include "distributed_file_daemon_manager.h"
|
||||
#include "eventcenter/pasteboard_event.h"
|
||||
#include "eventcenter/event_center.h"
|
||||
#include "eventcenter/pasteboard_event.h"
|
||||
#include "hiview_adapter.h"
|
||||
#include "int_wrapper.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "loader.h"
|
||||
#include "long_wrapper.h"
|
||||
#include "mem_mgr_client.h"
|
||||
#include "mem_mgr_proxy.h"
|
||||
#include "int_wrapper.h"
|
||||
#include "long_wrapper.h"
|
||||
#include "native_token_info.h"
|
||||
#include "os_account_manager.h"
|
||||
#include "parameters.h"
|
||||
#include "pasteboard_dialog.h"
|
||||
#include "pasteboard_error.h"
|
||||
#include "pasteboard_event_dfx.h"
|
||||
#include "pasteboard_event_ue.h"
|
||||
#include "pasteboard_error.h"
|
||||
#include "pasteboard_service.h"
|
||||
#include "pasteboard_trace.h"
|
||||
#include "remote_file_share.h"
|
||||
#include "reporter.h"
|
||||
@ -72,11 +70,11 @@ constexpr const int GET_WRONG_SIZE = 0;
|
||||
constexpr const size_t MAX_URI_COUNT = 500;
|
||||
constexpr const int32_t COMMON_USERID = 0;
|
||||
const std::int32_t INIT_INTERVAL = 10000L;
|
||||
constexpr const char* PASTEBOARD_SERVICE_NAME = "PasteboardService";
|
||||
constexpr const char* FAIL_TO_GET_TIME_STAMP = "FAIL_TO_GET_TIME_STAMP";
|
||||
constexpr const char* SECURE_PASTE_PERMISSION = "ohos.permission.SECURE_PASTE";
|
||||
constexpr const char* READ_PASTEBOARD_PERMISSION = "ohos.permission.READ_PASTEBOARD";
|
||||
constexpr const char* TRANSMIT_CONTROL_PROP_KEY = "persist.distributed_scene.datafiles_trans_ctrl";
|
||||
constexpr const char *PASTEBOARD_SERVICE_NAME = "PasteboardService";
|
||||
constexpr const char *FAIL_TO_GET_TIME_STAMP = "FAIL_TO_GET_TIME_STAMP";
|
||||
constexpr const char *SECURE_PASTE_PERMISSION = "ohos.permission.SECURE_PASTE";
|
||||
constexpr const char *READ_PASTEBOARD_PERMISSION = "ohos.permission.READ_PASTEBOARD";
|
||||
constexpr const char *TRANSMIT_CONTROL_PROP_KEY = "persist.distributed_scene.datafiles_trans_ctrl";
|
||||
|
||||
const std::int32_t INVAILD_VERSION = -1;
|
||||
const std::int32_t ADD_PERMISSION_CHECK_SDK_VERSION = 12;
|
||||
@ -127,8 +125,7 @@ void PasteboardService::InitScreenStatus()
|
||||
#ifdef PB_SCREENLOCK_MGR_ENABLE
|
||||
auto isScreenLocked = OHOS::ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked();
|
||||
PasteboardService::currentScreenStatus = isScreenLocked ? ScreenEvent::ScreenLocked : ScreenEvent::ScreenUnlocked;
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "screen status is %{public}d",
|
||||
PasteboardService::currentScreenStatus);
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "screen status is %{public}d", PasteboardService::currentScreenStatus);
|
||||
#else
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "PB_SCREENLOCK_MGR_ENABLE not defined");
|
||||
return;
|
||||
@ -155,7 +152,9 @@ void PasteboardService::OnStart()
|
||||
moduleConfig_.Watch(std::bind(&PasteboardService::OnConfigChange, this, std::placeholders::_1));
|
||||
AddSysAbilityListener();
|
||||
if (Init() != ERR_OK) {
|
||||
auto callback = [this]() { Init(); };
|
||||
auto callback = [this]() {
|
||||
Init();
|
||||
};
|
||||
serviceHandler_->PostTask(callback, INIT_INTERVAL);
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "Init failed. Try again 10s later.");
|
||||
return;
|
||||
@ -234,10 +233,10 @@ PasteboardService::DelayGetterDeathRecipient::DelayGetterDeathRecipient(int32_t
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "Construct Delay Getter Death Recipient");
|
||||
}
|
||||
|
||||
void PasteboardService::DelayGetterDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
void PasteboardService::DelayGetterDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "start");
|
||||
(void) remote;
|
||||
(void)remote;
|
||||
service_.NotifyDelayGetterDied(userId_);
|
||||
}
|
||||
|
||||
@ -255,10 +254,10 @@ PasteboardService::EntryGetterDeathRecipient::EntryGetterDeathRecipient(int32_t
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "Construct Entry Getter Death Recipient");
|
||||
}
|
||||
|
||||
void PasteboardService::EntryGetterDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
void PasteboardService::EntryGetterDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "start");
|
||||
(void) remote;
|
||||
(void)remote;
|
||||
service_.NotifyEntryGetterDied(userId_);
|
||||
}
|
||||
|
||||
@ -322,7 +321,7 @@ void PasteboardService::Clear()
|
||||
CleanDistributedData(userId);
|
||||
}
|
||||
|
||||
int32_t PasteboardService::GetRecordValueByType(uint32_t dataId, uint32_t recordId, PasteDataEntry& value)
|
||||
int32_t PasteboardService::GetRecordValueByType(uint32_t dataId, uint32_t recordId, PasteDataEntry &value)
|
||||
{
|
||||
auto tokenId = IPCSkeleton::GetCallingTokenID();
|
||||
auto callPid = IPCSkeleton::GetCallingPid();
|
||||
@ -341,8 +340,8 @@ int32_t PasteboardService::GetRecordValueByType(uint32_t dataId, uint32_t record
|
||||
auto data = clip.second;
|
||||
if (dataId != data->GetDataId()) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE,
|
||||
"get record value fail, data is out time, pre dataId is %{public}d, cur dataId is %{public}d",
|
||||
dataId, data->GetDataId());
|
||||
"get record value fail, data is out time, pre dataId is %{public}d, cur dataId is %{public}d", dataId,
|
||||
data->GetDataId());
|
||||
return static_cast<int32_t>(PasteboardError::TIMEOUT_ERROR);
|
||||
}
|
||||
auto getter = entryGetter.second;
|
||||
@ -360,8 +359,8 @@ int32_t PasteboardService::GetRecordValueByType(uint32_t dataId, uint32_t record
|
||||
clips_.ComputeIfPresent(appInfo.userId, [dataId, recordId, value](auto, auto &data) {
|
||||
if (dataId != data->GetDataId()) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE,
|
||||
"set record value fail, data is out time, pre dataId is %{public}d, cur dataId is %{public}d",
|
||||
dataId, data->GetDataId());
|
||||
"set record value fail, data is out time, pre dataId is %{public}d, cur dataId is %{public}d", dataId,
|
||||
data->GetDataId());
|
||||
return true;
|
||||
}
|
||||
auto record = data->GetRecordAt(recordId - 1);
|
||||
@ -449,8 +448,8 @@ int32_t PasteboardService::IsDataVaild(PasteData &pasteData, uint32_t tokenId)
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE,
|
||||
"tokenId = 0x%{public}x, shareOption = %{public}d is error.", tokenId, pasteData.GetShareOption());
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "tokenId = 0x%{public}x, shareOption = %{public}d is error.",
|
||||
tokenId, pasteData.GetShareOption());
|
||||
return static_cast<int32_t>(PasteboardError::INVALID_DATA_ERROR);
|
||||
}
|
||||
}
|
||||
@ -474,7 +473,7 @@ int32_t PasteboardService::GetSdkVersion(uint32_t tokenId)
|
||||
return hapTokenInfo.apiVersion;
|
||||
}
|
||||
|
||||
bool PasteboardService::IsPermissionGranted(const std::string& perm, uint32_t tokenId)
|
||||
bool PasteboardService::IsPermissionGranted(const std::string &perm, uint32_t tokenId)
|
||||
{
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "check grant permission, perm=%{public}s", perm.c_str());
|
||||
int32_t result = AccessTokenKit::VerifyAccessToken(tokenId, perm);
|
||||
@ -600,8 +599,8 @@ void PasteboardService::AddPermissionRecord(uint32_t tokenId, bool isReadGrant,
|
||||
if (!isGrant) {
|
||||
return;
|
||||
}
|
||||
auto permUsedType = static_cast<PermissionUsedType>(AccessTokenKit::GetPermissionUsedType(tokenId,
|
||||
isSecureGrant ? SECURE_PASTE_PERMISSION : READ_PASTEBOARD_PERMISSION));
|
||||
auto permUsedType = static_cast<PermissionUsedType>(AccessTokenKit::GetPermissionUsedType(
|
||||
tokenId, isSecureGrant ? SECURE_PASTE_PERMISSION : READ_PASTEBOARD_PERMISSION));
|
||||
AddPermParamInfo info;
|
||||
info.tokenId = tokenId;
|
||||
info.permissionName = READ_PASTEBOARD_PERMISSION;
|
||||
@ -640,7 +639,7 @@ int32_t PasteboardService::GetData(uint32_t tokenId, PasteData &data, int32_t &s
|
||||
return result;
|
||||
}
|
||||
int64_t fileSize = GetFileSize(data);
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "fileSize=%{public}" PRId64", isremote=%{public}d", fileSize,
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "fileSize=%{public}" PRId64 ", isremote=%{public}d", fileSize,
|
||||
static_cast<int>(data.IsRemote()));
|
||||
if (data.IsRemote() && fileSize > 0) {
|
||||
data.SetPasteId(pasteId);
|
||||
@ -664,8 +663,8 @@ int64_t PasteboardService::GetFileSize(PasteData &data)
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
PasteboardService::RemoteDataTaskManager::DataTask PasteboardService::RemoteDataTaskManager::GetRemoteDataTask(const
|
||||
Event &event)
|
||||
PasteboardService::RemoteDataTaskManager::DataTask PasteboardService::RemoteDataTaskManager::GetRemoteDataTask(
|
||||
const Event &event)
|
||||
{
|
||||
auto key = event.deviceId + std::to_string(event.seqId);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@ -689,9 +688,9 @@ void PasteboardService::RemoteDataTaskManager::Notify(const Event &event, std::s
|
||||
if (it == dataTasks_.end()) {
|
||||
return;
|
||||
}
|
||||
auto& task = it->second;
|
||||
auto &task = it->second;
|
||||
task->data_ = data;
|
||||
task->getDataBlocks_.ForEach([](const auto& key, auto value) -> bool {
|
||||
task->getDataBlocks_.ForEach([](const auto &key, auto value) -> bool {
|
||||
value->SetValue(true);
|
||||
return false;
|
||||
});
|
||||
@ -752,8 +751,8 @@ int32_t PasteboardService::GetRemoteData(int32_t userId, const Event &event, Pas
|
||||
data = *it.second;
|
||||
}
|
||||
taskMgr_.ClearRemoteDataTask(event);
|
||||
int32_t res = it.first ? static_cast<int32_t>(PasteboardError::E_OK) :
|
||||
static_cast<int32_t>(PasteboardError::INVALID_EVENT_ERROR);
|
||||
int32_t res = it.first ? static_cast<int32_t>(PasteboardError::E_OK)
|
||||
: static_cast<int32_t>(PasteboardError::INVALID_EVENT_ERROR);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -771,8 +770,8 @@ int32_t PasteboardService::GetRemotePasteData(int32_t userId, const Event &event
|
||||
result.first->SetRemote(true);
|
||||
if (validEvent.second == event) {
|
||||
clips_.InsertOrAssign(userId, result.first);
|
||||
auto curTime = static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch())
|
||||
.count());
|
||||
auto curTime =
|
||||
static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
|
||||
copyTime_.InsertOrAssign(userId, curTime);
|
||||
}
|
||||
pasteDataTime->syncTime = result.second.syncTime;
|
||||
@ -898,8 +897,8 @@ bool PasteboardService::GetDelayPasteRecord(const AppInfo &appInfo, PasteData &d
|
||||
auto result = getter.first->GetRecordValueByType(record->GetRecordId(), *entries[0]);
|
||||
if (result != static_cast<int32_t>(PasteboardError::E_OK)) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE,
|
||||
"get record value fail, dataId is %{public}d, recordId is %{public}d",
|
||||
data.GetDataId(), record->GetRecordId());
|
||||
"get record value fail, dataId is %{public}d, recordId is %{public}d", data.GetDataId(),
|
||||
record->GetRecordId());
|
||||
continue;
|
||||
}
|
||||
record->AddEntry(entries[0]->GetUtdId(), entries[0]);
|
||||
@ -912,8 +911,8 @@ void PasteboardService::EstablishP2PLink(const std::string &networkId, const std
|
||||
{
|
||||
#ifdef PB_DEVICE_MANAGER_ENABLE
|
||||
auto callPid = IPCSkeleton::GetCallingPid();
|
||||
p2pMap_.Compute(networkId, [pasteId, callPid] (const auto& key, auto& value) {
|
||||
value.Compute(pasteId, [callPid] (const auto& key, auto& value) {
|
||||
p2pMap_.Compute(networkId, [pasteId, callPid](const auto &key, auto &value) {
|
||||
value.Compute(pasteId, [callPid](const auto &key, auto &value) {
|
||||
value = callPid;
|
||||
return true;
|
||||
});
|
||||
@ -988,12 +987,12 @@ void PasteboardService::PasteComplete(const std::string &deviceId, const std::st
|
||||
if (deviceId.empty()) {
|
||||
return;
|
||||
}
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "deviceId is %{public}.6s, taskId is %{public}s",
|
||||
deviceId.c_str(), pasteId.c_str());
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "deviceId is %{public}.6s, taskId is %{public}s", deviceId.c_str(),
|
||||
pasteId.c_str());
|
||||
RADAR_REPORT(RadarReporter::DFX_GET_PASTEBOARD, RadarReporter::DFX_DISTRIBUTED_FILE_END, RadarReporter::DFX_SUCCESS,
|
||||
RadarReporter::BIZ_STATE, RadarReporter::DFX_END, RadarReporter::CONCURRENT_ID, pasteId);
|
||||
p2pMap_.ComputeIfPresent(deviceId, [pasteId, deviceId, this] (const auto& key, auto& value) {
|
||||
value.ComputeIfPresent(pasteId, [deviceId] (const auto& key, auto& value) {
|
||||
p2pMap_.ComputeIfPresent(deviceId, [pasteId, deviceId, this](const auto &key, auto &value) {
|
||||
value.ComputeIfPresent(pasteId, [deviceId](const auto &key, auto &value) {
|
||||
return false;
|
||||
});
|
||||
if (value.Empty()) {
|
||||
@ -1023,8 +1022,8 @@ int32_t PasteboardService::GrantUriPermission(PasteData &data, const std::string
|
||||
count = length - offset;
|
||||
}
|
||||
auto sendValues = std::vector<Uri>(grantUris.begin() + offset, grantUris.begin() + offset + count);
|
||||
auto permissionCode = AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermissionPrivileged(sendValues,
|
||||
AAFwk::Want::FLAG_AUTH_READ_URI_PERMISSION, targetBundleName);
|
||||
auto permissionCode = AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermissionPrivileged(
|
||||
sendValues, AAFwk::Want::FLAG_AUTH_READ_URI_PERMISSION, targetBundleName);
|
||||
if (permissionCode == 0) {
|
||||
std::lock_guard<std::mutex> lock(bundleMutex_);
|
||||
if (readBundles_.count(targetBundleName) == 0) {
|
||||
@ -1035,12 +1034,12 @@ int32_t PasteboardService::GrantUriPermission(PasteData &data, const std::string
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "permissionCode is %{public}d", permissionCode);
|
||||
offset += count;
|
||||
}
|
||||
return grantSuccess ? static_cast<int32_t>(PasteboardError::E_OK) :
|
||||
static_cast<int32_t>(PasteboardError::URI_GRANT_ERROR);
|
||||
return grantSuccess ? static_cast<int32_t>(PasteboardError::E_OK)
|
||||
: static_cast<int32_t>(PasteboardError::URI_GRANT_ERROR);
|
||||
}
|
||||
|
||||
void PasteboardService::CheckUriPermission(PasteData &data, std::vector<Uri> &grantUris,
|
||||
const std::string &targetBundleName)
|
||||
void PasteboardService::CheckUriPermission(
|
||||
PasteData &data, std::vector<Uri> &grantUris, const std::string &targetBundleName)
|
||||
{
|
||||
for (size_t i = 0; i < data.GetRecordCount(); i++) {
|
||||
auto item = data.GetRecordAt(i);
|
||||
@ -1079,8 +1078,8 @@ void PasteboardService::RevokeUriPermission(std::shared_ptr<PasteData> pasteData
|
||||
if (pasteData == nullptr || bundles.empty()) {
|
||||
return;
|
||||
}
|
||||
std::thread thread([pasteData, bundles] () {
|
||||
auto& permissionClient = AAFwk::UriPermissionManagerClient::GetInstance();
|
||||
std::thread thread([pasteData, bundles]() {
|
||||
auto &permissionClient = AAFwk::UriPermissionManagerClient::GetInstance();
|
||||
for (size_t i = 0; i < pasteData->GetRecordCount(); i++) {
|
||||
auto item = pasteData->GetRecordAt(i);
|
||||
if (item == nullptr || item->GetOrginUri() == nullptr) {
|
||||
@ -1133,8 +1132,8 @@ void PasteboardService::CheckAppUriPermission(PasteData &data)
|
||||
count = length - offset;
|
||||
}
|
||||
auto sendValues = std::vector<std::string>(uris.begin() + offset, uris.begin() + offset + count);
|
||||
std::vector<bool> ret = AAFwk::UriPermissionManagerClient::GetInstance().CheckUriAuthorization(sendValues,
|
||||
AAFwk::Want::FLAG_AUTH_READ_URI_PERMISSION, data.GetTokenId());
|
||||
std::vector<bool> ret = AAFwk::UriPermissionManagerClient::GetInstance().CheckUriAuthorization(
|
||||
sendValues, AAFwk::Want::FLAG_AUTH_READ_URI_PERMISSION, data.GetTokenId());
|
||||
checkResults.insert(checkResults.end(), ret.begin(), ret.end());
|
||||
offset += count;
|
||||
}
|
||||
@ -1175,8 +1174,10 @@ bool PasteboardService::HasPasteData()
|
||||
auto tokenId = IPCSkeleton::GetCallingTokenID();
|
||||
auto ret = IsDataVaild(*(it.second), tokenId);
|
||||
if (ret != static_cast<int32_t>(PasteboardError::E_OK)) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "pasteData is invalid, tokenId: %{public}d, userId: %{public}d,"
|
||||
"ret is %{public}d", tokenId, userId, ret);
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE,
|
||||
"pasteData is invalid, tokenId: %{public}d, userId: %{public}d,"
|
||||
"ret is %{public}d",
|
||||
tokenId, userId, ret);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -1189,8 +1190,8 @@ int32_t PasteboardService::SetPasteData(PasteData &pasteData, const sptr<IPasteb
|
||||
return SavePasteData(data, delayGetter, entryGetter);
|
||||
}
|
||||
|
||||
int32_t PasteboardService::SaveData(std::shared_ptr<PasteData> &pasteData,
|
||||
sptr<IPasteboardDelayGetter> delayGetter, sptr<IPasteboardEntryGetter> entryGetter)
|
||||
int32_t PasteboardService::SaveData(std::shared_ptr<PasteData> &pasteData, sptr<IPasteboardDelayGetter> delayGetter,
|
||||
sptr<IPasteboardEntryGetter> entryGetter)
|
||||
{
|
||||
PasteboardTrace tracer("PasteboardService, SetPasteData");
|
||||
auto tokenId = IPCSkeleton::GetCallingTokenID();
|
||||
@ -1226,8 +1227,8 @@ int32_t PasteboardService::SaveData(std::shared_ptr<PasteData> &pasteData,
|
||||
SetWebViewPasteData(*pasteData, appInfo.bundleName);
|
||||
CheckAppUriPermission(*pasteData);
|
||||
clips_.InsertOrAssign(appInfo.userId, pasteData);
|
||||
RADAR_REPORT(DFX_SET_PASTEBOARD, DFX_CHECK_SET_DELAY_COPY, static_cast<int>(pasteData->IsDelayData()), SET_DATA_APP,
|
||||
appInfo.bundleName, LOCAL_DEV_TYPE, DMAdapter::GetInstance().GetLocalDeviceType());
|
||||
RADAR_REPORT(DFX_SET_PASTEBOARD, DFX_CHECK_SET_DELAY_COPY, static_cast<int>(pasteData->IsDelayData()),
|
||||
SET_DATA_APP, appInfo.bundleName, LOCAL_DEV_TYPE, DMAdapter::GetInstance().GetLocalDeviceType());
|
||||
HandleDelayDataAndRecord(pasteData, delayGetter, entryGetter, appInfo);
|
||||
auto curTime = static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "curTime = %{public}" PRIu64, curTime);
|
||||
@ -1243,17 +1244,17 @@ int32_t PasteboardService::SaveData(std::shared_ptr<PasteData> &pasteData,
|
||||
}
|
||||
|
||||
void PasteboardService::HandleDelayDataAndRecord(std::shared_ptr<PasteData> &pasteData,
|
||||
sptr<IPasteboardDelayGetter> delayGetter, sptr<IPasteboardEntryGetter> entryGetter, const AppInfo& appInfo)
|
||||
sptr<IPasteboardDelayGetter> delayGetter, sptr<IPasteboardEntryGetter> entryGetter, const AppInfo &appInfo)
|
||||
{
|
||||
if (pasteData->IsDelayData()) {
|
||||
sptr<DelayGetterDeathRecipient> deathRecipient =
|
||||
new (std::nothrow) DelayGetterDeathRecipient(appInfo.userId, *this);
|
||||
sptr<DelayGetterDeathRecipient> deathRecipient = new (std::nothrow)
|
||||
DelayGetterDeathRecipient(appInfo.userId, *this);
|
||||
delayGetter->AsObject()->AddDeathRecipient(deathRecipient);
|
||||
delayGetters_.InsertOrAssign(appInfo.userId, std::make_pair(delayGetter, deathRecipient));
|
||||
}
|
||||
if (pasteData->IsDelayRecord()) {
|
||||
sptr<EntryGetterDeathRecipient> deathRecipient =
|
||||
new (std::nothrow) EntryGetterDeathRecipient(appInfo.userId, *this);
|
||||
sptr<EntryGetterDeathRecipient> deathRecipient = new (std::nothrow)
|
||||
EntryGetterDeathRecipient(appInfo.userId, *this);
|
||||
entryGetter->AsObject()->AddDeathRecipient(deathRecipient);
|
||||
entryGetters_.InsertOrAssign(appInfo.userId, std::make_pair(entryGetter, deathRecipient));
|
||||
}
|
||||
@ -1322,8 +1323,7 @@ std::pair<bool, ClipPlugin::GlobalEvent> PasteboardService::GetValidDistributeEv
|
||||
}
|
||||
|
||||
evt = events[0];
|
||||
if (evt.deviceId == DMAdapter::GetInstance().GetLocalNetworkId() ||
|
||||
evt.expiration < currentEvent_.expiration) {
|
||||
if (evt.deviceId == DMAdapter::GetInstance().GetLocalNetworkId() || evt.expiration < currentEvent_.expiration) {
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "get local data.");
|
||||
return std::make_pair(false, evt);
|
||||
}
|
||||
@ -1370,13 +1370,16 @@ bool PasteboardService::HasLocalDataType(const std::string &mimeType)
|
||||
auto tokenId = IPCSkeleton::GetCallingTokenID();
|
||||
auto ret = IsDataVaild(*(it.second), tokenId);
|
||||
if (ret != static_cast<int32_t>(PasteboardError::E_OK)) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "pasteData is invalid, tokenId is %{public}d, userId: %{public}d,"
|
||||
"mimeType: %{public}s, ret is %{public}d", tokenId, userId, mimeType.c_str(), ret);
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE,
|
||||
"pasteData is invalid, tokenId is %{public}d, userId: %{public}d,"
|
||||
"mimeType: %{public}s, ret is %{public}d",
|
||||
tokenId, userId, mimeType.c_str(), ret);
|
||||
return false;
|
||||
}
|
||||
auto screenStatus = GetCurrentScreenStatus();
|
||||
if (it.second->GetScreenStatus() > screenStatus) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "current screen is %{public}d, set data screen is %{public}d."
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE,
|
||||
"current screen is %{public}d, set data screen is %{public}d."
|
||||
"userId: %{public}d, mimeType: %{public}s",
|
||||
screenStatus, it.second->GetScreenStatus(), userId, mimeType.c_str());
|
||||
return false;
|
||||
@ -1398,7 +1401,7 @@ bool PasteboardService::IsRemoteData()
|
||||
}
|
||||
auto it = clips_.Find(userId);
|
||||
if (!it.first) {
|
||||
auto evt = GetValidDistributeEvent(userId);
|
||||
auto evt = GetValidDistributeEvent(userId);
|
||||
return evt.first;
|
||||
}
|
||||
return it.second->IsRemote();
|
||||
@ -1458,7 +1461,7 @@ void PasteboardService::SetWebViewPasteData(PasteData &pasteData, const std::str
|
||||
return;
|
||||
}
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteboardService for webview.");
|
||||
for (auto& item : pasteData.AllRecords()) {
|
||||
for (auto &item : pasteData.AllRecords()) {
|
||||
if (item->GetUri() == nullptr) {
|
||||
continue;
|
||||
}
|
||||
@ -1512,8 +1515,7 @@ bool PasteboardService::IsCopyable(uint32_t tokenId) const
|
||||
return true;
|
||||
}
|
||||
|
||||
void PasteboardService::SubscribeObserver(PasteboardObserverType type,
|
||||
const sptr<IPasteboardChangedObserver> &observer)
|
||||
void PasteboardService::SubscribeObserver(PasteboardObserverType type, const sptr<IPasteboardChangedObserver> &observer)
|
||||
{
|
||||
bool isEventType = static_cast<uint32_t>(type) & static_cast<uint32_t>(PasteboardObserverType::OBSERVER_EVENT);
|
||||
int32_t userId = isEventType ? COMMON_USERID : GetCurrentAccountId();
|
||||
@ -1534,8 +1536,8 @@ void PasteboardService::SubscribeObserver(PasteboardObserverType type,
|
||||
}
|
||||
}
|
||||
|
||||
void PasteboardService::UnsubscribeObserver(PasteboardObserverType type,
|
||||
const sptr<IPasteboardChangedObserver> &observer)
|
||||
void PasteboardService::UnsubscribeObserver(
|
||||
PasteboardObserverType type, const sptr<IPasteboardChangedObserver> &observer)
|
||||
{
|
||||
bool isEventType = static_cast<uint32_t>(type) & static_cast<uint32_t>(PasteboardObserverType::OBSERVER_EVENT);
|
||||
int32_t userId = isEventType ? COMMON_USERID : GetCurrentAccountId();
|
||||
@ -1577,8 +1579,8 @@ void PasteboardService::UnsubscribeAllObserver(PasteboardObserverType type)
|
||||
}
|
||||
}
|
||||
|
||||
void PasteboardService::AddObserver(int32_t userId, const sptr<IPasteboardChangedObserver> &observer,
|
||||
ObserverMap &observerMap)
|
||||
void PasteboardService::AddObserver(
|
||||
int32_t userId, const sptr<IPasteboardChangedObserver> &observer, ObserverMap &observerMap)
|
||||
{
|
||||
if (observer == nullptr) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "observer null.");
|
||||
@ -1595,12 +1597,12 @@ void PasteboardService::AddObserver(int32_t userId, const sptr<IPasteboardChange
|
||||
}
|
||||
observers->insert(observer);
|
||||
RADAR_REPORT(DFX_OBSERVER, DFX_ADD_OBSERVER, DFX_SUCCESS);
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "observers->size = %{public}u.",
|
||||
static_cast<unsigned int>(observers->size()));
|
||||
PASTEBOARD_HILOGI(
|
||||
PASTEBOARD_MODULE_SERVICE, "observers->size = %{public}u.", static_cast<unsigned int>(observers->size()));
|
||||
}
|
||||
|
||||
void PasteboardService::RemoveSingleObserver(int32_t userId, const sptr<IPasteboardChangedObserver> &observer,
|
||||
ObserverMap &observerMap)
|
||||
void PasteboardService::RemoveSingleObserver(
|
||||
int32_t userId, const sptr<IPasteboardChangedObserver> &observer, ObserverMap &observerMap)
|
||||
{
|
||||
if (observer == nullptr) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "observer null.");
|
||||
@ -1612,8 +1614,8 @@ void PasteboardService::RemoveSingleObserver(int32_t userId, const sptr<IPastebo
|
||||
return;
|
||||
}
|
||||
auto observers = it->second;
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "observers size: %{public}u.",
|
||||
static_cast<unsigned int>(observers->size()));
|
||||
PASTEBOARD_HILOGD(
|
||||
PASTEBOARD_MODULE_SERVICE, "observers size: %{public}u.", static_cast<unsigned int>(observers->size()));
|
||||
auto eraseNum = observers->erase(observer);
|
||||
RADAR_REPORT(DFX_OBSERVER, DFX_REMOVE_SINGLE_OBSERVER, DFX_SUCCESS);
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "observers size = %{public}u, eraseNum = %{public}zu",
|
||||
@ -1629,8 +1631,8 @@ void PasteboardService::RemoveAllObserver(int32_t userId, ObserverMap &observerM
|
||||
return;
|
||||
}
|
||||
auto observers = it->second;
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "observers size: %{public}u.",
|
||||
static_cast<unsigned int>(observers->size()));
|
||||
PASTEBOARD_HILOGD(
|
||||
PASTEBOARD_MODULE_SERVICE, "observers size: %{public}u.", static_cast<unsigned int>(observers->size()));
|
||||
auto eraseNum = observerMap.erase(userId);
|
||||
RADAR_REPORT(DFX_OBSERVER, DFX_REMOVE_ALL_OBSERVER, DFX_SUCCESS);
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "observers size = %{public}u, eraseNum = %{public}zu",
|
||||
@ -1643,7 +1645,7 @@ int32_t PasteboardService::SetGlobalShareOption(const std::map<uint32_t, ShareOp
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "No Permission");
|
||||
return static_cast<int32_t>(PasteboardError::PERMISSION_VERIFICATION_ERROR);
|
||||
}
|
||||
for (const auto &[tokenId, shareOption] : globalShareOptions) {
|
||||
for (const auto &[tokenId, shareOption] : globalShareOptions) {
|
||||
globalShareOptions_.InsertOrAssign(tokenId, shareOption);
|
||||
}
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "Set %{public}zu global shareOption.", globalShareOptions.size());
|
||||
@ -1694,8 +1696,8 @@ int32_t PasteboardService::SetAppShareOptions(const ShareOption &shareOptions)
|
||||
{
|
||||
auto fullTokenId = IPCSkeleton::GetCallingFullTokenID();
|
||||
if (!OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE,
|
||||
"No permission, full token id: 0x%{public}" PRIx64 "", fullTokenId);
|
||||
PASTEBOARD_HILOGE(
|
||||
PASTEBOARD_MODULE_SERVICE, "No permission, full token id: 0x%{public}" PRIx64 "", fullTokenId);
|
||||
return static_cast<int32_t>(PasteboardError::PERMISSION_VERIFICATION_ERROR);
|
||||
}
|
||||
auto tokenId = IPCSkeleton::GetCallingTokenID();
|
||||
@ -1706,8 +1708,8 @@ int32_t PasteboardService::SetAppShareOptions(const ShareOption &shareOptions)
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "Settings already exist, token id: 0x%{public}x.", tokenId);
|
||||
return static_cast<int32_t>(PasteboardError::INVALID_OPERATION_ERROR);
|
||||
}
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE,
|
||||
"Set token id: 0x%{public}x share options: %{public}d success.", tokenId, shareOptions);
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "Set token id: 0x%{public}x share options: %{public}d success.",
|
||||
tokenId, shareOptions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1715,8 +1717,8 @@ int32_t PasteboardService::RemoveAppShareOptions()
|
||||
{
|
||||
auto fullTokenId = IPCSkeleton::GetCallingFullTokenID();
|
||||
if (!OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE,
|
||||
"No permission, full token id: 0x%{public}" PRIx64 "", fullTokenId);
|
||||
PASTEBOARD_HILOGE(
|
||||
PASTEBOARD_MODULE_SERVICE, "No permission, full token id: 0x%{public}" PRIx64 "", fullTokenId);
|
||||
return static_cast<int32_t>(PasteboardError::PERMISSION_VERIFICATION_ERROR);
|
||||
}
|
||||
auto tokenId = IPCSkeleton::GetCallingTokenID();
|
||||
@ -1727,8 +1729,8 @@ int32_t PasteboardService::RemoveAppShareOptions()
|
||||
|
||||
void PasteboardService::UpdateShareOption(PasteData &pasteData)
|
||||
{
|
||||
globalShareOptions_.ComputeIfPresent(pasteData.GetTokenId(),
|
||||
[&pasteData](const uint32_t &tokenId, ShareOption &shareOption) {
|
||||
globalShareOptions_.ComputeIfPresent(
|
||||
pasteData.GetTokenId(), [&pasteData](const uint32_t &tokenId, ShareOption &shareOption) {
|
||||
pasteData.SetShareOption(shareOption);
|
||||
return true;
|
||||
});
|
||||
@ -1746,7 +1748,7 @@ inline bool PasteboardService::IsCallerUidValid()
|
||||
|
||||
void PasteboardService::NotifyObservers(std::string bundleName, PasteboardEventStatus status)
|
||||
{
|
||||
std::thread thread([this, bundleName, status] () {
|
||||
std::thread thread([this, bundleName, status]() {
|
||||
std::lock_guard<std::mutex> lock(observerMutex_);
|
||||
for (auto &observers : observerLocalChangedMap_) {
|
||||
for (const auto &observer : *(observers.second)) {
|
||||
@ -1779,7 +1781,7 @@ size_t PasteboardService::GetDataSize(PasteData &data) const
|
||||
bool PasteboardService::SetPasteboardHistory(HistoryInfo &info)
|
||||
{
|
||||
std::string history = std::move(info.time) + " " + std::move(info.bundleName) + " " + std::move(info.state) + " " +
|
||||
" " + std::move(info.remote);
|
||||
" " + std::move(info.remote);
|
||||
constexpr const size_t DATA_HISTORY_SIZE = 10;
|
||||
std::lock_guard<decltype(historyMutex_)> lg(historyMutex_);
|
||||
if (dataHistory_.size() == DATA_HISTORY_SIZE) {
|
||||
@ -1949,13 +1951,13 @@ void PasteboardService::GetPasteDataDot(PasteData &pasteData, const std::string
|
||||
};
|
||||
|
||||
Reporter::GetInstance().PasteboardBehaviour().Report({ bState, bundleName });
|
||||
|
||||
|
||||
size_t dataSize = GetDataSize(pasteData);
|
||||
CalculateTimeConsuming timeC(dataSize, pState);
|
||||
}
|
||||
|
||||
std::pair<std::shared_ptr<PasteData>, PasteDateResult> PasteboardService::GetDistributedData(const Event &event,
|
||||
int32_t user)
|
||||
std::pair<std::shared_ptr<PasteData>, PasteDateResult> PasteboardService::GetDistributedData(
|
||||
const Event &event, int32_t user)
|
||||
{
|
||||
auto clipPlugin = GetClipPlugin();
|
||||
PasteDateResult pasteDateResult;
|
||||
@ -1994,8 +1996,8 @@ std::pair<std::shared_ptr<PasteData>, PasteDateResult> PasteboardService::GetDis
|
||||
|
||||
bool PasteboardService::IsAllowSendData()
|
||||
{
|
||||
auto contralType = system::GetIntParameter(TRANSMIT_CONTROL_PROP_KEY, CONTROL_TYPE_ALLOW_SEND_RECEIVE, INT_MIN,
|
||||
INT_MAX);
|
||||
auto contralType =
|
||||
system::GetIntParameter(TRANSMIT_CONTROL_PROP_KEY, CONTROL_TYPE_ALLOW_SEND_RECEIVE, INT_MIN, INT_MAX);
|
||||
if (contralType != CONTROL_TYPE_ALLOW_SEND_RECEIVE) {
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "control type is: %{public}d.", contralType);
|
||||
return false;
|
||||
@ -2036,8 +2038,8 @@ bool PasteboardService::SetDistributedData(int32_t user, PasteData &data)
|
||||
return false;
|
||||
}
|
||||
if (data.GetShareOption() == InApp) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "data share option is in app, dataId:%{public}d",
|
||||
data.GetDataId());
|
||||
PASTEBOARD_HILOGE(
|
||||
PASTEBOARD_MODULE_SERVICE, "data share option is in app, dataId:%{public}d", data.GetDataId());
|
||||
return false;
|
||||
}
|
||||
auto networkId = DMAdapter::GetInstance().GetLocalNetworkId();
|
||||
@ -2155,8 +2157,10 @@ void PasteboardService::GenerateDistributedUri(PasteData &data)
|
||||
if (!uris.empty()) {
|
||||
int ret = RemoteFileShare::GetDfsUrisFromLocal(uris, userId, dfsUris);
|
||||
if (ret != 0 || dfsUris.empty()) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "Get remoteUri failed, ret = %{public}d, userId: %{public}d,"
|
||||
"uri size:%{public}zu.", ret, userId, uris.size());
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE,
|
||||
"Get remoteUri failed, ret = %{public}d, userId: %{public}d,"
|
||||
"uri size:%{public}zu.",
|
||||
ret, userId, uris.size());
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < indexs.size(); i++) {
|
||||
@ -2296,31 +2300,29 @@ bool PasteboardService::SubscribeKeyboardEvent()
|
||||
return true;
|
||||
}
|
||||
inputEventCallback_ = std::make_shared<InputEventCallback>();
|
||||
int32_t monitorId =
|
||||
MMI::InputManager::GetInstance()->AddMonitor(std::static_pointer_cast<MMI::IInputEventConsumer>(
|
||||
inputEventCallback_));
|
||||
int32_t monitorId = MMI::InputManager::GetInstance()->AddMonitor(
|
||||
std::static_pointer_cast<MMI::IInputEventConsumer>(inputEventCallback_));
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "add monitor ret is: %{public}d", monitorId);
|
||||
return monitorId >= 0;
|
||||
}
|
||||
|
||||
void PasteboardService::PasteboardEventSubscriber()
|
||||
{
|
||||
EventCenter::GetInstance().Subscribe(PasteboardEvent::DISCONNECT,
|
||||
[this](const OHOS::MiscServices::Event& event) {
|
||||
auto &evt = static_cast<const PasteboardEvent &>(event);
|
||||
auto networkId = evt.GetNetworkId();
|
||||
if (networkId.empty()) {
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "networkId is empty.");
|
||||
return;
|
||||
EventCenter::GetInstance().Subscribe(PasteboardEvent::DISCONNECT, [this](const OHOS::MiscServices::Event &event) {
|
||||
auto &evt = static_cast<const PasteboardEvent &>(event);
|
||||
auto networkId = evt.GetNetworkId();
|
||||
if (networkId.empty()) {
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "networkId is empty.");
|
||||
return;
|
||||
}
|
||||
p2pMap_.EraseIf([networkId, this](auto &key, auto &value) {
|
||||
if (key == networkId) {
|
||||
CloseP2PLink(networkId);
|
||||
return true;
|
||||
}
|
||||
p2pMap_.EraseIf([networkId, this](auto &key, auto &value) {
|
||||
if (key == networkId) {
|
||||
CloseP2PLink(networkId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void PasteboardService::CommonEventSubscriber()
|
||||
@ -2355,7 +2357,7 @@ int32_t PasteboardService::AppExit(pid_t pid)
|
||||
}
|
||||
return false;
|
||||
});
|
||||
for (const auto& id: networkIds) {
|
||||
for (const auto &id : networkIds) {
|
||||
CloseP2PLink(id);
|
||||
}
|
||||
clients_.Erase(pid);
|
||||
@ -2364,12 +2366,12 @@ int32_t PasteboardService::AppExit(pid_t pid)
|
||||
|
||||
void PasteboardService::PasteboardDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
(void) remote;
|
||||
(void)remote;
|
||||
service_.AppExit(pid_);
|
||||
}
|
||||
|
||||
PasteboardService::PasteboardDeathRecipient::PasteboardDeathRecipient(PasteboardService &service,
|
||||
sptr<IRemoteObject> observer, pid_t pid)
|
||||
PasteboardService::PasteboardDeathRecipient::PasteboardDeathRecipient(
|
||||
PasteboardService &service, sptr<IRemoteObject> observer, pid_t pid)
|
||||
: service_(service), observer_(observer), pid_(pid)
|
||||
{
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "Construct Pasteboard Client Death Recipient, pid: %{public}d", pid);
|
||||
@ -2378,8 +2380,7 @@ PasteboardService::PasteboardDeathRecipient::PasteboardDeathRecipient(Pasteboard
|
||||
int32_t PasteboardService::RegisterClientDeathObserver(sptr<IRemoteObject> observer)
|
||||
{
|
||||
pid_t pid = IPCSkeleton::GetCallingPid();
|
||||
sptr<PasteboardDeathRecipient> deathRecipient =
|
||||
new (std::nothrow) PasteboardDeathRecipient(*this, observer, pid);
|
||||
sptr<PasteboardDeathRecipient> deathRecipient = new (std::nothrow) PasteboardDeathRecipient(*this, observer, pid);
|
||||
observer->AddDeathRecipient(deathRecipient);
|
||||
clients_.InsertOrAssign(pid, std::move(deathRecipient));
|
||||
return ERR_OK;
|
||||
@ -2405,25 +2406,21 @@ void InputEventCallback::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) c
|
||||
return;
|
||||
}
|
||||
if (((keyItems[0].GetKeyCode() == MMI::KeyEvent::KEYCODE_CTRL_LEFT) ||
|
||||
(keyItems[0].GetKeyCode() == MMI::KeyEvent::KEYCODE_CTRL_RIGHT)) &&
|
||||
(keyItems[0].GetKeyCode() == MMI::KeyEvent::KEYCODE_CTRL_RIGHT)) &&
|
||||
keyItems[1].GetKeyCode() == MMI::KeyEvent::KEYCODE_V) {
|
||||
int32_t windowId = keyEvent->GetTargetWindowId();
|
||||
std::unique_lock<std::shared_mutex> lock(inputEventMutex_);
|
||||
windowPid_ = MMI::InputManager::GetInstance()->GetWindowPid(windowId);
|
||||
actionTime_ = static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch())
|
||||
.count());
|
||||
actionTime_ =
|
||||
static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
|
||||
}
|
||||
}
|
||||
|
||||
void InputEventCallback::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
|
||||
{
|
||||
}
|
||||
void InputEventCallback::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const {}
|
||||
|
||||
void InputEventCallback::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const
|
||||
{
|
||||
}
|
||||
void InputEventCallback::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const {}
|
||||
|
||||
bool InputEventCallback::IsCtrlVProcess(uint32_t callingPid, bool isFocused)
|
||||
bool InputEventCallback::IsCtrlVProcess(uint32_t callingPid, bool isFocused)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(inputEventMutex_);
|
||||
auto curTime = static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user