From f269b8e0e9ab950fc6652b9594b7a3431c81630c Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Mon, 9 Jun 2014 20:01:29 -0700 Subject: [PATCH] audio policy: use factory to create audio policy manager Use the class factory to create the audio policy mamager instead of AudioPolicyManager class constructor and use a pointer to an AudioPolicyInterface. Change-Id: Ibb5a8eee5d597db67cf13f279c909181cfee9949 --- CleanSpec.mk | 4 ++++ services/audiopolicy/Android.mk | 16 ++++++++++++++- services/audiopolicy/AudioPolicyFactory.cpp | 32 +++++++++++++++++++++++++++++ services/audiopolicy/AudioPolicyService.cpp | 4 ++-- services/audiopolicy/AudioPolicyService.h | 2 +- 5 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 services/audiopolicy/AudioPolicyFactory.cpp diff --git a/CleanSpec.mk b/CleanSpec.mk index 20da9255fc..d0890fed82 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk @@ -55,6 +55,10 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libaudiopolicy $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/libaudiopolicy.so) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libaudiopolicyservice_intermediates) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libaudiopolicymanager_intermediates) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/libaudiopolicyservice.so) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/libaudiopolicymanager.so) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libaudiopolicyservice_intermediates) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libaudiopolicymanager_intermediates) # ************************************************ # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST diff --git a/services/audiopolicy/Android.mk b/services/audiopolicy/Android.mk index a22ad9d4dc..cddc503a2f 100644 --- a/services/audiopolicy/Android.mk +++ b/services/audiopolicy/Android.mk @@ -46,8 +46,8 @@ LOCAL_CFLAGS += -fvisibility=hidden include $(BUILD_SHARED_LIBRARY) + ifneq ($(USE_LEGACY_AUDIO_POLICY), 1) -ifneq ($(USE_CUSTOM_AUDIO_POLICY), 1) include $(CLEAR_VARS) @@ -62,6 +62,20 @@ LOCAL_SHARED_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \ libmedia_helper +LOCAL_MODULE:= libaudiopolicymanagerdefault + +include $(BUILD_SHARED_LIBRARY) + +ifneq ($(USE_CUSTOM_AUDIO_POLICY), 1) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + AudioPolicyFactory.cpp + +LOCAL_SHARED_LIBRARIES := \ + libaudiopolicymanagerdefault + LOCAL_MODULE:= libaudiopolicymanager include $(BUILD_SHARED_LIBRARY) diff --git a/services/audiopolicy/AudioPolicyFactory.cpp b/services/audiopolicy/AudioPolicyFactory.cpp new file mode 100644 index 0000000000..2ae7bc1b95 --- /dev/null +++ b/services/audiopolicy/AudioPolicyFactory.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AudioPolicyManager.h" + +namespace android { + +extern "C" AudioPolicyInterface* createAudioPolicyManager( + AudioPolicyClientInterface *clientInterface) +{ + return new AudioPolicyManager(clientInterface); +} + +extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface) +{ + delete interface; +} + +}; // namespace android diff --git a/services/audiopolicy/AudioPolicyService.cpp b/services/audiopolicy/AudioPolicyService.cpp index a2a0461b8a..cd4fb3376f 100644 --- a/services/audiopolicy/AudioPolicyService.cpp +++ b/services/audiopolicy/AudioPolicyService.cpp @@ -108,7 +108,7 @@ AudioPolicyService::AudioPolicyService() ALOGI("AudioPolicyService CSTOR in new mode"); mAudioPolicyClient = new AudioPolicyClient(this); - mAudioPolicyManager = new AudioPolicyManager(mAudioPolicyClient); + mAudioPolicyManager = createAudioPolicyManager(mAudioPolicyClient); #endif // load audio pre processing modules @@ -145,7 +145,7 @@ AudioPolicyService::~AudioPolicyService() audio_policy_dev_close(mpAudioPolicyDev); } #else - delete mAudioPolicyManager; + destroyAudioPolicyManager(mAudioPolicyManager); delete mAudioPolicyClient; #endif diff --git a/services/audiopolicy/AudioPolicyService.h b/services/audiopolicy/AudioPolicyService.h index 40f589b1e9..66d9cad02c 100644 --- a/services/audiopolicy/AudioPolicyService.h +++ b/services/audiopolicy/AudioPolicyService.h @@ -539,7 +539,7 @@ private: sp mOutputCommandThread; // process stop and release output struct audio_policy_device *mpAudioPolicyDev; struct audio_policy *mpAudioPolicy; - AudioPolicyManager *mAudioPolicyManager; + AudioPolicyInterface *mAudioPolicyManager; AudioPolicyClient *mAudioPolicyClient; KeyedVector< audio_source_t, InputSourceDesc* > mInputSources; -- 2.11.0