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 #include "privacy_window_manager_agent.h"
16 #include "accesstoken_log.h"
17 #include "privacy_error.h"
18
19 namespace OHOS {
20 namespace Security {
21 namespace AccessToken {
22 namespace {
23 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
24 LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyWindowManagerAgent"
25 };
26 }
27
PrivacyWindowManagerAgent(WindowChangeCallback callback)28 PrivacyWindowManagerAgent::PrivacyWindowManagerAgent(WindowChangeCallback callback)
29 {
30 callback_ = callback;
31 }
32
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int PrivacyWindowManagerAgent::OnRemoteRequest(uint32_t code, MessageParcel& data,
34 MessageParcel& reply, MessageOption& option)
35 {
36 ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called, code: %{public}u", __func__, code);
37 if (data.ReadInterfaceToken() != IWindowManagerAgent::GetDescriptor()) {
38 ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called, read desciptor error", __func__);
39 return ERROR_IPC_REQUEST_FAIL;
40 }
41 PrivacyWindowServiceInterfaceCode msgId = static_cast<PrivacyWindowServiceInterfaceCode>(code);
42 switch (msgId) {
43 case PrivacyWindowServiceInterfaceCode::TRANS_ID_UPDATE_CAMERA_FLOAT: {
44 uint32_t accessTokenId = data.ReadUint32();
45 bool isShowing = data.ReadBool();
46 UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
47 break;
48 }
49 case PrivacyWindowServiceInterfaceCode::TRANS_ID_UPDATE_CAMERA_WINDOW_STATUS: {
50 uint32_t accessTokenId = data.ReadUint32();
51 bool isShowing = data.ReadBool();
52 UpdateCameraWindowStatus(accessTokenId, isShowing);
53 break;
54 }
55 default:
56 break;
57 }
58 return 0;
59 }
60
UpdateCameraFloatWindowStatus(uint32_t accessTokenId,bool isShowing)61 void PrivacyWindowManagerAgent::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing)
62 {
63 ACCESSTOKEN_LOG_INFO(LABEL, "OnChange(tokenId=%{public}d, isShow=%{public}d)", accessTokenId, isShowing);
64 callback_(accessTokenId, isShowing);
65 }
66
UpdateCameraWindowStatus(uint32_t accessTokenId,bool isShowing)67 void PrivacyWindowManagerAgent::UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing)
68 {
69 ACCESSTOKEN_LOG_INFO(LABEL, "OnChange(tokenId=%{public}d, isShow=%{public}d)", accessTokenId, isShowing);
70 callback_(accessTokenId, isShowing);
71 }
72 } // namespace AccessToken
73 } // namespace Security
74 } // namespace OHOS
75
76