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 
21 namespace OHOS {
22 namespace Rosen {
23 namespace {
24 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SnapshotStub"};
25 }
26 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int32_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             AAFwk::Snapshot snapshot_;
38             sptr<IRemoteObject> abilityObject = data.ReadRemoteObject();
39             int32_t ret = GetSnapshot(abilityObject, snapshot_);
40             if (snapshot_.GetPixelMap() == nullptr) {
41                 reply.WriteParcelable(nullptr);
42                 reply.WriteInt32(static_cast<int32_t>(WMError::WM_ERROR_NULLPTR));
43                 break;
44             }
45             reply.WriteParcelable(snapshot_.GetPixelMap().get());
46             reply.WriteInt32(ret);
47             break;
48         }
49         default:
50             WLOGFW("unknown transaction code");
51             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
52     }
53     return ERR_NONE;
54 }
55 }
56 }
57