• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "privacy_scene_session_manager_proxy.h"
17 
18 #include "accesstoken_common_log.h"
19 #include "privacy_error.h"
20 
21 namespace OHOS {
22 namespace Security {
23 namespace AccessToken {
24 
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)25 int32_t PrivacySceneSessionManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
26     const sptr<IWindowManagerAgent>& windowManagerAgent)
27 {
28     MessageOption option;
29     MessageParcel reply;
30     MessageParcel data;
31     if (!data.WriteInterfaceToken(GetDescriptor())) {
32         LOGE(PRI_DOMAIN, PRI_TAG, "Write InterfaceToken failed");
33         return ERR_WRITE_PARCEL_FAILED;
34     }
35 
36     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
37         LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed");
38         return ERR_WRITE_PARCEL_FAILED;
39     }
40 
41     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
42         LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed");
43         return ERR_WRITE_PARCEL_FAILED;
44     }
45 
46     int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
47         SceneSessionManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
48         data, reply, option);
49     if (error != ERR_NONE) {
50         LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, err=%{public}d.", error);
51         return error;
52     }
53 
54     return reply.ReadInt32();
55 }
56 
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)57 int32_t PrivacySceneSessionManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
58     const sptr<IWindowManagerAgent>& windowManagerAgent)
59 {
60     MessageParcel reply;
61     MessageOption option;
62     MessageParcel data;
63     if (!data.WriteInterfaceToken(GetDescriptor())) {
64         LOGE(PRI_DOMAIN, PRI_TAG, "Write InterfaceToken failed");
65         return ERR_WRITE_PARCEL_FAILED;
66     }
67 
68     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
69         LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed");
70         return ERR_WRITE_PARCEL_FAILED;
71     }
72 
73     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
74         LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed");
75         return ERR_WRITE_PARCEL_FAILED;
76     }
77 
78     int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
79         SceneSessionManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
80         data, reply, option);
81     if (error != ERR_NONE) {
82         LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, err=%{public}d.", error);
83         return error;
84     }
85 
86     return reply.ReadInt32();
87 }
88 }
89 }
90 }