1f857971dSopenharmony_ci/* 2f857971dSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f857971dSopenharmony_ci * you may not use this file except in compliance with the License. 5f857971dSopenharmony_ci * You may obtain a copy of the License at 6f857971dSopenharmony_ci * 7f857971dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f857971dSopenharmony_ci * 9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f857971dSopenharmony_ci * See the License for the specific language governing permissions and 13f857971dSopenharmony_ci * limitations under the License. 14f857971dSopenharmony_ci */ 15f857971dSopenharmony_ci 16f857971dSopenharmony_ci#include "drag_server.h" 17f857971dSopenharmony_ci 18f857971dSopenharmony_ci#include "tokenid_kit.h" 19f857971dSopenharmony_ci 20f857971dSopenharmony_ci#include "accesstoken_kit.h" 21f857971dSopenharmony_ci#include "drag_params.h" 22f857971dSopenharmony_ci#include "devicestatus_define.h" 23f857971dSopenharmony_ci 24f857971dSopenharmony_ci#undef LOG_TAG 25f857971dSopenharmony_ci#define LOG_TAG "DragServer" 26f857971dSopenharmony_ci 27f857971dSopenharmony_cinamespace OHOS { 28f857971dSopenharmony_cinamespace Msdp { 29f857971dSopenharmony_cinamespace DeviceStatus { 30f857971dSopenharmony_ci 31f857971dSopenharmony_ciDragServer::DragServer(IContext *env) 32f857971dSopenharmony_ci : env_(env) 33f857971dSopenharmony_ci{} 34f857971dSopenharmony_ci 35f857971dSopenharmony_ciint32_t DragServer::Enable(CallingContext &context, MessageParcel &data, MessageParcel &reply) 36f857971dSopenharmony_ci{ 37f857971dSopenharmony_ci CALL_DEBUG_ENTER; 38f857971dSopenharmony_ci return RET_ERR; 39f857971dSopenharmony_ci} 40f857971dSopenharmony_ci 41f857971dSopenharmony_ciint32_t DragServer::Disable(CallingContext &context, MessageParcel &data, MessageParcel &reply) 42f857971dSopenharmony_ci{ 43f857971dSopenharmony_ci CALL_DEBUG_ENTER; 44f857971dSopenharmony_ci return RET_ERR; 45f857971dSopenharmony_ci} 46f857971dSopenharmony_ci 47f857971dSopenharmony_ciint32_t DragServer::Start(CallingContext &context, MessageParcel &data, MessageParcel &reply) 48f857971dSopenharmony_ci{ 49f857971dSopenharmony_ci CALL_DEBUG_ENTER; 50f857971dSopenharmony_ci DragData dragData {}; 51f857971dSopenharmony_ci StartDragParam param { dragData }; 52f857971dSopenharmony_ci 53f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 54f857971dSopenharmony_ci FI_HILOGE("Failed to unmarshalling param"); 55f857971dSopenharmony_ci return RET_ERR; 56f857971dSopenharmony_ci } 57f857971dSopenharmony_ci CHKPR(env_, RET_ERR); 58f857971dSopenharmony_ci auto session = env_->GetSocketSessionManager().FindSessionByPid(context.pid); 59f857971dSopenharmony_ci CHKPR(session, RET_ERR); 60f857971dSopenharmony_ci session->SetProgramName(GetPackageName(context.tokenId)); 61f857971dSopenharmony_ci return env_->GetDragManager().StartDrag(dragData, context.pid); 62f857971dSopenharmony_ci} 63f857971dSopenharmony_ci 64f857971dSopenharmony_ciint32_t DragServer::Stop(CallingContext &context, MessageParcel &data, MessageParcel &reply) 65f857971dSopenharmony_ci{ 66f857971dSopenharmony_ci CALL_DEBUG_ENTER; 67f857971dSopenharmony_ci StopDragParam param {}; 68f857971dSopenharmony_ci 69f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 70f857971dSopenharmony_ci FI_HILOGE("Failed to unmarshalling param"); 71f857971dSopenharmony_ci return RET_ERR; 72f857971dSopenharmony_ci } 73f857971dSopenharmony_ci CHKPR(env_, RET_ERR); 74f857971dSopenharmony_ci return env_->GetDragManager().StopDrag(param.dropResult_, GetPackageName(context.tokenId), context.pid); 75f857971dSopenharmony_ci} 76f857971dSopenharmony_ci 77f857971dSopenharmony_ciint32_t DragServer::AddWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) 78f857971dSopenharmony_ci{ 79f857971dSopenharmony_ci CALL_DEBUG_ENTER; 80f857971dSopenharmony_ci switch (id) { 81f857971dSopenharmony_ci case DragRequestID::ADD_DRAG_LISTENER: { 82f857971dSopenharmony_ci return AddListener(context, data); 83f857971dSopenharmony_ci } 84f857971dSopenharmony_ci case DragRequestID::ADD_SUBSCRIPT_LISTENER: { 85f857971dSopenharmony_ci FI_HILOGD("Add subscript listener, from:%{public}d", context.pid); 86f857971dSopenharmony_ci return env_->GetDragManager().AddSubscriptListener(context.pid); 87f857971dSopenharmony_ci } 88f857971dSopenharmony_ci default: { 89f857971dSopenharmony_ci FI_HILOGE("Unexpected request ID (%{public}u)", id); 90f857971dSopenharmony_ci return RET_ERR; 91f857971dSopenharmony_ci } 92f857971dSopenharmony_ci } 93f857971dSopenharmony_ci} 94f857971dSopenharmony_ci 95f857971dSopenharmony_ciint32_t DragServer::RemoveWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) 96f857971dSopenharmony_ci{ 97f857971dSopenharmony_ci CALL_DEBUG_ENTER; 98f857971dSopenharmony_ci switch (id) { 99f857971dSopenharmony_ci case DragRequestID::REMOVE_DRAG_LISTENER: { 100f857971dSopenharmony_ci return RemoveListener(context, data); 101f857971dSopenharmony_ci } 102f857971dSopenharmony_ci case DragRequestID::REMOVE_SUBSCRIPT_LISTENER: { 103f857971dSopenharmony_ci FI_HILOGD("Remove subscript listener, from:%{public}d", context.pid); 104f857971dSopenharmony_ci return env_->GetDragManager().RemoveSubscriptListener(context.pid); 105f857971dSopenharmony_ci } 106f857971dSopenharmony_ci default: { 107f857971dSopenharmony_ci FI_HILOGE("Unexpected request ID (%{public}u)", id); 108f857971dSopenharmony_ci return RET_ERR; 109f857971dSopenharmony_ci } 110f857971dSopenharmony_ci } 111f857971dSopenharmony_ci} 112f857971dSopenharmony_ci 113f857971dSopenharmony_ciint32_t DragServer::SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) 114f857971dSopenharmony_ci{ 115f857971dSopenharmony_ci CALL_DEBUG_ENTER; 116f857971dSopenharmony_ci switch (id) { 117f857971dSopenharmony_ci case DragRequestID::SET_DRAG_WINDOW_VISIBLE: { 118f857971dSopenharmony_ci return SetDragWindowVisible(context, data, reply); 119f857971dSopenharmony_ci } 120f857971dSopenharmony_ci case DragRequestID::UPDATE_DRAG_STYLE: { 121f857971dSopenharmony_ci return UpdateDragStyle(context, data, reply); 122f857971dSopenharmony_ci } 123f857971dSopenharmony_ci case DragRequestID::UPDATE_SHADOW_PIC: { 124f857971dSopenharmony_ci return UpdateShadowPic(context, data, reply); 125f857971dSopenharmony_ci } 126f857971dSopenharmony_ci case DragRequestID::UPDATE_PREVIEW_STYLE: { 127f857971dSopenharmony_ci return UpdatePreviewStyle(context, data, reply); 128f857971dSopenharmony_ci } 129f857971dSopenharmony_ci case DragRequestID::UPDATE_PREVIEW_STYLE_WITH_ANIMATION: { 130f857971dSopenharmony_ci return UpdatePreviewAnimation(context, data, reply); 131f857971dSopenharmony_ci } 132f857971dSopenharmony_ci case DragRequestID::SET_DRAG_WINDOW_SCREEN_ID: { 133f857971dSopenharmony_ci return SetDragWindowScreenId(context, data, reply); 134f857971dSopenharmony_ci } 135f857971dSopenharmony_ci case DragRequestID::ADD_SELECTED_PIXELMAP: { 136f857971dSopenharmony_ci return AddSelectedPixelMap(context, data, reply); 137f857971dSopenharmony_ci } 138f857971dSopenharmony_ci default: { 139f857971dSopenharmony_ci FI_HILOGE("Unexpected request ID (%{public}u)", id); 140f857971dSopenharmony_ci return RET_ERR; 141f857971dSopenharmony_ci } 142f857971dSopenharmony_ci } 143f857971dSopenharmony_ci} 144f857971dSopenharmony_ci 145f857971dSopenharmony_ciint32_t DragServer::GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) 146f857971dSopenharmony_ci{ 147f857971dSopenharmony_ci CALL_DEBUG_ENTER; 148f857971dSopenharmony_ci switch (id) { 149f857971dSopenharmony_ci case DragRequestID::GET_DRAG_TARGET_PID: { 150f857971dSopenharmony_ci FI_HILOGI("Get drag target pid, from:%{public}d", context.pid); 151f857971dSopenharmony_ci return GetDragTargetPid(context, data, reply); 152f857971dSopenharmony_ci } 153f857971dSopenharmony_ci case DragRequestID::GET_UDKEY: { 154f857971dSopenharmony_ci FI_HILOGI("Get udkey, from:%{public}d", context.pid); 155f857971dSopenharmony_ci return GetUdKey(context, data, reply); 156f857971dSopenharmony_ci } 157f857971dSopenharmony_ci case DragRequestID::GET_SHADOW_OFFSET: { 158f857971dSopenharmony_ci FI_HILOGD("Get shadow offset, from:%{public}d", context.pid); 159f857971dSopenharmony_ci return GetShadowOffset(context, data, reply); 160f857971dSopenharmony_ci } 161f857971dSopenharmony_ci case DragRequestID::GET_DRAG_DATA: { 162f857971dSopenharmony_ci FI_HILOGD("Get drag data, from:%{public}d", context.pid); 163f857971dSopenharmony_ci return GetDragData(context, data, reply); 164f857971dSopenharmony_ci } 165f857971dSopenharmony_ci case DragRequestID::GET_DRAG_STATE: { 166f857971dSopenharmony_ci FI_HILOGD("Get drag state, from:%{public}d", context.pid); 167f857971dSopenharmony_ci return GetDragState(context, data, reply); 168f857971dSopenharmony_ci } 169f857971dSopenharmony_ci case DragRequestID::GET_DRAG_SUMMARY: { 170f857971dSopenharmony_ci FI_HILOGD("Get drag summary, from:%{public}d", context.pid); 171f857971dSopenharmony_ci return GetDragSummary(context, data, reply); 172f857971dSopenharmony_ci } 173f857971dSopenharmony_ci case DragRequestID::GET_DRAG_ACTION: { 174f857971dSopenharmony_ci FI_HILOGI("Get drag action, from:%{public}d", context.pid); 175f857971dSopenharmony_ci return GetDragAction(context, data, reply); 176f857971dSopenharmony_ci } 177f857971dSopenharmony_ci case DragRequestID::GET_EXTRA_INFO: { 178f857971dSopenharmony_ci FI_HILOGI("Get extra info, from:%{public}d", context.pid); 179f857971dSopenharmony_ci return GetExtraInfo(context, data, reply); 180f857971dSopenharmony_ci } 181f857971dSopenharmony_ci default: { 182f857971dSopenharmony_ci FI_HILOGE("Unexpected request ID (%{public}u)", id); 183f857971dSopenharmony_ci return RET_ERR; 184f857971dSopenharmony_ci } 185f857971dSopenharmony_ci } 186f857971dSopenharmony_ci} 187f857971dSopenharmony_ci 188f857971dSopenharmony_ciint32_t DragServer::Control(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) 189f857971dSopenharmony_ci{ 190f857971dSopenharmony_ci CALL_DEBUG_ENTER; 191f857971dSopenharmony_ci switch (id) { 192f857971dSopenharmony_ci case DragRequestID::ADD_PRIVILEGE: { 193f857971dSopenharmony_ci FI_HILOGI("Add privilege, from:%{public}d", context.pid); 194f857971dSopenharmony_ci return env_->GetDragManager().AddPrivilege(context.tokenId); 195f857971dSopenharmony_ci } 196f857971dSopenharmony_ci case DragRequestID::ENTER_TEXT_EDITOR_AREA: { 197f857971dSopenharmony_ci FI_HILOGI("Enter text editor area, from:%{public}d", context.pid); 198f857971dSopenharmony_ci return EnterTextEditorArea(context, data, reply); 199f857971dSopenharmony_ci } 200f857971dSopenharmony_ci case DragRequestID::ROTATE_DRAG_WINDOW_SYNC: { 201f857971dSopenharmony_ci FI_HILOGI("Rotate drag window sync, from:%{public}d", context.pid); 202f857971dSopenharmony_ci return RotateDragWindowSync(context, data, reply); 203f857971dSopenharmony_ci } 204f857971dSopenharmony_ci case DragRequestID::ERASE_MOUSE_ICON: { 205f857971dSopenharmony_ci FI_HILOGI("Erase mouse, from:%{public}d", context.pid); 206f857971dSopenharmony_ci return env_->GetDragManager().EraseMouseIcon(); 207f857971dSopenharmony_ci } 208f857971dSopenharmony_ci case DragRequestID::SET_MOUSE_DRAG_MONITOR_STATE: { 209f857971dSopenharmony_ci FI_HILOGI("Set mouse drag monitor state, from:%{public}d", context.pid); 210f857971dSopenharmony_ci return SetMouseDragMonitorState(context, data, reply); 211f857971dSopenharmony_ci } 212f857971dSopenharmony_ci default: { 213f857971dSopenharmony_ci FI_HILOGE("Unexpected request ID (%{public}u)", id); 214f857971dSopenharmony_ci return RET_ERR; 215f857971dSopenharmony_ci } 216f857971dSopenharmony_ci } 217f857971dSopenharmony_ci} 218f857971dSopenharmony_ci 219f857971dSopenharmony_ciint32_t DragServer::AddListener(CallingContext &context, MessageParcel &data) 220f857971dSopenharmony_ci{ 221f857971dSopenharmony_ci AddDraglistenerParam param {}; 222f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 223f857971dSopenharmony_ci FI_HILOGE("AddDraglistenerParam::Unmarshalling fail"); 224f857971dSopenharmony_ci return RET_ERR; 225f857971dSopenharmony_ci } 226f857971dSopenharmony_ci 227f857971dSopenharmony_ci if (param.isJsCaller_ && !IsSystemHAPCalling(context)) { 228f857971dSopenharmony_ci FI_HILOGE("The caller is not system hap"); 229f857971dSopenharmony_ci return COMMON_NOT_SYSTEM_APP; 230f857971dSopenharmony_ci } 231f857971dSopenharmony_ci FI_HILOGI("Add drag listener, from:%{public}d", context.pid); 232f857971dSopenharmony_ci return env_->GetDragManager().AddListener(context.pid); 233f857971dSopenharmony_ci} 234f857971dSopenharmony_ci 235f857971dSopenharmony_ciint32_t DragServer::RemoveListener(CallingContext &context, MessageParcel &data) 236f857971dSopenharmony_ci{ 237f857971dSopenharmony_ci RemoveDraglistenerParam param {}; 238f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 239f857971dSopenharmony_ci FI_HILOGE("RemoveDraglistenerParam::Unmarshalling fail"); 240f857971dSopenharmony_ci return RET_ERR; 241f857971dSopenharmony_ci } 242f857971dSopenharmony_ci 243f857971dSopenharmony_ci if (param.isJsCaller_ && !IsSystemHAPCalling(context)) { 244f857971dSopenharmony_ci FI_HILOGE("The caller is not system hap"); 245f857971dSopenharmony_ci return COMMON_NOT_SYSTEM_APP; 246f857971dSopenharmony_ci } 247f857971dSopenharmony_ci FI_HILOGD("Remove drag listener, from:%{public}d", context.pid); 248f857971dSopenharmony_ci return env_->GetDragManager().RemoveListener(context.pid); 249f857971dSopenharmony_ci} 250f857971dSopenharmony_ci 251f857971dSopenharmony_ciint32_t DragServer::SetDragWindowVisible(CallingContext &context, MessageParcel &data, MessageParcel &reply) 252f857971dSopenharmony_ci{ 253f857971dSopenharmony_ci SetDragWindowVisibleParam param {}; 254f857971dSopenharmony_ci 255f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 256f857971dSopenharmony_ci FI_HILOGE("SetDragWindowVisibleParam::Unmarshalling fail"); 257f857971dSopenharmony_ci return RET_ERR; 258f857971dSopenharmony_ci } 259f857971dSopenharmony_ci FI_HILOGI("SetDragWindowVisible(%{public}d, %{public}d)", param.visible_, param.isForce_); 260f857971dSopenharmony_ci return env_->GetDragManager().OnSetDragWindowVisible(param.visible_, param.isForce_); 261f857971dSopenharmony_ci} 262f857971dSopenharmony_ci 263f857971dSopenharmony_ciint32_t DragServer::UpdateDragStyle(CallingContext &context, MessageParcel &data, MessageParcel &reply) 264f857971dSopenharmony_ci{ 265f857971dSopenharmony_ci UpdateDragStyleParam param {}; 266f857971dSopenharmony_ci 267f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 268f857971dSopenharmony_ci FI_HILOGE("UpdateDragStyleParam::Unmarshalling fail"); 269f857971dSopenharmony_ci return RET_ERR; 270f857971dSopenharmony_ci } 271f857971dSopenharmony_ci FI_HILOGI("UpdateDragStyle(%{public}d)", static_cast<int32_t>(param.cursorStyle_)); 272f857971dSopenharmony_ci return env_->GetDragManager().UpdateDragStyle(param.cursorStyle_, context.pid, context.tokenId, param.eventId_); 273f857971dSopenharmony_ci} 274f857971dSopenharmony_ci 275f857971dSopenharmony_ciint32_t DragServer::UpdateShadowPic(CallingContext &context, MessageParcel &data, MessageParcel &reply) 276f857971dSopenharmony_ci{ 277f857971dSopenharmony_ci UpdateShadowPicParam param {}; 278f857971dSopenharmony_ci 279f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 280f857971dSopenharmony_ci FI_HILOGE("UpdateShadowPicParam::Unmarshalling fail"); 281f857971dSopenharmony_ci return RET_ERR; 282f857971dSopenharmony_ci } 283f857971dSopenharmony_ci FI_HILOGD("Updata shadow pic"); 284f857971dSopenharmony_ci return env_->GetDragManager().UpdateShadowPic(param.shadowInfo_); 285f857971dSopenharmony_ci} 286f857971dSopenharmony_ci 287f857971dSopenharmony_ciint32_t DragServer::AddSelectedPixelMap(CallingContext &context, MessageParcel &data, MessageParcel &reply) 288f857971dSopenharmony_ci{ 289f857971dSopenharmony_ci AddSelectedPixelMapParam param {}; 290f857971dSopenharmony_ci 291f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 292f857971dSopenharmony_ci FI_HILOGE("AddSelectedPixelMap::Unmarshalling fail"); 293f857971dSopenharmony_ci return RET_ERR; 294f857971dSopenharmony_ci } 295f857971dSopenharmony_ci return env_->GetDragManager().AddSelectedPixelMap(param.pixelMap_); 296f857971dSopenharmony_ci} 297f857971dSopenharmony_ci 298f857971dSopenharmony_ciint32_t DragServer::UpdatePreviewStyle(CallingContext &context, MessageParcel &data, MessageParcel &reply) 299f857971dSopenharmony_ci{ 300f857971dSopenharmony_ci UpdatePreviewStyleParam param {}; 301f857971dSopenharmony_ci 302f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 303f857971dSopenharmony_ci FI_HILOGE("UpdatePreviewStyleParam::Unmarshalling fail"); 304f857971dSopenharmony_ci return RET_ERR; 305f857971dSopenharmony_ci } 306f857971dSopenharmony_ci return env_->GetDragManager().UpdatePreviewStyle(param.previewStyle_); 307f857971dSopenharmony_ci} 308f857971dSopenharmony_ci 309f857971dSopenharmony_ciint32_t DragServer::UpdatePreviewAnimation(CallingContext &context, MessageParcel &data, MessageParcel &reply) 310f857971dSopenharmony_ci{ 311f857971dSopenharmony_ci UpdatePreviewAnimationParam param {}; 312f857971dSopenharmony_ci 313f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 314f857971dSopenharmony_ci FI_HILOGE("UpdatePreviewAnimationParam::Unmarshalling fail"); 315f857971dSopenharmony_ci return RET_ERR; 316f857971dSopenharmony_ci } 317f857971dSopenharmony_ci return env_->GetDragManager().UpdatePreviewStyleWithAnimation(param.previewStyle_, param.previewAnimation_); 318f857971dSopenharmony_ci} 319f857971dSopenharmony_ci 320f857971dSopenharmony_ciint32_t DragServer::RotateDragWindowSync(CallingContext &context, MessageParcel &data, MessageParcel &reply) 321f857971dSopenharmony_ci{ 322f857971dSopenharmony_ci RotateDragWindowSyncParam param {}; 323f857971dSopenharmony_ci 324f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 325f857971dSopenharmony_ci FI_HILOGE("RotateDragWindowSync::Unmarshalling fail"); 326f857971dSopenharmony_ci return RET_ERR; 327f857971dSopenharmony_ci } 328f857971dSopenharmony_ci return env_->GetDragManager().RotateDragWindowSync(param.rsTransaction_); 329f857971dSopenharmony_ci} 330f857971dSopenharmony_ci 331f857971dSopenharmony_ciint32_t DragServer::SetDragWindowScreenId(CallingContext &context, MessageParcel &data, MessageParcel &reply) 332f857971dSopenharmony_ci{ 333f857971dSopenharmony_ci SetDragWindowScreenIdParam param {}; 334f857971dSopenharmony_ci 335f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 336f857971dSopenharmony_ci FI_HILOGE("SetDragWindowScreenId::Unmarshalling fail"); 337f857971dSopenharmony_ci return RET_ERR; 338f857971dSopenharmony_ci } 339f857971dSopenharmony_ci env_->GetDragManager().SetDragWindowScreenId(param.displayId_, param.screenId_); 340f857971dSopenharmony_ci return RET_OK; 341f857971dSopenharmony_ci} 342f857971dSopenharmony_ci 343f857971dSopenharmony_ciint32_t DragServer::GetDragTargetPid(CallingContext &context, MessageParcel &data, MessageParcel &reply) 344f857971dSopenharmony_ci{ 345f857971dSopenharmony_ci int32_t targetPid = env_->GetDragManager().GetDragTargetPid(); 346f857971dSopenharmony_ci GetDragTargetPidReply targetPidReply { targetPid }; 347f857971dSopenharmony_ci 348f857971dSopenharmony_ci if (!targetPidReply.Marshalling(reply)) { 349f857971dSopenharmony_ci FI_HILOGE("GetDragTargetPidReply::Marshalling fail"); 350f857971dSopenharmony_ci return RET_ERR; 351f857971dSopenharmony_ci } 352f857971dSopenharmony_ci return RET_OK; 353f857971dSopenharmony_ci} 354f857971dSopenharmony_ci 355f857971dSopenharmony_ciint32_t DragServer::GetUdKey(CallingContext &context, MessageParcel &data, MessageParcel &reply) 356f857971dSopenharmony_ci{ 357f857971dSopenharmony_ci std::string udKey; 358f857971dSopenharmony_ci 359f857971dSopenharmony_ci int32_t ret = env_->GetDragManager().GetUdKey(udKey); 360f857971dSopenharmony_ci if (ret != RET_OK) { 361f857971dSopenharmony_ci FI_HILOGE("IDragManager::GetUdKey fail, error:%{public}d", ret); 362f857971dSopenharmony_ci return ret; 363f857971dSopenharmony_ci } 364f857971dSopenharmony_ci GetUdKeyReply udKeyReply { std::move(udKey) }; 365f857971dSopenharmony_ci 366f857971dSopenharmony_ci if (!udKeyReply.Marshalling(reply)) { 367f857971dSopenharmony_ci FI_HILOGE("GetUdKeyReply::Marshalling fail"); 368f857971dSopenharmony_ci return RET_ERR; 369f857971dSopenharmony_ci } 370f857971dSopenharmony_ci return RET_OK; 371f857971dSopenharmony_ci} 372f857971dSopenharmony_ci 373f857971dSopenharmony_ciint32_t DragServer::GetShadowOffset(CallingContext &context, MessageParcel &data, MessageParcel &reply) 374f857971dSopenharmony_ci{ 375f857971dSopenharmony_ci ShadowOffset shadowOffset {}; 376f857971dSopenharmony_ci 377f857971dSopenharmony_ci int32_t ret = env_->GetDragManager().OnGetShadowOffset(shadowOffset); 378f857971dSopenharmony_ci if (ret != RET_OK) { 379f857971dSopenharmony_ci FI_HILOGE("IDragManager::GetShadowOffset fail, error:%{public}d", ret); 380f857971dSopenharmony_ci return ret; 381f857971dSopenharmony_ci } 382f857971dSopenharmony_ci GetShadowOffsetReply shadowOffsetReply { shadowOffset }; 383f857971dSopenharmony_ci 384f857971dSopenharmony_ci if (!shadowOffsetReply.Marshalling(reply)) { 385f857971dSopenharmony_ci FI_HILOGE("GetShadowOffsetReply::Marshalling fail"); 386f857971dSopenharmony_ci return RET_ERR; 387f857971dSopenharmony_ci } 388f857971dSopenharmony_ci return RET_OK; 389f857971dSopenharmony_ci} 390f857971dSopenharmony_ci 391f857971dSopenharmony_ciint32_t DragServer::GetDragData(CallingContext &context, MessageParcel &data, MessageParcel &reply) 392f857971dSopenharmony_ci{ 393f857971dSopenharmony_ci DragData dragData {}; 394f857971dSopenharmony_ci 395f857971dSopenharmony_ci int32_t ret = env_->GetDragManager().GetDragData(dragData); 396f857971dSopenharmony_ci if (ret != RET_OK) { 397f857971dSopenharmony_ci FI_HILOGE("IDragManager::GetDragData fail, error:%{public}d", ret); 398f857971dSopenharmony_ci return ret; 399f857971dSopenharmony_ci } 400f857971dSopenharmony_ci GetDragDataReply dragDataReply { static_cast<const DragData&>(dragData) }; 401f857971dSopenharmony_ci 402f857971dSopenharmony_ci if (!dragDataReply.Marshalling(reply)) { 403f857971dSopenharmony_ci FI_HILOGE("GetDragDataReply::Marshalling fail"); 404f857971dSopenharmony_ci return RET_ERR; 405f857971dSopenharmony_ci } 406f857971dSopenharmony_ci return RET_OK; 407f857971dSopenharmony_ci} 408f857971dSopenharmony_ci 409f857971dSopenharmony_ciint32_t DragServer::GetDragState(CallingContext &context, MessageParcel &data, MessageParcel &reply) 410f857971dSopenharmony_ci{ 411f857971dSopenharmony_ci DragState dragState {}; 412f857971dSopenharmony_ci 413f857971dSopenharmony_ci int32_t ret = env_->GetDragManager().GetDragState(dragState); 414f857971dSopenharmony_ci if (ret != RET_OK) { 415f857971dSopenharmony_ci FI_HILOGE("IDragManager::GetDragState fail, error:%{public}d", ret); 416f857971dSopenharmony_ci return ret; 417f857971dSopenharmony_ci } 418f857971dSopenharmony_ci GetDragStateReply dragStateReply { dragState }; 419f857971dSopenharmony_ci 420f857971dSopenharmony_ci if (!dragStateReply.Marshalling(reply)) { 421f857971dSopenharmony_ci FI_HILOGE("GetDragStateReply::Marshalling fail"); 422f857971dSopenharmony_ci return RET_ERR; 423f857971dSopenharmony_ci } 424f857971dSopenharmony_ci return RET_OK; 425f857971dSopenharmony_ci} 426f857971dSopenharmony_ci 427f857971dSopenharmony_ciint32_t DragServer::GetDragSummary(CallingContext &context, MessageParcel &data, MessageParcel &reply) 428f857971dSopenharmony_ci{ 429f857971dSopenharmony_ci GetDragSummaryParam param {}; 430f857971dSopenharmony_ci 431f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 432f857971dSopenharmony_ci FI_HILOGE("GetDragSummary::Unmarshalling fail"); 433f857971dSopenharmony_ci return RET_ERR; 434f857971dSopenharmony_ci } 435f857971dSopenharmony_ci if (param.isJsCaller_ && !IsSystemHAPCalling(context)) { 436f857971dSopenharmony_ci FI_HILOGE("The caller is not system hap"); 437f857971dSopenharmony_ci return COMMON_NOT_SYSTEM_APP; 438f857971dSopenharmony_ci } 439f857971dSopenharmony_ci std::map<std::string, int64_t> summaries; 440f857971dSopenharmony_ci 441f857971dSopenharmony_ci int32_t ret = env_->GetDragManager().GetDragSummary(summaries); 442f857971dSopenharmony_ci if (ret != RET_OK) { 443f857971dSopenharmony_ci FI_HILOGE("IDragManager::GetDragSummary fail, error:%{public}d", ret); 444f857971dSopenharmony_ci return ret; 445f857971dSopenharmony_ci } 446f857971dSopenharmony_ci GetDragSummaryReply summaryReply { std::move(summaries) }; 447f857971dSopenharmony_ci 448f857971dSopenharmony_ci if (!summaryReply.Marshalling(reply)) { 449f857971dSopenharmony_ci FI_HILOGE("GetDragSummaryReply::Marshalling fail"); 450f857971dSopenharmony_ci return RET_ERR; 451f857971dSopenharmony_ci } 452f857971dSopenharmony_ci return RET_OK; 453f857971dSopenharmony_ci} 454f857971dSopenharmony_ci 455f857971dSopenharmony_ciint32_t DragServer::GetDragAction(CallingContext &context, MessageParcel &data, MessageParcel &reply) 456f857971dSopenharmony_ci{ 457f857971dSopenharmony_ci DragAction dragAction {}; 458f857971dSopenharmony_ci 459f857971dSopenharmony_ci int32_t ret = env_->GetDragManager().GetDragAction(dragAction); 460f857971dSopenharmony_ci if (ret != RET_OK) { 461f857971dSopenharmony_ci FI_HILOGE("IDragManager::GetDragSummary fail, error:%{public}d", ret); 462f857971dSopenharmony_ci return ret; 463f857971dSopenharmony_ci } 464f857971dSopenharmony_ci GetDragActionReply dragActionReply { dragAction }; 465f857971dSopenharmony_ci 466f857971dSopenharmony_ci if (!dragActionReply.Marshalling(reply)) { 467f857971dSopenharmony_ci FI_HILOGE("GetDragActionReply::Marshalling fail"); 468f857971dSopenharmony_ci return RET_ERR; 469f857971dSopenharmony_ci } 470f857971dSopenharmony_ci return RET_OK; 471f857971dSopenharmony_ci} 472f857971dSopenharmony_ci 473f857971dSopenharmony_ciint32_t DragServer::GetExtraInfo(CallingContext &context, MessageParcel &data, MessageParcel &reply) 474f857971dSopenharmony_ci{ 475f857971dSopenharmony_ci std::string extraInfo; 476f857971dSopenharmony_ci 477f857971dSopenharmony_ci int32_t ret = env_->GetDragManager().GetExtraInfo(extraInfo); 478f857971dSopenharmony_ci if (ret != RET_OK) { 479f857971dSopenharmony_ci FI_HILOGE("IDragManager::GetExtraInfo fail, error:%{public}d", ret); 480f857971dSopenharmony_ci return ret; 481f857971dSopenharmony_ci } 482f857971dSopenharmony_ci GetExtraInfoReply extraInfoReply { std::move(extraInfo) }; 483f857971dSopenharmony_ci 484f857971dSopenharmony_ci if (!extraInfoReply.Marshalling(reply)) { 485f857971dSopenharmony_ci FI_HILOGE("GetExtraInfoReply::Marshalling fail"); 486f857971dSopenharmony_ci return RET_ERR; 487f857971dSopenharmony_ci } 488f857971dSopenharmony_ci return RET_OK; 489f857971dSopenharmony_ci} 490f857971dSopenharmony_ci 491f857971dSopenharmony_ciint32_t DragServer::EnterTextEditorArea(CallingContext &context, MessageParcel &data, MessageParcel &reply) 492f857971dSopenharmony_ci{ 493f857971dSopenharmony_ci EnterTextEditorAreaParam param {}; 494f857971dSopenharmony_ci 495f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 496f857971dSopenharmony_ci FI_HILOGE("EnterTextEditorAreaParam::Unmarshalling fail"); 497f857971dSopenharmony_ci return RET_ERR; 498f857971dSopenharmony_ci } 499f857971dSopenharmony_ci return env_->GetDragManager().EnterTextEditorArea(param.state); 500f857971dSopenharmony_ci} 501f857971dSopenharmony_ci 502f857971dSopenharmony_ciint32_t DragServer::SetMouseDragMonitorState(CallingContext &context, MessageParcel &data, MessageParcel &reply) 503f857971dSopenharmony_ci{ 504f857971dSopenharmony_ci SetMouseDragMonitorStateParam param {}; 505f857971dSopenharmony_ci 506f857971dSopenharmony_ci if (!param.Unmarshalling(data)) { 507f857971dSopenharmony_ci FI_HILOGE("SetMouseDragMonitorStateParam::Unmarshalling fail"); 508f857971dSopenharmony_ci return RET_ERR; 509f857971dSopenharmony_ci } 510f857971dSopenharmony_ci return env_->GetDragManager().SetMouseDragMonitorState(param.state); 511f857971dSopenharmony_ci} 512f857971dSopenharmony_ci 513f857971dSopenharmony_cistd::string DragServer::GetPackageName(Security::AccessToken::AccessTokenID tokenId) 514f857971dSopenharmony_ci{ 515f857971dSopenharmony_ci std::string packageName = std::string(); 516f857971dSopenharmony_ci int32_t tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); 517f857971dSopenharmony_ci switch (tokenType) { 518f857971dSopenharmony_ci case Security::AccessToken::ATokenTypeEnum::TOKEN_HAP: { 519f857971dSopenharmony_ci Security::AccessToken::HapTokenInfo hapInfo; 520f857971dSopenharmony_ci if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, hapInfo) != 0) { 521f857971dSopenharmony_ci FI_HILOGE("Get hap token info failed"); 522f857971dSopenharmony_ci } else { 523f857971dSopenharmony_ci packageName = hapInfo.bundleName; 524f857971dSopenharmony_ci } 525f857971dSopenharmony_ci break; 526f857971dSopenharmony_ci } 527f857971dSopenharmony_ci case Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE: 528f857971dSopenharmony_ci case Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL: { 529f857971dSopenharmony_ci Security::AccessToken::NativeTokenInfo tokenInfo; 530f857971dSopenharmony_ci if (Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(tokenId, tokenInfo) != 0) { 531f857971dSopenharmony_ci FI_HILOGE("Get native token info failed"); 532f857971dSopenharmony_ci } else { 533f857971dSopenharmony_ci packageName = tokenInfo.processName; 534f857971dSopenharmony_ci } 535f857971dSopenharmony_ci break; 536f857971dSopenharmony_ci } 537f857971dSopenharmony_ci default: { 538f857971dSopenharmony_ci FI_HILOGW("token type not match"); 539f857971dSopenharmony_ci break; 540f857971dSopenharmony_ci } 541f857971dSopenharmony_ci } 542f857971dSopenharmony_ci return packageName; 543f857971dSopenharmony_ci} 544f857971dSopenharmony_ci 545f857971dSopenharmony_cibool DragServer::IsSystemServiceCalling(CallingContext &context) 546f857971dSopenharmony_ci{ 547f857971dSopenharmony_ci auto flag = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(context.tokenId); 548f857971dSopenharmony_ci if ((flag == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) || 549f857971dSopenharmony_ci (flag == Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)) { 550f857971dSopenharmony_ci FI_HILOGI("system service calling, flag:%{public}u", flag); 551f857971dSopenharmony_ci return true; 552f857971dSopenharmony_ci } 553f857971dSopenharmony_ci return false; 554f857971dSopenharmony_ci} 555f857971dSopenharmony_ci 556f857971dSopenharmony_cibool DragServer::IsSystemHAPCalling(CallingContext &context) 557f857971dSopenharmony_ci{ 558f857971dSopenharmony_ci if (IsSystemServiceCalling(context)) { 559f857971dSopenharmony_ci return true; 560f857971dSopenharmony_ci } 561f857971dSopenharmony_ci return Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(context.fullTokenId); 562f857971dSopenharmony_ci} 563f857971dSopenharmony_ci} // namespace DeviceStatus 564f857971dSopenharmony_ci} // namespace Msdp 565f857971dSopenharmony_ci} // namespace OHOS