• 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 "audio_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, "AudioManagerPrivacyProxy"};
24 static constexpr int32_t ERROR = -1;
25 }
26 
IsMicrophoneMute()27 bool AudioManagerPrivacyProxy::IsMicrophoneMute()
28 {
29     MessageParcel data;
30     MessageParcel reply;
31     MessageOption option;
32     if (!data.WriteInterfaceToken(GetDescriptor())) {
33         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed");
34         return false;
35     }
36     int32_t error = Remote()->SendRequest(AudioPolicyCommand::IS_MICROPHONE_MUTE, data, reply, option);
37     if (error != ERR_NONE) {
38         ACCESSTOKEN_LOG_ERROR(LABEL, "IsMicrophoneMute failed, error: %{public}d", error);
39         return false;
40     }
41     return reply.ReadBool();
42 }
43 
SetMicrophoneMute(bool isMute)44 int32_t AudioManagerPrivacyProxy::SetMicrophoneMute(bool isMute)
45 {
46     MessageParcel data;
47     MessageParcel reply;
48     MessageOption option;
49     if (!data.WriteInterfaceToken(GetDescriptor())) {
50         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed");
51         return ERROR;
52     }
53     data.WriteBool(isMute);
54     int32_t error = Remote()->SendRequest(AudioPolicyCommand::SET_MICROPHONE_MUTE, data, reply, option);
55     if (error != ERR_NONE) {
56         ACCESSTOKEN_LOG_ERROR(LABEL, "set microphoneMute failed, error: %d", error);
57         return error;
58     }
59     return reply.ReadInt32();
60 }
61 
SetMicStateChangeCallback(const int32_t clientId,const sptr<IRemoteObject> & object)62 int32_t AudioManagerPrivacyProxy::SetMicStateChangeCallback(const int32_t clientId, const sptr<IRemoteObject> &object)
63 {
64     MessageParcel data;
65     MessageParcel reply;
66     MessageOption option;
67     if (!data.WriteInterfaceToken(GetDescriptor())) {
68         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed");
69         return ERROR;
70     }
71     data.WriteInt32(clientId);
72     (void)data.WriteRemoteObject(object);
73     int error = Remote()->SendRequest(AudioPolicyCommand::SET_MIC_STATE_CHANGE_CALLBACK, data, reply, option);
74     if (error != ERR_NONE) {
75         ACCESSTOKEN_LOG_ERROR(LABEL, "SetMicStateChangeCallback failed, error: %{public}d", error);
76         return error;
77     }
78     return reply.ReadInt32();
79 }
80 } // namespace AccessToken
81 } // namespace Security
82 } // namespace OHOS
83