mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2024-11-27 01:30:57 +00:00
!2008 add function for drag enable
Merge pull request !2008 from hongtao/master
This commit is contained in:
commit
c6f1bd6cc9
@ -33,6 +33,8 @@ public:
|
||||
static napi_value On(napi_env env, napi_callback_info info);
|
||||
static napi_value Off(napi_env env, napi_callback_info info);
|
||||
static napi_value GetDataSummary(napi_env env, napi_callback_info info);
|
||||
static napi_value SetDragSwitchState(napi_env env, napi_callback_info info);
|
||||
static napi_value SetAppDragSwitchState(napi_env env, napi_callback_info info);
|
||||
|
||||
private:
|
||||
static napi_value CreateInstance(napi_env env);
|
||||
|
@ -43,6 +43,8 @@ public:
|
||||
void RegisterListener(napi_env env, napi_value handle);
|
||||
void UnregisterListener(napi_env env, napi_value handle = nullptr);
|
||||
napi_value GetDataSummary(napi_env env);
|
||||
void SetDragSwitchState(napi_env env, bool enable);
|
||||
void SetAppDragSwitchState(napi_env env, bool enable, const std::string &pkgName);
|
||||
|
||||
private:
|
||||
struct CallbackInfo : public RefBase {
|
||||
|
@ -30,6 +30,7 @@ namespace {
|
||||
const char* DRAG_CLASS { "drag_class" };
|
||||
const char* DRAG { "drag" };
|
||||
inline constexpr size_t MAX_STRING_LEN { 1024 };
|
||||
inline constexpr std::string_view GET_VALUE_BOOL { "napi_get_value_bool" };
|
||||
} // namespace
|
||||
|
||||
JsDragContext::JsDragContext()
|
||||
@ -229,6 +230,68 @@ napi_value JsDragContext::GetDataSummary(napi_env env, napi_callback_info info)
|
||||
return jsDragMgr->GetDataSummary(env);
|
||||
}
|
||||
|
||||
napi_value JsDragContext::SetDragSwitchState(napi_env env, napi_callback_info info)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
size_t argc = ONE_PARAM;
|
||||
napi_value argv[ONE_PARAM] = { nullptr };
|
||||
CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO);
|
||||
|
||||
JsDragContext *jsDev = JsDragContext::GetInstance(env);
|
||||
CHKPP(jsDev);
|
||||
auto jsDragMgr = jsDev->GetJsDragMgr();
|
||||
CHKPP(jsDragMgr);
|
||||
if (argc < ONE_PARAM) {
|
||||
THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Wrong number of parameters");
|
||||
return nullptr;
|
||||
}
|
||||
if (!UtilNapi::TypeOf(env, argv[ZERO_PARAM], napi_boolean)) {
|
||||
THROWERR(env, COMMON_PARAMETER_ERROR, "enable", "boolean");
|
||||
return nullptr;
|
||||
}
|
||||
bool enable = false;
|
||||
CHKRP(napi_get_value_bool(env, argv[ZERO_PARAM], &enable), GET_VALUE_BOOL);
|
||||
jsDragMgr->SetDragSwitchState(env, enable);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value JsDragContext::SetAppDragSwitchState(napi_env env, napi_callback_info info)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
size_t argc = TWO_PARAM;
|
||||
napi_value argv[TWO_PARAM] = { nullptr };
|
||||
CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO);
|
||||
|
||||
JsDragContext *jsDev = JsDragContext::GetInstance(env);
|
||||
CHKPP(jsDev);
|
||||
auto jsDragMgr = jsDev->GetJsDragMgr();
|
||||
CHKPP(jsDragMgr);
|
||||
if (argc < TWO_PARAM) {
|
||||
THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Wrong number of parameters");
|
||||
return nullptr;
|
||||
}
|
||||
if (!UtilNapi::TypeOf(env, argv[ZERO_PARAM], napi_boolean)) {
|
||||
THROWERR(env, COMMON_PARAMETER_ERROR, "enable", "boolean");
|
||||
return nullptr;
|
||||
}
|
||||
if (!UtilNapi::TypeOf(env, argv[ONE_PARAM], napi_string)) {
|
||||
THROWERR(env, COMMON_PARAMETER_ERROR, "pkgName", "string");
|
||||
return nullptr;
|
||||
}
|
||||
bool enable = false;
|
||||
CHKRP(napi_get_value_bool(env, argv[ZERO_PARAM], &enable), GET_VALUE_BOOL);
|
||||
char param[MAX_STRING_LEN] = { 0 };
|
||||
size_t length = 0;
|
||||
CHKRP(napi_get_value_string_utf8(env, argv[ONE_PARAM], param, sizeof(param), &length), CREATE_STRING_UTF8);
|
||||
if (!length) {
|
||||
THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Parameter pkgName is empty");
|
||||
return nullptr;
|
||||
}
|
||||
std::string pkgName = param;
|
||||
jsDragMgr->SetAppDragSwitchState(env, enable, pkgName);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void JsDragContext::DeclareDragData(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_value startMsg = nullptr;
|
||||
@ -258,7 +321,9 @@ void JsDragContext::DeclareDragInterface(napi_env env, napi_value exports)
|
||||
napi_property_descriptor functions[] = {
|
||||
DECLARE_NAPI_STATIC_FUNCTION("on", On),
|
||||
DECLARE_NAPI_STATIC_FUNCTION("off", Off),
|
||||
DECLARE_NAPI_STATIC_FUNCTION("getDataSummary", GetDataSummary)
|
||||
DECLARE_NAPI_STATIC_FUNCTION("getDataSummary", GetDataSummary),
|
||||
DECLARE_NAPI_STATIC_FUNCTION("setDragSwitchState", SetDragSwitchState),
|
||||
DECLARE_NAPI_STATIC_FUNCTION("setAppDragSwitchState", SetAppDragSwitchState)
|
||||
};
|
||||
CHKRV(napi_define_properties(env, exports,
|
||||
sizeof(functions) / sizeof(*functions), functions), DEFINE_PROPERTIES);
|
||||
|
@ -74,6 +74,24 @@ napi_value JsDragManager::GetDataSummary(napi_env env)
|
||||
return arr;
|
||||
}
|
||||
|
||||
void JsDragManager::SetDragSwitchState(napi_env env, bool enable)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
INTERACTION_MGR->SetDragSwitchState(enable, true);
|
||||
}
|
||||
|
||||
void JsDragManager::SetAppDragSwitchState(napi_env env, bool enable, const std::string &pkgName)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
if (pkgName.empty()) {
|
||||
FI_HILOGE("The pkgName is empty");
|
||||
return;
|
||||
}
|
||||
INTERACTION_MGR->SetAppDragSwitchState(enable, pkgName, true);
|
||||
}
|
||||
|
||||
void JsDragManager::RegisterListener(napi_env env, napi_value handle)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
|
@ -230,6 +230,16 @@ int32_t InteractionManager::GetDragSummary(std::map<std::string, int64_t> &summa
|
||||
return INTER_MGR_IMPL.GetDragSummary(summarys, isJsCaller);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::SetDragSwitchState(bool enable, bool isJsCaller)
|
||||
{
|
||||
return INTER_MGR_IMPL.SetDragSwitchState(enable);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::SetAppDragSwitchState(bool enable, const std::string &pkgName, bool isJsCaller)
|
||||
{
|
||||
return INTER_MGR_IMPL.SetAppDragSwitchState(enable, pkgName);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::GetDragAction(DragAction &dragAction)
|
||||
{
|
||||
return INTER_MGR_IMPL.GetDragAction(dragAction);
|
||||
|
@ -57,6 +57,9 @@ public:
|
||||
int32_t SetDragWindowScreenId(ITunnelClient &tunnel, uint64_t displayId, uint64_t screenId);
|
||||
int32_t GetDragSummary(ITunnelClient &tunnel, std::map<std::string, int64_t> &summary,
|
||||
bool isJsCaller = false);
|
||||
int32_t SetDragSwitchState(ITunnelClient &tunnel, bool enable, bool isJsCaller = false);
|
||||
int32_t SetAppDragSwitchState(ITunnelClient &tunnel, bool enable, const std::string &pkgName,
|
||||
bool isJsCaller = false);
|
||||
int32_t GetDragState(ITunnelClient &tunnel, DragState &dragState);
|
||||
int32_t EnableUpperCenterMode(ITunnelClient &tunnel, bool enable);
|
||||
int32_t GetDragAction(ITunnelClient &tunnel, DragAction &dragAction);
|
||||
|
@ -344,6 +344,31 @@ int32_t DragClient::GetDragSummary(ITunnelClient &tunnel, std::map<std::string,
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t DragClient::SetDragSwitchState(ITunnelClient &tunnel, bool enable, bool isJsCaller)
|
||||
{
|
||||
SetDragSwitchStateParam param { enable, isJsCaller };
|
||||
DefaultReply reply {};
|
||||
|
||||
int32_t ret = tunnel.SetParam(Intention::DRAG, DragRequestID::SET_DRAG_SWITCH_STATE, param, reply);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("ITunnelClient::SetParam fail");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DragClient::SetAppDragSwitchState(ITunnelClient &tunnel, bool enable, const std::string &pkgName,
|
||||
bool isJsCaller)
|
||||
{
|
||||
SetAppDragSwitchStateParam param { enable, pkgName, isJsCaller };
|
||||
DefaultReply reply {};
|
||||
|
||||
int32_t ret = tunnel.SetParam(Intention::DRAG, DragRequestID::SET_APP_DRAG_SWITCH_STATE, param, reply);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("ITunnelClient::SetParam fail");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DragClient::GetDragState(ITunnelClient &tunnel, DragState &dragState)
|
||||
{
|
||||
DefaultParam param {};
|
||||
|
@ -44,6 +44,8 @@ enum DragRequestID : uint32_t {
|
||||
UPDATE_PREVIEW_STYLE_WITH_ANIMATION,
|
||||
ROTATE_DRAG_WINDOW_SYNC,
|
||||
GET_DRAG_SUMMARY,
|
||||
SET_DRAG_SWITCH_STATE,
|
||||
SET_APP_DRAG_SWITCH_STATE,
|
||||
GET_DRAG_STATE,
|
||||
ADD_PRIVILEGE,
|
||||
ENTER_TEXT_EDITOR_AREA,
|
||||
@ -228,6 +230,29 @@ struct GetDragSummaryReply final : public ParamBase {
|
||||
std::map<std::string, int64_t> summary_;
|
||||
};
|
||||
|
||||
struct SetDragSwitchStateParam final : public ParamBase {
|
||||
SetDragSwitchStateParam() = default;
|
||||
SetDragSwitchStateParam(bool enable, bool isJsCaller);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
bool enable_ { false };
|
||||
bool isJsCaller_ { false };
|
||||
};
|
||||
|
||||
struct SetAppDragSwitchStateParam final : public ParamBase {
|
||||
SetAppDragSwitchStateParam() = default;
|
||||
SetAppDragSwitchStateParam(bool enable, const std::string &pkgName, bool isJsCaller);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
bool enable_ { false };
|
||||
std::string pkgName_;
|
||||
bool isJsCaller_ { false };
|
||||
};
|
||||
|
||||
struct GetDragStateReply final : public ParamBase {
|
||||
GetDragStateReply() = default;
|
||||
explicit GetDragStateReply(DragState dragState);
|
||||
|
@ -350,6 +350,34 @@ bool GetDragSummaryReply::Unmarshalling(MessageParcel &parcel)
|
||||
return (SummaryPacker::UnMarshalling(parcel, summary_) == RET_OK);
|
||||
}
|
||||
|
||||
SetDragSwitchStateParam::SetDragSwitchStateParam(bool enable, bool isJsCaller)
|
||||
: enable_(enable), isJsCaller_(isJsCaller)
|
||||
{}
|
||||
|
||||
bool SetDragSwitchStateParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return parcel.WriteBool(enable_) && parcel.WriteBool(isJsCaller_);
|
||||
}
|
||||
|
||||
bool SetDragSwitchStateParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return parcel.ReadBool(enable_) && parcel.ReadBool(isJsCaller_);
|
||||
}
|
||||
|
||||
SetAppDragSwitchStateParam::SetAppDragSwitchStateParam(bool enable, const std::string &pkgName, bool isJsCaller)
|
||||
: enable_(enable), pkgName_(pkgName), isJsCaller_(isJsCaller)
|
||||
{}
|
||||
|
||||
bool SetAppDragSwitchStateParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return parcel.WriteBool(enable_) && parcel.WriteString(pkgName_) && parcel.WriteBool(isJsCaller_);
|
||||
}
|
||||
|
||||
bool SetAppDragSwitchStateParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return parcel.ReadBool(enable_) && parcel.ReadString(pkgName_) && parcel.ReadBool(isJsCaller_);
|
||||
}
|
||||
|
||||
GetDragStateReply::GetDragStateReply(DragState dragState)
|
||||
: dragState_(dragState)
|
||||
{}
|
||||
|
@ -58,6 +58,8 @@ private:
|
||||
int32_t GetDragState(CallingContext &context, MessageParcel &data, MessageParcel &reply);
|
||||
__attribute__((no_sanitize("cfi"))) int32_t GetDragSummary(CallingContext &context,
|
||||
MessageParcel &data, MessageParcel &reply);
|
||||
int32_t SetDragSwitchState(CallingContext &context, MessageParcel &data, MessageParcel &reply);
|
||||
int32_t SetAppDragSwitchState(CallingContext &context, MessageParcel &data, MessageParcel &reply);
|
||||
int32_t GetDragAction(CallingContext &context, MessageParcel &data, MessageParcel &reply);
|
||||
int32_t GetExtraInfo(CallingContext &context, MessageParcel &data, MessageParcel &reply);
|
||||
int32_t EnterTextEditorArea(CallingContext &context, MessageParcel &data, MessageParcel &reply);
|
||||
|
@ -135,6 +135,12 @@ int32_t DragServer::SetParam(CallingContext &context, uint32_t id, MessageParcel
|
||||
case DragRequestID::ADD_SELECTED_PIXELMAP: {
|
||||
return AddSelectedPixelMap(context, data, reply);
|
||||
}
|
||||
case DragRequestID::SET_DRAG_SWITCH_STATE: {
|
||||
return SetDragSwitchState(context, data, reply);
|
||||
}
|
||||
case DragRequestID::SET_APP_DRAG_SWITCH_STATE: {
|
||||
return SetAppDragSwitchState(context, data, reply);
|
||||
}
|
||||
case DragRequestID::SET_DRAGGABLE_STATE: {
|
||||
return SetDraggableState(context, data, reply);
|
||||
}
|
||||
@ -455,6 +461,36 @@ int32_t DragServer::GetDragSummary(CallingContext &context, MessageParcel &data,
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t DragServer::SetDragSwitchState(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
SetDragSwitchStateParam param {};
|
||||
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("SetDragSwitchStateParam::Unmarshalling fail");
|
||||
return RET_ERR;
|
||||
}
|
||||
if (param.isJsCaller_ && !IsSystemHAPCalling(context)) {
|
||||
FI_HILOGE("The caller is not system hap");
|
||||
return COMMON_NOT_SYSTEM_APP;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t DragServer::SetAppDragSwitchState(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
SetAppDragSwitchStateParam param {};
|
||||
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("SetAppDragSwitchStateParam::Unmarshalling fail");
|
||||
return RET_ERR;
|
||||
}
|
||||
if (param.isJsCaller_ && !IsSystemHAPCalling(context)) {
|
||||
FI_HILOGE("The caller is not system hap");
|
||||
return COMMON_NOT_SYSTEM_APP;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t DragServer::GetDragAction(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
DragAction dragAction {};
|
||||
|
@ -77,6 +77,8 @@ public:
|
||||
int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, const PreviewAnimation &animation);
|
||||
int32_t RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr);
|
||||
int32_t GetDragSummary(std::map<std::string, int64_t> &summarys, bool isJsCaller = false);
|
||||
int32_t SetDragSwitchState(bool enable, bool isJsCaller = false);
|
||||
int32_t SetAppDragSwitchState(bool enable, const std::string &pkgName, bool isJsCaller = false);
|
||||
int32_t EnterTextEditorArea(bool enable);
|
||||
int32_t GetDragAction(DragAction &dragAction);
|
||||
int32_t GetExtraInfo(std::string &extraInfo);
|
||||
|
@ -459,6 +459,18 @@ int32_t IntentionManager::GetDragSummary(std::map<std::string, int64_t> &summary
|
||||
return drag_.GetDragSummary(*tunnel_, summarys, isJsCaller);
|
||||
}
|
||||
|
||||
int32_t IntentionManager::SetDragSwitchState(bool enable, bool isJsCaller)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return drag_.SetDragSwitchState(*tunnel_, enable, isJsCaller);
|
||||
}
|
||||
|
||||
int32_t IntentionManager::SetAppDragSwitchState(bool enable, const std::string &pkgName, bool isJsCaller)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return drag_.SetAppDragSwitchState(*tunnel_, enable, pkgName, isJsCaller);
|
||||
}
|
||||
|
||||
int32_t IntentionManager::EnterTextEditorArea(bool enable)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
|
@ -360,6 +360,25 @@ public:
|
||||
* @since 11
|
||||
*/
|
||||
int32_t GetDragSummary(std::map<std::string, int64_t> &summarys, bool isJsCaller = false);
|
||||
|
||||
/**
|
||||
* @brief Sets the master switch for enhancing the drag capability.
|
||||
* @param enable Switch state.
|
||||
* @param isJsCaller Indicates whether to add checking.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
|
||||
* @since 14
|
||||
*/
|
||||
int32_t SetDragSwitchState(bool enable, bool isJsCaller = false);
|
||||
|
||||
/**
|
||||
* @brief Sets the app switch for enhancing the drag capability.
|
||||
* @param enable Switch state.
|
||||
* @param pkgName App package name.
|
||||
* @param isJsCaller Indicates whether to add checking.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
|
||||
* @since 14
|
||||
*/
|
||||
int32_t SetAppDragSwitchState(bool enable, const std::string &pkgName, bool isJsCaller = false);
|
||||
#else
|
||||
/**
|
||||
* @brief Obtains data summary of the drag object.
|
||||
|
@ -61,6 +61,8 @@
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::RotateDragWindowSync(std::__h::shared_ptr<OHOS::Rosen::RSTransaction> const&)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::GetDragSummary(std::__h::map<std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>>, long long, std::__h::less<std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>>>, std::__h::allocator<std::__h::pair<std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const, long long>>>&, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::GetDragSummary(std::__h::map<std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>>, long, std::__h::less<std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>>>, std::__h::allocator<std::__h::pair<std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const, long>>>&, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::SetDragSwitchState(bool, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::SetAppDragSwitchState(bool, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::GetDropType(OHOS::Msdp::DeviceStatus::DropType&)";
|
||||
"OHOS::Msdp::DeviceStatus::DragDataUtil::Marshalling(OHOS::Msdp::DeviceStatus::DragData const&, OHOS::Parcel&, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::DragDataUtil::UnMarshalling(OHOS::Parcel&, OHOS::Msdp::DeviceStatus::DragData&, bool)";
|
||||
|
Loading…
Reference in New Issue
Block a user