1 /*
2 * Copyright (c) 2022 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 "camera_manager_privacy_proxy.h"
17 #include "accesstoken_log.h"
18
19 namespace OHOS {
20 namespace Security {
21 namespace AccessToken {
22 namespace {
23 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PRIVACY, "CameraManagerPrivacyProxy"};
24 static constexpr int32_t ERROR = -1;
25 }
26
MuteCameraPersist(PolicyType policyType,bool muteMode)27 int32_t CameraManagerPrivacyProxy::MuteCameraPersist(PolicyType policyType, bool muteMode)
28 {
29 MessageParcel data;
30 MessageParcel reply;
31 MessageOption option;
32 if (!data.WriteInterfaceToken(GetDescriptor())) {
33 ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write descriptor");
34 return ERROR;
35 }
36 if (!data.WriteInt32(static_cast<int32_t>(policyType))) {
37 ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write bool");
38 return ERROR;
39 }
40 if (!data.WriteBool(muteMode)) {
41 ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write bool");
42 return ERROR;
43 }
44 sptr<IRemoteObject> remote = Remote();
45 if (remote == nullptr) {
46 ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null.");
47 return ERROR;
48 }
49 int32_t error = remote->SendRequest(
50 static_cast<uint32_t>(CAMERA_SERVICE_MUTE_CAMERA_PERSIST), data, reply, option);
51 if (error != ERR_NONE) {
52 ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, error: %{public}d", error);
53 }
54 return error;
55 }
56
IsCameraMuted(bool & muteMode)57 int32_t CameraManagerPrivacyProxy::IsCameraMuted(bool &muteMode)
58 {
59 MessageParcel data;
60 MessageParcel reply;
61 MessageOption option;
62 if (!data.WriteInterfaceToken(GetDescriptor())) {
63 ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write descriptor");
64 return ERROR;
65 }
66 if (!data.WriteBool(muteMode)) {
67 ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write bool");
68 return ERROR;
69 }
70 sptr<IRemoteObject> remote = Remote();
71 if (remote == nullptr) {
72 ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null.");
73 return ERROR;
74 }
75 int32_t error = remote->SendRequest(static_cast<uint32_t>(CAMERA_SERVICE_IS_CAMERA_MUTED), data, reply, option);
76 if (error != ERR_NONE) {
77 ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, error: %{public}d", error);
78 return ERROR;
79 }
80 muteMode = reply.ReadBool();
81 ACCESSTOKEN_LOG_DEBUG(LABEL, "IsCameraMuted Read muteMode is %{public}d", muteMode);
82 return error;
83 }
84 } // namespace AccessToken
85 } // namespace Security
86 } // namespace OHOS
87