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