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_session_manager_proxy.h"
17 
18 #include "accesstoken_log.h"
19 
20 namespace OHOS {
21 namespace Security {
22 namespace AccessToken {
23 namespace {
24 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacySessionManagerProxy" };
25 }
26 
GetSceneSessionManager()27 sptr<IRemoteObject> PrivacySessionManagerProxy::GetSceneSessionManager()
28 {
29     MessageParcel data;
30     MessageParcel reply;
31     MessageOption option(MessageOption::TF_SYNC);
32 
33     if (!data.WriteInterfaceToken(GetDescriptor())) {
34         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed");
35         return nullptr;
36     }
37 
38     sptr<IRemoteObject> remote = Remote();
39     if (remote == nullptr) {
40         ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null.");
41         return nullptr;
42     }
43     auto ret = remote->SendRequest(
44         static_cast<uint32_t>(SessionManagerServiceMessage::TRANS_ID_GET_SCENE_SESSION_MANAGER),
45         data, reply, option);
46     if (ret != ERR_NONE) {
47         ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, errorCode %{public}d", ret);
48         return nullptr;
49     }
50 
51     return reply.ReadRemoteObject();
52 }
53 
GetSceneSessionManagerLite()54 sptr<IRemoteObject> PrivacySessionManagerProxy::GetSceneSessionManagerLite()
55 {
56     MessageParcel data;
57     MessageParcel reply;
58     MessageOption option(MessageOption::TF_SYNC);
59 
60     if (!data.WriteInterfaceToken(GetDescriptor())) {
61         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed");
62         return nullptr;
63     }
64 
65     sptr<IRemoteObject> remote = Remote();
66     if (remote == nullptr) {
67         ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null.");
68         return nullptr;
69     }
70     auto ret = remote->SendRequest(
71         static_cast<uint32_t>(SessionManagerServiceMessage::TRANS_ID_GET_SCENE_SESSION_MANAGER_LITE),
72         data, reply, option);
73     if (ret != ERR_NONE) {
74         ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, errorCode %{public}d", ret);
75         return nullptr;
76     }
77 
78     return reply.ReadRemoteObject();
79 }
80 }
81 }
82 }