• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "boomerang_callback_stub.h"
17 
18 #include <message_parcel.h>
19 
20 #include "devicestatus_common.h"
21 #include "devicestatus_define.h"
22 
23 #undef LOG_TAG
24 #define LOG_TAG "BoomerangCallbackStub"
25 
26 namespace OHOS {
27 namespace Msdp {
28 namespace DeviceStatus {
29 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int32_t BoomerangCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
31     MessageOption &option)
32 {
33     FI_HILOGD("cmd:%{public}u, flags:%{public}d", code, option.GetFlags());
34     std::u16string descripter = BoomerangCallbackStub::GetDescriptor();
35     std::u16string remoteDescripter = data.ReadInterfaceToken();
36     if (descripter != remoteDescripter) {
37         FI_HILOGE("BoomerangCallbackStub::OnRemoteRequest failed, descriptor mismatch");
38         return E_DEVICESTATUS_GET_SERVICE_FAILED;
39     }
40 
41     switch (code) {
42         case static_cast<int32_t>(IRemoteBoomerangCallback::SCREENSHOT): {
43             return OnScreenshotStub(data);
44         }
45         case static_cast<int32_t>(IRemoteBoomerangCallback::NOTIFY_METADATA): {
46             return OnNotifyMetadataStub(data);
47         }
48         case static_cast<int32_t>(IRemoteBoomerangCallback::ENCODE_IMAGE): {
49             return OnEncodeImageStub(data);
50         }
51         default:
52             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
53     }
54     return RET_OK;
55 }
56 
OnScreenshotStub(MessageParcel & data)57 int32_t BoomerangCallbackStub::OnScreenshotStub(MessageParcel &data)
58 {
59     CALL_DEBUG_ENTER;
60     int32_t type = 0;
61     int32_t status = 0;
62     READINT32(data, type, E_DEVICESTATUS_READ_PARCEL_ERROR);
63     READINT32(data, status, E_DEVICESTATUS_READ_PARCEL_ERROR);
64     BoomerangData boomerangData = {
65         static_cast<BoomerangType>(type),
66         static_cast<BoomerangStatus>(status)
67     };
68     OnScreenshotResult(boomerangData);
69     return RET_OK;
70 }
71 
OnEncodeImageStub(MessageParcel & data)72 int32_t BoomerangCallbackStub::OnEncodeImageStub(MessageParcel &data)
73 {
74     CALL_DEBUG_ENTER;
75     Media::PixelMap *rawPixelMap = OHOS::Media::PixelMap::Unmarshalling(data);
76     CHKPF(rawPixelMap);
77     std::shared_ptr<OHOS::Media::PixelMap> pixelMap = std::shared_ptr<Media::PixelMap>(rawPixelMap);
78     OnEncodeImageResult(pixelMap);
79     return RET_OK;
80 }
81 
OnNotifyMetadataStub(MessageParcel & data)82 int32_t BoomerangCallbackStub::OnNotifyMetadataStub(MessageParcel &data)
83 {
84     CALL_DEBUG_ENTER;
85     std::string metadata;
86     READSTRING(data, metadata, E_DEVICESTATUS_READ_PARCEL_ERROR);
87     OnNotifyMetadata(metadata);
88     return RET_OK;
89 }
90 } // namespace DeviceStatus
91 } // namespace Msdp
92 } // namespace OHOS
93