1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #define LOG_TAG "AudioPowerPolicyClient" 18 19 #include "PowerPolicyClient.h" 20 #include "AudioControl.h" 21 22 #include <android-base/logging.h> 23 24 namespace aidl { 25 namespace android { 26 namespace hardware { 27 namespace automotive { 28 namespace audiocontrol { 29 30 namespace aafap = ::aidl::android::frameworks::automotive::powerpolicy; 31 32 using aafap::CarPowerPolicy; 33 using aafap::CarPowerPolicyFilter; 34 using aafap::PowerComponent; 35 using ::android::frameworks::automotive::powerpolicy::hasComponent; 36 using ::ndk::ScopedAStatus; 37 38 namespace { 39 40 constexpr PowerComponent kAudioComponent = PowerComponent::AUDIO; 41 42 } // namespace 43 PowerPolicyClient(const std::shared_ptr<AudioControl> & audioControl)44PowerPolicyClient::PowerPolicyClient(const std::shared_ptr<AudioControl>& audioControl) 45 : mAudioControl(audioControl) {} 46 onInitFailed()47void PowerPolicyClient::onInitFailed() { 48 LOG(ERROR) << "Initializing power policy client failed"; 49 } 50 getComponentsOfInterest()51std::vector<PowerComponent> PowerPolicyClient::getComponentsOfInterest() { 52 std::vector<PowerComponent> components{kAudioComponent}; 53 return components; 54 } 55 onPolicyChanged(const CarPowerPolicy & powerPolicy)56ScopedAStatus PowerPolicyClient::onPolicyChanged(const CarPowerPolicy& powerPolicy) { 57 if (hasComponent(powerPolicy.enabledComponents, kAudioComponent)) { 58 mAudioControl->setAudioEnabled(true); 59 } else if (hasComponent(powerPolicy.disabledComponents, kAudioComponent)) { 60 mAudioControl->setAudioEnabled(false); 61 } 62 63 return ScopedAStatus::ok(); 64 } 65 66 } // namespace audiocontrol 67 } // namespace automotive 68 } // namespace hardware 69 } // namespace android 70 } // namespace aidl 71