1 /*
2 * Copyright (c) 2021 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 "snapshot_proxy.h"
17 #include "ipc_types.h"
18 #include "pixel_map.h"
19 #include "window_manager_hilog.h"
20
21 namespace OHOS {
22 namespace Rosen {
23 namespace {
24 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SnapshotProxy"};
25 }
26
GetSnapshot(const sptr<IRemoteObject> & token,AAFwk::Snapshot & snapshot)27 int32_t SnapshotProxy::GetSnapshot(const sptr<IRemoteObject>& token, AAFwk::Snapshot& snapshot)
28 {
29 MessageParcel data;
30 MessageParcel reply;
31 MessageOption option;
32
33 if (!data.WriteInterfaceToken(GetDescriptor())) {
34 WLOGFE("WriteInterfaceToken failed");
35 return static_cast<int32_t>(WMError::WM_ERROR_IPC_FAILED);
36 }
37
38 if (!data.WriteRemoteObject(token)) {
39 WLOGFE("Write ability token failed");
40 return static_cast<int32_t>(WMError::WM_ERROR_IPC_FAILED);
41 }
42
43 sptr<IRemoteObject> remote = Remote();
44 if (remote == nullptr) {
45 WLOGFE("remote is null");
46 return static_cast<int32_t>(WMError::WM_ERROR_IPC_FAILED);
47 }
48 if (remote->SendRequest(TRANS_ID_GET_SNAPSHOT, data, reply, option) != ERR_NONE) {
49 return static_cast<int32_t>(WMError::WM_ERROR_IPC_FAILED);
50 }
51
52 std::shared_ptr<Media::PixelMap> pixelMap(reply.ReadParcelable<Media::PixelMap>());
53 snapshot.SetPixelMap(pixelMap);
54 return reply.ReadInt32();
55 }
56 }
57 }