• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SetMuteCallback(const sptr<ICameraMuteServiceCallback> & callback)27 int32_t CameraManagerPrivacyProxy::SetMuteCallback(const sptr<ICameraMuteServiceCallback>& callback)
28 {
29     MessageParcel data;
30     MessageParcel reply;
31     MessageOption option;
32 
33     if (callback == nullptr) {
34         ACCESSTOKEN_LOG_ERROR(LABEL, "callback is null");
35         return ERROR;
36     }
37 
38     if (!data.WriteInterfaceToken(GetDescriptor())) {
39         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed");
40         return ERROR;
41     }
42     if (!data.WriteRemoteObject(callback->AsObject())) {
43         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteRemoteObject failed");
44         return ERROR;
45     }
46 
47     int32_t error = Remote()->SendRequest(static_cast<uint32_t>(CAMERA_SERVICE_SET_MUTE_CALLBACK), data, reply, option);
48     if (error != ERR_NONE) {
49         ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, error: %{public}d", error);
50     }
51     return error;
52 }
53 
MuteCamera(bool muteMode)54 int32_t CameraManagerPrivacyProxy::MuteCamera(bool muteMode)
55 {
56     MessageParcel data;
57     MessageParcel reply;
58     MessageOption option;
59     if (!data.WriteInterfaceToken(GetDescriptor())) {
60         ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write descriptor");
61         return ERROR;
62     }
63     if (!data.WriteBool(muteMode)) {
64         ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write bool");
65         return ERROR;
66     }
67     int32_t error = Remote()->SendRequest(static_cast<uint32_t>(CAMERA_SERVICE_MUTE_CAMERA), data, reply, option);
68     if (error != ERR_NONE) {
69         ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, error: %{public}d", error);
70         return ERROR;
71     }
72     error = reply.ReadInt32();
73     ACCESSTOKEN_LOG_DEBUG(LABEL, "MuteCamera Read muteMode is %{public}d", error);
74     return error;
75 }
76 
IsCameraMuted(bool & muteMode)77 int32_t CameraManagerPrivacyProxy::IsCameraMuted(bool &muteMode)
78 {
79     MessageParcel data;
80     MessageParcel reply;
81     MessageOption option;
82     if (!data.WriteInterfaceToken(GetDescriptor())) {
83         ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write descriptor");
84         return ERROR;
85     }
86     if (!data.WriteBool(muteMode)) {
87         ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write bool");
88         return ERROR;
89     }
90     int32_t error = Remote()->SendRequest(static_cast<uint32_t>(CAMERA_SERVICE_IS_CAMERA_MUTED), data, reply, option);
91     if (error != ERR_NONE) {
92         ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed, error: %{public}d", error);
93         return ERROR;
94     }
95     muteMode = reply.ReadBool();
96     ACCESSTOKEN_LOG_DEBUG(LABEL, "IsCameraMuted Read muteMode is %{public}d", muteMode);
97     return error;
98 }
99 } // namespace AccessToken
100 } // namespace Security
101 } // namespace OHOS
102