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_stub.h"
17#include <ipc_skeleton.h>
18#include "window_manager_hilog.h"
19#include "wm_common.h"
20
21namespace OHOS {
22namespace Rosen {
23namespace {
24constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SnapshotStub"};
25}
26
27int32_t SnapshotStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
28    MessageOption& option)
29{
30    WLOGI("SnapshotStub::OnRemoteRequest code is %{public}u", code);
31    if (data.ReadInterfaceToken() != GetDescriptor()) {
32        WLOGFE("InterfaceToken check failed!");
33        return ERR_TRANSACTION_FAILED;
34    }
35    switch (code) {
36        case TRANS_ID_GET_SNAPSHOT : {
37            sptr<IRemoteObject> abilityObject = data.ReadRemoteObject();
38            if (abilityObject == nullptr) {
39                TLOGE(WmsLogTag::DEFAULT, "Read remote object error");
40                return ERR_INVALID_DATA;
41            }
42            AAFwk::Snapshot snapshot;
43            int32_t ret = GetSnapshot(abilityObject, snapshot);
44            if (snapshot.GetPixelMap() == nullptr) {
45                reply.WriteParcelable(nullptr);
46                reply.WriteInt32(static_cast<int32_t>(WMError::WM_ERROR_NULLPTR));
47                break;
48            }
49            reply.WriteParcelable(snapshot.GetPixelMap().get());
50            reply.WriteInt32(ret);
51            break;
52        }
53        default:
54            WLOGFW("unknown transaction code");
55            return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56    }
57    return ERR_NONE;
58}
59}
60}
61