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