1 /*
2  * Copyright (c) 2023 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 "zidl/session_manager_service_recover_proxy.h"
17 #include "window_manager_hilog.h"
18 
19 namespace OHOS {
20 namespace Rosen {
21 namespace {
22 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionManagerServiceRecoverProxy"};
23 }
24 
OnSessionManagerServiceRecover(const sptr<IRemoteObject> & sessionManagerService)25 void SessionManagerServiceRecoverProxy::OnSessionManagerServiceRecover(
26     const sptr<IRemoteObject>& sessionManagerService)
27 {
28     MessageParcel data;
29     MessageParcel reply;
30     MessageOption option = { MessageOption::TF_ASYNC };
31     if (!data.WriteInterfaceToken(GetDescriptor())) {
32         TLOGE(WmsLogTag::WMS_RECOVER, "WriteInterfaceToken failed");
33         return;
34     }
35 
36     if (!data.WriteRemoteObject(sessionManagerService)) {
37         TLOGE(WmsLogTag::WMS_RECOVER, "WriteRemoteObject failed");
38         return;
39     }
40 
41     sptr<IRemoteObject> remote = Remote();
42     if (remote == nullptr) {
43         TLOGE(WmsLogTag::WMS_RECOVER, "remote is null");
44         return;
45     }
46     if (remote->SendRequest(static_cast<uint32_t>(
47         SessionManagerServiceRecoverMessage::TRANS_ID_ON_SESSION_MANAGER_SERVICE_RECOVER),
48         data, reply, option) != ERR_NONE) {
49         TLOGE(WmsLogTag::WMS_RECOVER, "SendRequest failed");
50         return;
51     }
52 }
53 
OnWMSConnectionChanged(int32_t userId,int32_t screenId,bool isConnected,const sptr<IRemoteObject> & sessionManagerService)54 void SessionManagerServiceRecoverProxy::OnWMSConnectionChanged(
55     int32_t userId, int32_t screenId, bool isConnected, const sptr<IRemoteObject>& sessionManagerService)
56 {
57     MessageParcel data;
58     MessageParcel reply;
59     MessageOption option = { MessageOption::TF_ASYNC };
60     if (!data.WriteInterfaceToken(GetDescriptor())) {
61         WLOGFE("WriteInterfaceToken failed");
62         return;
63     }
64     if (!data.WriteInt32(userId)) {
65         WLOGFE("Write userId failed");
66         return;
67     }
68     if (!data.WriteInt32(screenId)) {
69         WLOGFE("Write screenId failed");
70         return;
71     }
72     if (!data.WriteBool(isConnected)) {
73         WLOGFE("Write isConnected failed");
74         return;
75     }
76 
77     if (isConnected && !data.WriteRemoteObject(sessionManagerService)) {
78         WLOGFE("WriteRemoteObject failed");
79         return;
80     }
81 
82     sptr<IRemoteObject> remote = Remote();
83     if (remote == nullptr) {
84         WLOGFE("remote is null");
85         return;
86     }
87     if (remote->SendRequest(static_cast<uint32_t>(
88         SessionManagerServiceRecoverMessage::TRANS_ID_ON_WMS_CONNECTION_CHANGED), data, reply,
89         option) != ERR_NONE) {
90         WLOGFE("SendRequest failed");
91         return;
92     }
93 }
94 } // namespace Rosen
95 } // namespace OHOS