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_global_switch_change_stub.h"
17 #include "accesstoken_log.h"
18 #include "permission_record_manager.h"
19 #include "privacy_error.h"
20
21 namespace OHOS {
22 namespace Security {
23 namespace AccessToken {
24 namespace {
25 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE,
26 SECURITY_DOMAIN_ACCESSTOKEN, "AudioRoutingManagerListenerStub"};
27
28 static constexpr uint32_t UPDATE_CALLBACK_CLIENT = 0;
29 static constexpr int32_t ON_MIC_STATE_UPDATED = 6; // audio_policy_client.h | ON_MIC_STATE_UPDATED
30 }
AudioRoutingManagerListenerStub()31 AudioRoutingManagerListenerStub::AudioRoutingManagerListenerStub()
32 {
33 ACCESSTOKEN_LOG_INFO(LABEL, "AudioRoutingManagerListenerStub Instance create");
34 }
35
~AudioRoutingManagerListenerStub()36 AudioRoutingManagerListenerStub::~AudioRoutingManagerListenerStub()
37 {
38 ACCESSTOKEN_LOG_INFO(LABEL, "AudioRoutingManagerListenerStub Instance destroy");
39 }
40
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)41 int AudioRoutingManagerListenerStub::OnRemoteRequest(
42 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
43 {
44 if (data.ReadInterfaceToken() != GetDescriptor()) {
45 ACCESSTOKEN_LOG_INFO(LABEL, "AudioRoutingManagerListenerStub: ReadInterfaceToken failed");
46 return ERROR_IPC_REQUEST_FAIL;
47 }
48 switch (code) {
49 case UPDATE_CALLBACK_CLIENT: {
50 MicStateChangeEvent micStateChangeEvent = {};
51
52 int32_t clientCode = data.ReadInt32();
53 if (clientCode != ON_MIC_STATE_UPDATED) {
54 return NO_ERROR;
55 }
56
57 ACCESSTOKEN_LOG_INFO(LABEL, "Only handle ClientCode 6-ON_MIC_STATE_UPDATED, others ignore.");
58
59 micStateChangeEvent.mute = data.ReadBool();
60 OnMicStateUpdated(micStateChangeEvent);
61 return NO_ERROR;
62 }
63 default: {
64 ACCESSTOKEN_LOG_INFO(LABEL, "default case, need check AudioListenerStub");
65 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
66 }
67 }
68 return NO_ERROR;
69 }
70
OnMicStateUpdated(const MicStateChangeEvent & micStateChangeEvent)71 void AudioRoutingManagerListenerStub::OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent)
72 {
73 ACCESSTOKEN_LOG_INFO(LABEL, "OnMicMute(%{public}d)", micStateChangeEvent.mute);
74 PermissionRecordManager::GetInstance().NotifyMicChange(micStateChangeEvent.mute);
75 }
76 }
77 } // namespace AccessToken
78 } // namespace OHOS
79