165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian/*
265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Copyright (C) 2009 The Android Open Source Project
365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian *
465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * you may not use this file except in compliance with the License.
665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * You may obtain a copy of the License at
765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian *
865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian *
1065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Unless required by applicable law or agreed to in writing, software
1165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
1265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * See the License for the specific language governing permissions and
1465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * limitations under the License.
1565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian */
1665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define LOG_TAG "AudioPolicyService"
1865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian//#define LOG_NDEBUG 0
1965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#undef __STRICT_ANSI__
2165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define __STDINT_LIMITS
2265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define __STDC_LIMIT_MACROS
2365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <stdint.h>
2465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <sys/time.h>
2665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <binder/IServiceManager.h>
2765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/Log.h>
2865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <cutils/properties.h>
2965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <binder/IPCThreadState.h>
3065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/String16.h>
3165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/threads.h>
3265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include "AudioPolicyService.h"
3344deb053252a3bd2f57a007ab9560f4924f62394Glenn Kasten#include "ServiceUtilities.h"
3465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <hardware_legacy/power.h>
357c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <media/AudioEffect.h>
367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <media/EffectsFactoryApi.h>
3765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
38fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin#include <hardware/hardware.h>
3964760240f931714858a59c1579f07264d7182ba2Dima Zavin#include <system/audio.h>
407394a4f358fa9908a9f0a7c954b65c399f4268e6Dima Zavin#include <system/audio_policy.h>
41fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin#include <hardware/audio_policy.h>
427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <audio_effects/audio_effects_conf.h>
43fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin
4465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopiannamespace android {
4565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
468dad0e31c2366c501bd1d600261d0af35a6ca786Glenn Kastenstatic const char kDeadlockedString[] = "AudioPolicyService may be deadlocked\n";
478dad0e31c2366c501bd1d600261d0af35a6ca786Glenn Kastenstatic const char kCmdDeadlockedString[] = "AudioPolicyService command thread may be deadlocked\n";
4865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
4965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatic const int kDumpLockRetries = 50;
5022ecc912a87099cff8cadc424cd12f85c118673fGlenn Kastenstatic const int kDumpLockSleepUs = 20000;
5165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
52fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinnamespace {
53fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    extern struct audio_policy_service_ops aps_ops;
54fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin};
55fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin
5665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ----------------------------------------------------------------------------
5765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
5865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioPolicyService::AudioPolicyService()
59fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    : BnAudioPolicyService() , mpAudioPolicyDev(NULL) , mpAudioPolicy(NULL)
6065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
6165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    char value[PROPERTY_VALUE_MAX];
62fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    const struct hw_module_t *module;
63fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    int forced_val;
64fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    int rc;
6565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
66935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent    Mutex::Autolock _l(mLock);
67935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent
6865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // start tone playback thread
6965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    mTonePlaybackThread = new AudioCommandThread(String8(""));
7065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // start audio commands thread
71480b46802bef1371d5caa16ad5454fce04769c57Glenn Kasten    mAudioCommandThread = new AudioCommandThread(String8("ApmCommand"));
7265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
73fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    /* instantiate the audio policy manager */
74fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    rc = hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module);
75fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (rc)
76fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        return;
7765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
78fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    rc = audio_policy_dev_open(module, &mpAudioPolicyDev);
7929357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block    ALOGE_IF(rc, "couldn't open audio policy device (%s)", strerror(-rc));
80fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (rc)
81fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        return;
82935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent
83fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    rc = mpAudioPolicyDev->create_audio_policy(mpAudioPolicyDev, &aps_ops, this,
84fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                               &mpAudioPolicy);
8529357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block    ALOGE_IF(rc, "couldn't create audio policy (%s)", strerror(-rc));
86fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (rc)
87fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        return;
88fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin
89fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    rc = mpAudioPolicy->init_check(mpAudioPolicy);
9029357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block    ALOGE_IF(rc, "couldn't init_check the audio policy (%s)", strerror(-rc));
91fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (rc)
92fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        return;
93fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin
94df64d15042bbd5e0e4933ac49bf3c177dd94752cSteve Block    ALOGI("Loaded audio policy from %s (%s)", module->name, module->id);
957c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
967c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    // load audio pre processing modules
977c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    if (access(AUDIO_EFFECT_VENDOR_CONFIG_FILE, R_OK) == 0) {
987c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        loadPreProcessorConfig(AUDIO_EFFECT_VENDOR_CONFIG_FILE);
997c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    } else if (access(AUDIO_EFFECT_DEFAULT_CONFIG_FILE, R_OK) == 0) {
1007c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        loadPreProcessorConfig(AUDIO_EFFECT_DEFAULT_CONFIG_FILE);
1017c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    }
10265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
10365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
10465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioPolicyService::~AudioPolicyService()
10565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
10665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    mTonePlaybackThread->exit();
10765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    mTonePlaybackThread.clear();
10865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    mAudioCommandThread->exit();
10965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    mAudioCommandThread.clear();
11065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1117c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
1127c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    // release audio pre processing resources
1137c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    for (size_t i = 0; i < mInputSources.size(); i++) {
1149fda4b87441fe17d90d8144639c9de6d9022c3c0Glenn Kasten        delete mInputSources.valueAt(i);
1157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    }
1167c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    mInputSources.clear();
1177c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
1187c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    for (size_t i = 0; i < mInputs.size(); i++) {
1197c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        mInputs.valueAt(i)->mEffects.clear();
1207c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        delete mInputs.valueAt(i);
1217c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    }
1227c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    mInputs.clear();
1237c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
124a0d68338a88c2ddb4502f95017b546d603ef1ec7Glenn Kasten    if (mpAudioPolicy != NULL && mpAudioPolicyDev != NULL)
125fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        mpAudioPolicyDev->destroy_audio_policy(mpAudioPolicyDev, mpAudioPolicy);
126a0d68338a88c2ddb4502f95017b546d603ef1ec7Glenn Kasten    if (mpAudioPolicyDev != NULL)
127fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        audio_policy_dev_close(mpAudioPolicyDev);
12865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
12965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
130fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatus_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device,
131fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                                  audio_policy_dev_state_t state,
13265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                                  const char *device_address)
13365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
134fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
13565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return NO_INIT;
13665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
13744deb053252a3bd2f57a007ab9560f4924f62394Glenn Kasten    if (!settingsAllowed()) {
13865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return PERMISSION_DENIED;
13965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
140fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (!audio_is_output_device(device) && !audio_is_input_device(device)) {
14165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return BAD_VALUE;
14265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
143fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE &&
144fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) {
14565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return BAD_VALUE;
14665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
14765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setDeviceConnectionState() tid %d", gettid());
14965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex::Autolock _l(mLock);
150fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->set_device_connection_state(mpAudioPolicy, device,
151fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                                      state, device_address);
15265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
15365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
154fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinaudio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState(
155fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                                              audio_devices_t device,
156de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                              const char *device_address)
15765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
158fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
159fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
16065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
161fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->get_device_connection_state(mpAudioPolicy, device,
162fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                                      device_address);
16365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
16465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
165f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kastenstatus_t AudioPolicyService::setPhoneState(audio_mode_t state)
16665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
167fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
16865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return NO_INIT;
16965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
17044deb053252a3bd2f57a007ab9560f4924f62394Glenn Kasten    if (!settingsAllowed()) {
17165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return PERMISSION_DENIED;
17265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
173930f4caa1e311ef7ff538c421a324396157eb24fGlenn Kasten    if (uint32_t(state) >= AUDIO_MODE_CNT) {
17465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return BAD_VALUE;
17565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
17665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1773856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setPhoneState() tid %d", gettid());
17865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
17965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // TODO: check if it is more appropriate to do it in platform specific policy manager
18065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    AudioSystem::setMode(state);
18165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
18265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex::Autolock _l(mLock);
183fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    mpAudioPolicy->set_phone_state(mpAudioPolicy, state);
18465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    return NO_ERROR;
18565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
18665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
187fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatus_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage,
188fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                         audio_policy_forced_cfg_t config)
18965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
190fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
19165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return NO_INIT;
19265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
19344deb053252a3bd2f57a007ab9560f4924f62394Glenn Kasten    if (!settingsAllowed()) {
19465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return PERMISSION_DENIED;
19565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
196fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) {
19765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return BAD_VALUE;
19865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
199fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) {
20065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return BAD_VALUE;
20165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
2023856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setForceUse() tid %d", gettid());
20365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex::Autolock _l(mLock);
204fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    mpAudioPolicy->set_force_use(mpAudioPolicy, usage, config);
20565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    return NO_ERROR;
20665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
20765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
208fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinaudio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage)
20965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
210fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
211fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        return AUDIO_POLICY_FORCE_NONE;
21265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
213fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) {
214fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        return AUDIO_POLICY_FORCE_NONE;
21565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
216fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->get_force_use(mpAudioPolicy, usage);
21765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
21865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
219fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinaudio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream,
22065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    uint32_t samplingRate,
22158f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                    audio_format_t format,
222254af180475346b6186b49c297f340c9c4817511Glenn Kasten                                    audio_channel_mask_t channelMask,
2230ca3cf94c0dfc173ad7886ae162c4b67067539f6Eric Laurent                                    audio_output_flags_t flags)
22465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
225fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
22665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return 0;
22765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
2283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("getOutput() tid %d", gettid());
22965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex::Autolock _l(mLock);
230254af180475346b6186b49c297f340c9c4817511Glenn Kasten    return mpAudioPolicy->get_output(mpAudioPolicy, stream, samplingRate, format, channelMask, flags);
23165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
23265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
233de070137f11d346fba77605bd76a44c040a618fcEric Laurentstatus_t AudioPolicyService::startOutput(audio_io_handle_t output,
234fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                         audio_stream_type_t stream,
235de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                         int session)
23665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
237fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
23865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return NO_INIT;
23965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
2403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("startOutput() tid %d", gettid());
24165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex::Autolock _l(mLock);
242fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->start_output(mpAudioPolicy, output, stream, session);
24365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
24465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
245de070137f11d346fba77605bd76a44c040a618fcEric Laurentstatus_t AudioPolicyService::stopOutput(audio_io_handle_t output,
246fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                        audio_stream_type_t stream,
247de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                        int session)
24865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
249fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
25065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return NO_INIT;
25165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
2523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("stopOutput() tid %d", gettid());
25365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex::Autolock _l(mLock);
254fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->stop_output(mpAudioPolicy, output, stream, session);
25565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
25665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
25765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::releaseOutput(audio_io_handle_t output)
25865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
259fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
26065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return;
26165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
2623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("releaseOutput() tid %d", gettid());
26365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex::Autolock _l(mLock);
264fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    mpAudioPolicy->release_output(mpAudioPolicy, output);
26565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
26665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
267eba51fb3a361f67a6a64d5a16eba6084fe27d60eGlenn Kastenaudio_io_handle_t AudioPolicyService::getInput(audio_source_t inputSource,
26865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    uint32_t samplingRate,
26958f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                    audio_format_t format,
270254af180475346b6186b49c297f340c9c4817511Glenn Kasten                                    audio_channel_mask_t channelMask,
2717c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                    int audioSession)
27265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
273fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
27465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return 0;
27565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
276eba51fb3a361f67a6a64d5a16eba6084fe27d60eGlenn Kasten    // already checked by client, but double-check in case the client wrapper is bypassed
277eba51fb3a361f67a6a64d5a16eba6084fe27d60eGlenn Kasten    if (uint32_t(inputSource) >= AUDIO_SOURCE_CNT) {
278eba51fb3a361f67a6a64d5a16eba6084fe27d60eGlenn Kasten        return 0;
279eba51fb3a361f67a6a64d5a16eba6084fe27d60eGlenn Kasten    }
28065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex::Autolock _l(mLock);
28120010053daabfa43fcfe781bbf004473b4c08538Glenn Kasten    // the audio_in_acoustics_t parameter is ignored by get_input()
2827c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    audio_io_handle_t input = mpAudioPolicy->get_input(mpAudioPolicy, inputSource, samplingRate,
283254af180475346b6186b49c297f340c9c4817511Glenn Kasten                                                       format, channelMask, (audio_in_acoustics_t) 0);
2847c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
2857c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    if (input == 0) {
2867c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        return input;
2877c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    }
2887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    // create audio pre processors according to input source
289eba51fb3a361f67a6a64d5a16eba6084fe27d60eGlenn Kasten    ssize_t index = mInputSources.indexOfKey(inputSource);
2907c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    if (index < 0) {
2917c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        return input;
2927c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    }
2937c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    ssize_t idx = mInputs.indexOfKey(input);
2947c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    InputDesc *inputDesc;
2957c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    if (idx < 0) {
29681872a2ce65653ae980621ba2907da56a83ba9a7Glenn Kasten        inputDesc = new InputDesc(audioSession);
2977c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        mInputs.add(input, inputDesc);
2987c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    } else {
2997c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        inputDesc = mInputs.valueAt(idx);
3007c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    }
3017c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
3027c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    Vector <EffectDesc *> effects = mInputSources.valueAt(index)->mEffects;
3037c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    for (size_t i = 0; i < effects.size(); i++) {
3047c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        EffectDesc *effect = effects[i];
3057c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        sp<AudioEffect> fx = new AudioEffect(NULL, &effect->mUuid, -1, 0, 0, audioSession, input);
3067c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        status_t status = fx->initCheck();
3077c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        if (status != NO_ERROR && status != ALREADY_EXISTS) {
3085ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block            ALOGW("Failed to create Fx %s on input %d", effect->mName, input);
3097c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            // fx goes out of scope and strong ref on AudioEffect is released
3107c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            continue;
3117c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        }
3127c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        for (size_t j = 0; j < effect->mParams.size(); j++) {
3137c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            fx->setParameter(effect->mParams[j]);
3147c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        }
3157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        inputDesc->mEffects.add(fx);
3167c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    }
3177c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    setPreProcessorEnabled(inputDesc, true);
3187c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    return input;
31965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
32065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
32165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::startInput(audio_io_handle_t input)
32265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
323fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
32465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return NO_INIT;
32565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
32665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex::Autolock _l(mLock);
3277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
328fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->start_input(mpAudioPolicy, input);
32965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
33065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
33165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::stopInput(audio_io_handle_t input)
33265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
333fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
33465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return NO_INIT;
33565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
33665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex::Autolock _l(mLock);
3377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
338fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->stop_input(mpAudioPolicy, input);
33965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
34065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
34165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::releaseInput(audio_io_handle_t input)
34265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
343fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
34465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return;
34565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
34665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex::Autolock _l(mLock);
347fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    mpAudioPolicy->release_input(mpAudioPolicy, input);
3487c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
3497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    ssize_t index = mInputs.indexOfKey(input);
3507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    if (index < 0) {
3517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        return;
3527c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    }
3537c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    InputDesc *inputDesc = mInputs.valueAt(index);
3547c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    setPreProcessorEnabled(inputDesc, false);
3557c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    delete inputDesc;
3567c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    mInputs.removeItemsAt(index);
35765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
35865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
359fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatus_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream,
36065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                            int indexMin,
36165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                            int indexMax)
36265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
363fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
36465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return NO_INIT;
36565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
36644deb053252a3bd2f57a007ab9560f4924f62394Glenn Kasten    if (!settingsAllowed()) {
36765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return PERMISSION_DENIED;
36865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
369263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten    if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
37065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return BAD_VALUE;
37165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
3725f12136299918ea30555f3481668ec0dbb775e5fEric Laurent    Mutex::Autolock _l(mLock);
373fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    mpAudioPolicy->init_stream_volume(mpAudioPolicy, stream, indexMin, indexMax);
37465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    return NO_ERROR;
37565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
37665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
37783844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurentstatus_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream,
37883844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                                  int index,
37983844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                                  audio_devices_t device)
38065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
381fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
38265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return NO_INIT;
38365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
38444deb053252a3bd2f57a007ab9560f4924f62394Glenn Kasten    if (!settingsAllowed()) {
38565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return PERMISSION_DENIED;
38665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
387263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten    if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
38865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return BAD_VALUE;
38965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
3905f12136299918ea30555f3481668ec0dbb775e5fEric Laurent    Mutex::Autolock _l(mLock);
39183844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent    if (mpAudioPolicy->set_stream_volume_index_for_device) {
39283844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent        return mpAudioPolicy->set_stream_volume_index_for_device(mpAudioPolicy,
39383844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                                                stream,
39483844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                                                index,
39583844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                                                device);
39683844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent    } else {
39783844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent        return mpAudioPolicy->set_stream_volume_index(mpAudioPolicy, stream, index);
39883844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent    }
39965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
40065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
40183844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurentstatus_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream,
40283844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                                  int *index,
40383844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                                  audio_devices_t device)
40465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
405fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
40665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return NO_INIT;
40765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
408263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten    if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
40965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        return BAD_VALUE;
41065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
4115f12136299918ea30555f3481668ec0dbb775e5fEric Laurent    Mutex::Autolock _l(mLock);
41283844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent    if (mpAudioPolicy->get_stream_volume_index_for_device) {
41383844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent        return mpAudioPolicy->get_stream_volume_index_for_device(mpAudioPolicy,
41483844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                                                stream,
41583844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                                                index,
41683844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                                                device);
41783844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent    } else {
41883844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent        return mpAudioPolicy->get_stream_volume_index(mpAudioPolicy, stream, index);
41983844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent    }
42065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
42165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
422fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinuint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream)
423de070137f11d346fba77605bd76a44c040a618fcEric Laurent{
424fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
425de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return 0;
426de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
427fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->get_strategy_for_stream(mpAudioPolicy, stream);
428de070137f11d346fba77605bd76a44c040a618fcEric Laurent}
429de070137f11d346fba77605bd76a44c040a618fcEric Laurent
4306374252107fd6539397598195ea6defd5870fafbEric Laurent//audio policy: use audio_device_t appropriately
4316374252107fd6539397598195ea6defd5870fafbEric Laurent
4326374252107fd6539397598195ea6defd5870fafbEric Laurentaudio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream)
4336b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten{
434fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
4356374252107fd6539397598195ea6defd5870fafbEric Laurent        return (audio_devices_t)0;
4366b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten    }
437fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->get_devices_for_stream(mpAudioPolicy, stream);
4386b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten}
4396b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten
44058e5aa34f01d663654d8bafad65db1dda42161ffGlenn Kastenaudio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc)
441de070137f11d346fba77605bd76a44c040a618fcEric Laurent{
442fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
443de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return NO_INIT;
444de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
445de070137f11d346fba77605bd76a44c040a618fcEric Laurent    Mutex::Autolock _l(mLock);
446fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->get_output_for_effect(mpAudioPolicy, desc);
447de070137f11d346fba77605bd76a44c040a618fcEric Laurent}
448de070137f11d346fba77605bd76a44c040a618fcEric Laurent
44958e5aa34f01d663654d8bafad65db1dda42161ffGlenn Kastenstatus_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc,
4507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                audio_io_handle_t io,
451de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                uint32_t strategy,
452de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                int session,
453de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                int id)
454de070137f11d346fba77605bd76a44c040a618fcEric Laurent{
455fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
456de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return NO_INIT;
457de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
4587c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    return mpAudioPolicy->register_effect(mpAudioPolicy, desc, io, strategy, session, id);
459de070137f11d346fba77605bd76a44c040a618fcEric Laurent}
460de070137f11d346fba77605bd76a44c040a618fcEric Laurent
461de070137f11d346fba77605bd76a44c040a618fcEric Laurentstatus_t AudioPolicyService::unregisterEffect(int id)
462de070137f11d346fba77605bd76a44c040a618fcEric Laurent{
463fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
464de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return NO_INIT;
465de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
466fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->unregister_effect(mpAudioPolicy, id);
467de070137f11d346fba77605bd76a44c040a618fcEric Laurent}
468de070137f11d346fba77605bd76a44c040a618fcEric Laurent
469db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurentstatus_t AudioPolicyService::setEffectEnabled(int id, bool enabled)
470db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent{
471db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent    if (mpAudioPolicy == NULL) {
472db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent        return NO_INIT;
473db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent    }
474db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent    return mpAudioPolicy->set_effect_enabled(mpAudioPolicy, id, enabled);
475db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent}
476db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent
477fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kastenbool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
478eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent{
479fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    if (mpAudioPolicy == NULL) {
480eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        return 0;
481eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent    }
482eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent    Mutex::Autolock _l(mLock);
483fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    return mpAudioPolicy->is_stream_active(mpAudioPolicy, stream, inPastMs);
484eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent}
485eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent
486d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivibool AudioPolicyService::isSourceActive(audio_source_t source) const
487d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi{
488d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi    if (mpAudioPolicy == NULL) {
489d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi        return false;
490d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi    }
491d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi    if (mpAudioPolicy->is_source_active == 0) {
492d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi        return false;
493d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi    }
494d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi    Mutex::Autolock _l(mLock);
495d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi    return mpAudioPolicy->is_source_active(mpAudioPolicy, source);
496d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi}
497d7086030fcf731e4bcef6c033cc6418cd04e6b91Jean-Michel Trivi
49857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurentstatus_t AudioPolicyService::queryDefaultPreProcessing(int audioSession,
49957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                                                       effect_descriptor_t *descriptors,
50057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                                                       uint32_t *count)
50157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent{
50257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent
50357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    if (mpAudioPolicy == NULL) {
50457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        *count = 0;
50557dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        return NO_INIT;
50657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    }
50757dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    Mutex::Autolock _l(mLock);
50857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    status_t status = NO_ERROR;
50957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent
51057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    size_t index;
51157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    for (index = 0; index < mInputs.size(); index++) {
51257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        if (mInputs.valueAt(index)->mSessionId == audioSession) {
51357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            break;
51457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        }
51557dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    }
51657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    if (index == mInputs.size()) {
51757dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        *count = 0;
51857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        return BAD_VALUE;
51957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    }
52057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    Vector< sp<AudioEffect> > effects = mInputs.valueAt(index)->mEffects;
52157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent
52257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    for (size_t i = 0; i < effects.size(); i++) {
52357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        effect_descriptor_t desc = effects[i]->descriptor();
52457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        if (i < *count) {
525a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten            descriptors[i] = desc;
52657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        }
52757dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    }
52857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    if (effects.size() > *count) {
52957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        status = NO_MEMORY;
53057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    }
53157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    *count = effects.size();
53257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    return status;
53357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent}
53457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent
53565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::binderDied(const wp<IBinder>& who) {
53623d82a9bc9a43b49ba684ba40875b91db310d3b9Glenn Kasten    ALOGW("binderDied() %p, tid %d, calling pid %d", who.unsafe_get(), gettid(),
537de070137f11d346fba77605bd76a44c040a618fcEric Laurent            IPCThreadState::self()->getCallingPid());
53865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
53965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
54065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatic bool tryLock(Mutex& mutex)
54165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
54265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    bool locked = false;
54365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    for (int i = 0; i < kDumpLockRetries; ++i) {
54465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        if (mutex.tryLock() == NO_ERROR) {
54565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            locked = true;
54665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            break;
54765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
54822ecc912a87099cff8cadc424cd12f85c118673fGlenn Kasten        usleep(kDumpLockSleepUs);
54965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
55065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    return locked;
55165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
55265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
55365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::dumpInternals(int fd)
55465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
55565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    const size_t SIZE = 256;
55665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    char buffer[SIZE];
55765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    String8 result;
55865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
559fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    snprintf(buffer, SIZE, "PolicyManager Interface: %p\n", mpAudioPolicy);
56065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    result.append(buffer);
56165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    snprintf(buffer, SIZE, "Command Thread: %p\n", mAudioCommandThread.get());
56265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    result.append(buffer);
56365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    snprintf(buffer, SIZE, "Tones Thread: %p\n", mTonePlaybackThread.get());
56465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    result.append(buffer);
56565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
56665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    write(fd, result.string(), result.size());
56765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    return NO_ERROR;
56865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
56965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
57065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::dump(int fd, const Vector<String16>& args)
57165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
57244deb053252a3bd2f57a007ab9560f4924f62394Glenn Kasten    if (!dumpAllowed()) {
57365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        dumpPermissionDenial(fd);
57465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    } else {
57565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        bool locked = tryLock(mLock);
57665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        if (!locked) {
57765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            String8 result(kDeadlockedString);
57865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            write(fd, result.string(), result.size());
57965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
58065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
58165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        dumpInternals(fd);
5829d1f02d74fd395ec4de6861147da289423f0ab6fGlenn Kasten        if (mAudioCommandThread != 0) {
58365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            mAudioCommandThread->dump(fd);
58465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
5859d1f02d74fd395ec4de6861147da289423f0ab6fGlenn Kasten        if (mTonePlaybackThread != 0) {
58665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            mTonePlaybackThread->dump(fd);
58765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
58865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
589fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        if (mpAudioPolicy) {
590fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            mpAudioPolicy->dump(mpAudioPolicy, fd);
59165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
59265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
59365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        if (locked) mLock.unlock();
59465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    }
59565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    return NO_ERROR;
59665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
59765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
59865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::dumpPermissionDenial(int fd)
59965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
60065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    const size_t SIZE = 256;
60165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    char buffer[SIZE];
60265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    String8 result;
60365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    snprintf(buffer, SIZE, "Permission Denial: "
60465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            "can't dump AudioPolicyService from pid=%d, uid=%d\n",
60565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            IPCThreadState::self()->getCallingPid(),
60665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            IPCThreadState::self()->getCallingUid());
60765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    result.append(buffer);
60865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    write(fd, result.string(), result.size());
60965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    return NO_ERROR;
61065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
61165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
61281872a2ce65653ae980621ba2907da56a83ba9a7Glenn Kastenvoid AudioPolicyService::setPreProcessorEnabled(const InputDesc *inputDesc, bool enabled)
6137c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{
61481872a2ce65653ae980621ba2907da56a83ba9a7Glenn Kasten    const Vector<sp<AudioEffect> > &fxVector = inputDesc->mEffects;
6157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    for (size_t i = 0; i < fxVector.size(); i++) {
616a111792f1314479c649d1d44c30c2caf70c00c2aGlenn Kasten        fxVector.itemAt(i)->setEnabled(enabled);
6177c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    }
6187c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent}
6197c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
62065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::onTransact(
62165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
62265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
62365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    return BnAudioPolicyService::onTransact(code, data, reply, flags);
62465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
62565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
62665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
62765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// -----------  AudioPolicyService::AudioCommandThread implementation ----------
62865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
62965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioPolicyService::AudioCommandThread::AudioCommandThread(String8 name)
63065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    : Thread(false), mName(name)
63165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
63265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    mpToneGenerator = NULL;
63365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}
63465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
63565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
63665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioPolicyService::AudioCommandThread::~AudioCommandThread()
63765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
638