├── Android.mk ├── CleanSpec.mk ├── MODULE_LICENSE_APACHE2 ├── NOTICE ├── audio ├── A2dpAudioInterface.cpp ├── A2dpAudioInterface.h ├── Android.mk ├── AudioDumpInterface.cpp ├── AudioDumpInterface.h ├── AudioHardwareGeneric.cpp ├── AudioHardwareGeneric.h ├── AudioHardwareInterface.cpp ├── AudioHardwareStub.cpp ├── AudioHardwareStub.h ├── AudioPolicyCompatClient.cpp ├── AudioPolicyCompatClient.h ├── AudioPolicyManagerBase.cpp ├── AudioPolicyManagerDefault.cpp ├── AudioPolicyManagerDefault.h ├── audio_hw_hal.cpp ├── audio_policy.conf └── audio_policy_hal.cpp ├── include └── hardware_legacy │ ├── AudioHardwareBase.h │ ├── AudioHardwareInterface.h │ ├── AudioPolicyInterface.h │ ├── AudioPolicyManagerBase.h │ ├── AudioSystemLegacy.h │ ├── IMountService.h │ ├── audio_policy_conf.h │ ├── gscan.h │ ├── link_layer_stats.h │ ├── power.h │ ├── qemu_tracing.h │ ├── rtt.h │ ├── tdls.h │ ├── uevent.h │ ├── wifi.h │ ├── wifi_config.h │ ├── wifi_hal.h │ ├── wifi_logger.h │ ├── wifi_nan.h │ └── wifi_offload.h ├── power ├── Android.mk └── power.c ├── qemu.h ├── qemu ├── Android.mk └── qemu.c ├── qemu_tracing ├── Android.mk └── qemu_tracing.c ├── uevent ├── Android.mk └── uevent.c └── wifi ├── Android.mk ├── wifi.c ├── wifi_fst.c └── wifi_fst.h /Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2006 The Android Open Source Project 2 | 3 | # Setting LOCAL_PATH will mess up all-subdir-makefiles, so do it beforehand. 4 | legacy_modules := power uevent wifi qemu qemu_tracing 5 | 6 | SAVE_MAKEFILES := $(call all-named-subdir-makefiles,$(legacy_modules)) 7 | LEGACY_AUDIO_MAKEFILES := $(call all-named-subdir-makefiles,audio) 8 | 9 | LOCAL_PATH:= $(call my-dir) 10 | include $(CLEAR_VARS) 11 | 12 | LOCAL_SHARED_LIBRARIES := libcutils liblog 13 | 14 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include 15 | LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include 16 | 17 | LOCAL_CFLAGS += -DQEMU_HARDWARE -Wno-unused-parameter -Wno-gnu-designator 18 | 19 | ifeq ($(KERNEL_HAS_FINIT_MODULE), false) 20 | LOCAL_CFLAGS += -DNO_FINIT_MODULE 21 | endif 22 | 23 | ifdef USES_TI_MAC80211 24 | ifneq ($(wildcard external/libnl),) 25 | LOCAL_SHARED_LIBRARIES += libnl 26 | LOCAL_C_INCLUDES += external/libnl/include 27 | else 28 | LOCAL_STATIC_LIBRARIES := libnl_2 29 | LOCAL_C_INCLUDES += external/libnl-headers 30 | endif 31 | endif 32 | 33 | QEMU_HARDWARE := true 34 | 35 | LOCAL_SHARED_LIBRARIES += libdl 36 | 37 | include $(SAVE_MAKEFILES) 38 | 39 | LOCAL_MODULE:= libhardware_legacy 40 | 41 | include $(BUILD_SHARED_LIBRARY) 42 | 43 | # static library for librpc 44 | include $(CLEAR_VARS) 45 | 46 | LOCAL_MODULE:= libpower 47 | 48 | LOCAL_SRC_FILES += power/power.c 49 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include 50 | LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include 51 | 52 | include $(BUILD_STATIC_LIBRARY) 53 | 54 | # shared library for various HALs 55 | include $(CLEAR_VARS) 56 | 57 | LOCAL_MODULE := libpower 58 | 59 | LOCAL_SRC_FILES := power/power.c 60 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include 61 | LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include 62 | 63 | LOCAL_SHARED_LIBRARIES := libcutils 64 | 65 | include $(BUILD_SHARED_LIBRARY) 66 | 67 | # legacy_audio builds it's own set of libraries that aren't linked into 68 | # hardware_legacy 69 | include $(LEGACY_AUDIO_MAKEFILES) 70 | -------------------------------------------------------------------------------- /CleanSpec.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007 The Android Open Source Project 2 | # 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 | # If you don't need to do a full clean build but would like to touch 17 | # a file or delete some intermediate files, add a clean step to the end 18 | # of the list. These steps will only be run once, if they haven't been 19 | # run before. 20 | # 21 | # E.g.: 22 | # $(call add-clean-step, touch -c external/sqlite/sqlite3.h) 23 | # $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) 24 | # 25 | # Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with 26 | # files that are missing or have been moved. 27 | # 28 | # Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. 29 | # Use $(OUT_DIR) to refer to the "out" directory. 30 | # 31 | # If you need to re-do something that's already mentioned, just copy 32 | # the command and add it to the bottom of the list. E.g., if a change 33 | # that you made last week required touching a file and a change you 34 | # made today requires touching the same file, just copy the old 35 | # touch step and add it to the end of the list. 36 | # 37 | # ************************************************ 38 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 39 | # ************************************************ 40 | 41 | # For example: 42 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) 43 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) 44 | #$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) 45 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) 46 | 47 | # ************************************************ 48 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 49 | # ************************************************ 50 | $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libhardware_legacy_intermediates/) 51 | $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libhardware_legacy_intermediates/) -------------------------------------------------------------------------------- /MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyanogenMod/android_hardware_libhardware_legacy/2cf952c3af06428e0d99aef3d7ddc27f40851956/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2005-2008, 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 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | 13 | 14 | Apache License 15 | Version 2.0, January 2004 16 | http://www.apache.org/licenses/ 17 | 18 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 19 | 20 | 1. Definitions. 21 | 22 | "License" shall mean the terms and conditions for use, reproduction, 23 | and distribution as defined by Sections 1 through 9 of this document. 24 | 25 | "Licensor" shall mean the copyright owner or entity authorized by 26 | the copyright owner that is granting the License. 27 | 28 | "Legal Entity" shall mean the union of the acting entity and all 29 | other entities that control, are controlled by, or are under common 30 | control with that entity. For the purposes of this definition, 31 | "control" means (i) the power, direct or indirect, to cause the 32 | direction or management of such entity, whether by contract or 33 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 34 | outstanding shares, or (iii) beneficial ownership of such entity. 35 | 36 | "You" (or "Your") shall mean an individual or Legal Entity 37 | exercising permissions granted by this License. 38 | 39 | "Source" form shall mean the preferred form for making modifications, 40 | including but not limited to software source code, documentation 41 | source, and configuration files. 42 | 43 | "Object" form shall mean any form resulting from mechanical 44 | transformation or translation of a Source form, including but 45 | not limited to compiled object code, generated documentation, 46 | and conversions to other media types. 47 | 48 | "Work" shall mean the work of authorship, whether in Source or 49 | Object form, made available under the License, as indicated by a 50 | copyright notice that is included in or attached to the work 51 | (an example is provided in the Appendix below). 52 | 53 | "Derivative Works" shall mean any work, whether in Source or Object 54 | form, that is based on (or derived from) the Work and for which the 55 | editorial revisions, annotations, elaborations, or other modifications 56 | represent, as a whole, an original work of authorship. For the purposes 57 | of this License, Derivative Works shall not include works that remain 58 | separable from, or merely link (or bind by name) to the interfaces of, 59 | the Work and Derivative Works thereof. 60 | 61 | "Contribution" shall mean any work of authorship, including 62 | the original version of the Work and any modifications or additions 63 | to that Work or Derivative Works thereof, that is intentionally 64 | submitted to Licensor for inclusion in the Work by the copyright owner 65 | or by an individual or Legal Entity authorized to submit on behalf of 66 | the copyright owner. For the purposes of this definition, "submitted" 67 | means any form of electronic, verbal, or written communication sent 68 | to the Licensor or its representatives, including but not limited to 69 | communication on electronic mailing lists, source code control systems, 70 | and issue tracking systems that are managed by, or on behalf of, the 71 | Licensor for the purpose of discussing and improving the Work, but 72 | excluding communication that is conspicuously marked or otherwise 73 | designated in writing by the copyright owner as "Not a Contribution." 74 | 75 | "Contributor" shall mean Licensor and any individual or Legal Entity 76 | on behalf of whom a Contribution has been received by Licensor and 77 | subsequently incorporated within the Work. 78 | 79 | 2. Grant of Copyright License. Subject to the terms and conditions of 80 | this License, each Contributor hereby grants to You a perpetual, 81 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 82 | copyright license to reproduce, prepare Derivative Works of, 83 | publicly display, publicly perform, sublicense, and distribute the 84 | Work and such Derivative Works in Source or Object form. 85 | 86 | 3. Grant of Patent License. Subject to the terms and conditions of 87 | this License, each Contributor hereby grants to You a perpetual, 88 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 89 | (except as stated in this section) patent license to make, have made, 90 | use, offer to sell, sell, import, and otherwise transfer the Work, 91 | where such license applies only to those patent claims licensable 92 | by such Contributor that are necessarily infringed by their 93 | Contribution(s) alone or by combination of their Contribution(s) 94 | with the Work to which such Contribution(s) was submitted. If You 95 | institute patent litigation against any entity (including a 96 | cross-claim or counterclaim in a lawsuit) alleging that the Work 97 | or a Contribution incorporated within the Work constitutes direct 98 | or contributory patent infringement, then any patent licenses 99 | granted to You under this License for that Work shall terminate 100 | as of the date such litigation is filed. 101 | 102 | 4. Redistribution. You may reproduce and distribute copies of the 103 | Work or Derivative Works thereof in any medium, with or without 104 | modifications, and in Source or Object form, provided that You 105 | meet the following conditions: 106 | 107 | (a) You must give any other recipients of the Work or 108 | Derivative Works a copy of this License; and 109 | 110 | (b) You must cause any modified files to carry prominent notices 111 | stating that You changed the files; and 112 | 113 | (c) You must retain, in the Source form of any Derivative Works 114 | that You distribute, all copyright, patent, trademark, and 115 | attribution notices from the Source form of the Work, 116 | excluding those notices that do not pertain to any part of 117 | the Derivative Works; and 118 | 119 | (d) If the Work includes a "NOTICE" text file as part of its 120 | distribution, then any Derivative Works that You distribute must 121 | include a readable copy of the attribution notices contained 122 | within such NOTICE file, excluding those notices that do not 123 | pertain to any part of the Derivative Works, in at least one 124 | of the following places: within a NOTICE text file distributed 125 | as part of the Derivative Works; within the Source form or 126 | documentation, if provided along with the Derivative Works; or, 127 | within a display generated by the Derivative Works, if and 128 | wherever such third-party notices normally appear. The contents 129 | of the NOTICE file are for informational purposes only and 130 | do not modify the License. You may add Your own attribution 131 | notices within Derivative Works that You distribute, alongside 132 | or as an addendum to the NOTICE text from the Work, provided 133 | that such additional attribution notices cannot be construed 134 | as modifying the License. 135 | 136 | You may add Your own copyright statement to Your modifications and 137 | may provide additional or different license terms and conditions 138 | for use, reproduction, or distribution of Your modifications, or 139 | for any such Derivative Works as a whole, provided Your use, 140 | reproduction, and distribution of the Work otherwise complies with 141 | the conditions stated in this License. 142 | 143 | 5. Submission of Contributions. Unless You explicitly state otherwise, 144 | any Contribution intentionally submitted for inclusion in the Work 145 | by You to the Licensor shall be under the terms and conditions of 146 | this License, without any additional terms or conditions. 147 | Notwithstanding the above, nothing herein shall supersede or modify 148 | the terms of any separate license agreement you may have executed 149 | with Licensor regarding such Contributions. 150 | 151 | 6. Trademarks. This License does not grant permission to use the trade 152 | names, trademarks, service marks, or product names of the Licensor, 153 | except as required for reasonable and customary use in describing the 154 | origin of the Work and reproducing the content of the NOTICE file. 155 | 156 | 7. Disclaimer of Warranty. Unless required by applicable law or 157 | agreed to in writing, Licensor provides the Work (and each 158 | Contributor provides its Contributions) on an "AS IS" BASIS, 159 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 160 | implied, including, without limitation, any warranties or conditions 161 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 162 | PARTICULAR PURPOSE. You are solely responsible for determining the 163 | appropriateness of using or redistributing the Work and assume any 164 | risks associated with Your exercise of permissions under this License. 165 | 166 | 8. Limitation of Liability. In no event and under no legal theory, 167 | whether in tort (including negligence), contract, or otherwise, 168 | unless required by applicable law (such as deliberate and grossly 169 | negligent acts) or agreed to in writing, shall any Contributor be 170 | liable to You for damages, including any direct, indirect, special, 171 | incidental, or consequential damages of any character arising as a 172 | result of this License or out of the use or inability to use the 173 | Work (including but not limited to damages for loss of goodwill, 174 | work stoppage, computer failure or malfunction, or any and all 175 | other commercial damages or losses), even if such Contributor 176 | has been advised of the possibility of such damages. 177 | 178 | 9. Accepting Warranty or Additional Liability. While redistributing 179 | the Work or Derivative Works thereof, You may choose to offer, 180 | and charge a fee for, acceptance of support, warranty, indemnity, 181 | or other liability obligations and/or rights consistent with this 182 | License. However, in accepting such obligations, You may act only 183 | on Your own behalf and on Your sole responsibility, not on behalf 184 | of any other Contributor, and only if You agree to indemnify, 185 | defend, and hold each Contributor harmless for any liability 186 | incurred by, or claims asserted against, such Contributor by reason 187 | of your accepting any such warranty or additional liability. 188 | 189 | END OF TERMS AND CONDITIONS 190 | 191 | -------------------------------------------------------------------------------- /audio/A2dpAudioInterface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #include 18 | 19 | //#define LOG_NDEBUG 0 20 | #define LOG_TAG "A2dpAudioInterface" 21 | #include 22 | #include 23 | #include 24 | 25 | #include "A2dpAudioInterface.h" 26 | #include "audio/liba2dp.h" 27 | #include 28 | 29 | 30 | namespace android_audio_legacy { 31 | 32 | static const char *sA2dpWakeLock = "A2dpOutputStream"; 33 | #define MAX_WRITE_RETRIES 5 34 | 35 | // ---------------------------------------------------------------------------- 36 | 37 | //AudioHardwareInterface* A2dpAudioInterface::createA2dpInterface() 38 | //{ 39 | // AudioHardwareInterface* hw = 0; 40 | // 41 | // hw = AudioHardwareInterface::create(); 42 | // ALOGD("new A2dpAudioInterface(hw: %p)", hw); 43 | // hw = new A2dpAudioInterface(hw); 44 | // return hw; 45 | //} 46 | 47 | A2dpAudioInterface::A2dpAudioInterface(AudioHardwareInterface* hw) : 48 | mOutput(0), mHardwareInterface(hw), mBluetoothEnabled(true), mSuspended(false) 49 | { 50 | } 51 | 52 | A2dpAudioInterface::~A2dpAudioInterface() 53 | { 54 | closeOutputStream((AudioStreamOut *)mOutput); 55 | delete mHardwareInterface; 56 | } 57 | 58 | status_t A2dpAudioInterface::initCheck() 59 | { 60 | if (mHardwareInterface == 0) return NO_INIT; 61 | return mHardwareInterface->initCheck(); 62 | } 63 | 64 | AudioStreamOut* A2dpAudioInterface::openOutputStream( 65 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status) 66 | { 67 | if (!audio_is_a2dp_out_device(devices)) { 68 | ALOGV("A2dpAudioInterface::openOutputStream() open HW device: %x", devices); 69 | return mHardwareInterface->openOutputStream(devices, format, channels, sampleRate, status); 70 | } 71 | 72 | status_t err = 0; 73 | 74 | // only one output stream allowed 75 | if (mOutput) { 76 | if (status) 77 | *status = -1; 78 | return NULL; 79 | } 80 | 81 | // create new output stream 82 | A2dpAudioStreamOut* out = new A2dpAudioStreamOut(); 83 | if ((err = out->set(devices, format, channels, sampleRate)) == NO_ERROR) { 84 | mOutput = out; 85 | mOutput->setBluetoothEnabled(mBluetoothEnabled); 86 | mOutput->setSuspended(mSuspended); 87 | } else { 88 | delete out; 89 | } 90 | 91 | if (status) 92 | *status = err; 93 | return mOutput; 94 | } 95 | 96 | void A2dpAudioInterface::closeOutputStream(AudioStreamOut* out) { 97 | if (mOutput == 0 || mOutput != out) { 98 | mHardwareInterface->closeOutputStream(out); 99 | } 100 | else { 101 | delete mOutput; 102 | mOutput = 0; 103 | } 104 | } 105 | 106 | 107 | AudioStreamIn* A2dpAudioInterface::openInputStream( 108 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status, 109 | AudioSystem::audio_in_acoustics acoustics) 110 | { 111 | return mHardwareInterface->openInputStream(devices, format, channels, sampleRate, status, acoustics); 112 | } 113 | 114 | void A2dpAudioInterface::closeInputStream(AudioStreamIn* in) 115 | { 116 | return mHardwareInterface->closeInputStream(in); 117 | } 118 | 119 | status_t A2dpAudioInterface::setMode(int mode) 120 | { 121 | return mHardwareInterface->setMode(mode); 122 | } 123 | 124 | status_t A2dpAudioInterface::setMicMute(bool state) 125 | { 126 | return mHardwareInterface->setMicMute(state); 127 | } 128 | 129 | status_t A2dpAudioInterface::getMicMute(bool* state) 130 | { 131 | return mHardwareInterface->getMicMute(state); 132 | } 133 | 134 | status_t A2dpAudioInterface::setParameters(const String8& keyValuePairs) 135 | { 136 | AudioParameter param = AudioParameter(keyValuePairs); 137 | String8 value; 138 | String8 key; 139 | status_t status = NO_ERROR; 140 | 141 | ALOGV("setParameters() %s", keyValuePairs.string()); 142 | 143 | key = "bluetooth_enabled"; 144 | if (param.get(key, value) == NO_ERROR) { 145 | mBluetoothEnabled = (value == "true"); 146 | if (mOutput) { 147 | mOutput->setBluetoothEnabled(mBluetoothEnabled); 148 | } 149 | param.remove(key); 150 | } 151 | key = String8("A2dpSuspended"); 152 | if (param.get(key, value) == NO_ERROR) { 153 | mSuspended = (value == "true"); 154 | if (mOutput) { 155 | mOutput->setSuspended(mSuspended); 156 | } 157 | param.remove(key); 158 | } 159 | 160 | if (param.size()) { 161 | status_t hwStatus = mHardwareInterface->setParameters(param.toString()); 162 | if (status == NO_ERROR) { 163 | status = hwStatus; 164 | } 165 | } 166 | 167 | return status; 168 | } 169 | 170 | String8 A2dpAudioInterface::getParameters(const String8& keys) 171 | { 172 | AudioParameter param = AudioParameter(keys); 173 | AudioParameter a2dpParam = AudioParameter(); 174 | String8 value; 175 | String8 key; 176 | 177 | key = "bluetooth_enabled"; 178 | if (param.get(key, value) == NO_ERROR) { 179 | value = mBluetoothEnabled ? "true" : "false"; 180 | a2dpParam.add(key, value); 181 | param.remove(key); 182 | } 183 | key = "A2dpSuspended"; 184 | if (param.get(key, value) == NO_ERROR) { 185 | value = mSuspended ? "true" : "false"; 186 | a2dpParam.add(key, value); 187 | param.remove(key); 188 | } 189 | 190 | String8 keyValuePairs = a2dpParam.toString(); 191 | 192 | if (param.size()) { 193 | if (keyValuePairs != "") { 194 | keyValuePairs += ";"; 195 | } 196 | keyValuePairs += mHardwareInterface->getParameters(param.toString()); 197 | } 198 | 199 | ALOGV("getParameters() %s", keyValuePairs.string()); 200 | return keyValuePairs; 201 | } 202 | 203 | size_t A2dpAudioInterface::getInputBufferSize(uint32_t sampleRate, int format, int channelCount) 204 | { 205 | return mHardwareInterface->getInputBufferSize(sampleRate, format, channelCount); 206 | } 207 | 208 | status_t A2dpAudioInterface::setVoiceVolume(float v) 209 | { 210 | return mHardwareInterface->setVoiceVolume(v); 211 | } 212 | 213 | status_t A2dpAudioInterface::setMasterVolume(float v) 214 | { 215 | return mHardwareInterface->setMasterVolume(v); 216 | } 217 | 218 | status_t A2dpAudioInterface::dump(int fd, const Vector& args) 219 | { 220 | return mHardwareInterface->dumpState(fd, args); 221 | } 222 | 223 | // ---------------------------------------------------------------------------- 224 | 225 | A2dpAudioInterface::A2dpAudioStreamOut::A2dpAudioStreamOut() : 226 | mFd(-1), mStandby(true), mStartCount(0), mRetryCount(0), mData(NULL), 227 | // assume BT enabled to start, this is safe because its only the 228 | // enabled->disabled transition we are worried about 229 | mBluetoothEnabled(true), mDevice(0), mClosing(false), mSuspended(false) 230 | { 231 | // use any address by default 232 | strcpy(mA2dpAddress, "00:00:00:00:00:00"); 233 | init(); 234 | } 235 | 236 | status_t A2dpAudioInterface::A2dpAudioStreamOut::set( 237 | uint32_t device, int *pFormat, uint32_t *pChannels, uint32_t *pRate) 238 | { 239 | int lFormat = pFormat ? *pFormat : 0; 240 | uint32_t lChannels = pChannels ? *pChannels : 0; 241 | uint32_t lRate = pRate ? *pRate : 0; 242 | 243 | ALOGD("A2dpAudioStreamOut::set %x, %d, %d, %d\n", device, lFormat, lChannels, lRate); 244 | 245 | // fix up defaults 246 | if (lFormat == 0) lFormat = format(); 247 | if (lChannels == 0) lChannels = channels(); 248 | if (lRate == 0) lRate = sampleRate(); 249 | 250 | // check values 251 | if ((lFormat != format()) || 252 | (lChannels != channels()) || 253 | (lRate != sampleRate())){ 254 | if (pFormat) *pFormat = format(); 255 | if (pChannels) *pChannels = channels(); 256 | if (pRate) *pRate = sampleRate(); 257 | return BAD_VALUE; 258 | } 259 | 260 | if (pFormat) *pFormat = lFormat; 261 | if (pChannels) *pChannels = lChannels; 262 | if (pRate) *pRate = lRate; 263 | 264 | mDevice = device; 265 | mBufferDurationUs = ((bufferSize() * 1000 )/ frameSize() / sampleRate()) * 1000; 266 | return NO_ERROR; 267 | } 268 | 269 | A2dpAudioInterface::A2dpAudioStreamOut::~A2dpAudioStreamOut() 270 | { 271 | ALOGV("A2dpAudioStreamOut destructor"); 272 | close(); 273 | ALOGV("A2dpAudioStreamOut destructor returning from close()"); 274 | } 275 | 276 | ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t bytes) 277 | { 278 | status_t status = -1; 279 | { 280 | Mutex::Autolock lock(mLock); 281 | 282 | size_t remaining = bytes; 283 | 284 | if (!mBluetoothEnabled || mClosing || mSuspended) { 285 | ALOGV("A2dpAudioStreamOut::write(), but bluetooth disabled \ 286 | mBluetoothEnabled %d, mClosing %d, mSuspended %d", 287 | mBluetoothEnabled, mClosing, mSuspended); 288 | goto Error; 289 | } 290 | 291 | if (mStandby) { 292 | acquire_wake_lock (PARTIAL_WAKE_LOCK, sA2dpWakeLock); 293 | mStandby = false; 294 | mLastWriteTime = systemTime(); 295 | } 296 | 297 | status = init(); 298 | if (status < 0) 299 | goto Error; 300 | 301 | int retries = MAX_WRITE_RETRIES; 302 | while (remaining > 0 && retries) { 303 | status = a2dp_write(mData, buffer, remaining); 304 | if (status < 0) { 305 | ALOGE("a2dp_write failed err: %d\n", status); 306 | goto Error; 307 | } 308 | if (status == 0) { 309 | retries--; 310 | } 311 | remaining -= status; 312 | buffer = (char *)buffer + status; 313 | } 314 | 315 | // if A2DP sink runs abnormally fast, sleep a little so that audioflinger mixer thread 316 | // does no spin and starve other threads. 317 | // NOTE: It is likely that the A2DP headset is being disconnected 318 | nsecs_t now = systemTime(); 319 | if ((uint32_t)ns2us(now - mLastWriteTime) < (mBufferDurationUs >> 2)) { 320 | ALOGV("A2DP sink runs too fast"); 321 | usleep(mBufferDurationUs - (uint32_t)ns2us(now - mLastWriteTime)); 322 | } 323 | mLastWriteTime = now; 324 | return bytes; 325 | 326 | } 327 | Error: 328 | 329 | standby(); 330 | 331 | // Simulate audio output timing in case of error 332 | usleep(mBufferDurationUs); 333 | 334 | return status; 335 | } 336 | 337 | status_t A2dpAudioInterface::A2dpAudioStreamOut::init() 338 | { 339 | if (!mData) { 340 | status_t status = a2dp_init(44100, 2, &mData); 341 | if (status < 0) { 342 | ALOGE("a2dp_init failed err: %d\n", status); 343 | mData = NULL; 344 | return status; 345 | } 346 | a2dp_set_sink(mData, mA2dpAddress); 347 | } 348 | 349 | return 0; 350 | } 351 | 352 | status_t A2dpAudioInterface::A2dpAudioStreamOut::standby() 353 | { 354 | Mutex::Autolock lock(mLock); 355 | return standby_l(); 356 | } 357 | 358 | status_t A2dpAudioInterface::A2dpAudioStreamOut::standby_l() 359 | { 360 | int result = NO_ERROR; 361 | 362 | if (!mStandby) { 363 | ALOGV_IF(mClosing || !mBluetoothEnabled, "Standby skip stop: closing %d enabled %d", 364 | mClosing, mBluetoothEnabled); 365 | if (!mClosing && mBluetoothEnabled) { 366 | result = a2dp_stop(mData); 367 | } 368 | release_wake_lock(sA2dpWakeLock); 369 | mStandby = true; 370 | } 371 | 372 | return result; 373 | } 374 | 375 | status_t A2dpAudioInterface::A2dpAudioStreamOut::setParameters(const String8& keyValuePairs) 376 | { 377 | AudioParameter param = AudioParameter(keyValuePairs); 378 | String8 value; 379 | String8 key = String8("a2dp_sink_address"); 380 | status_t status = NO_ERROR; 381 | int device; 382 | ALOGV("A2dpAudioStreamOut::setParameters() %s", keyValuePairs.string()); 383 | 384 | if (param.get(key, value) == NO_ERROR) { 385 | if (value.length() != strlen("00:00:00:00:00:00")) { 386 | status = BAD_VALUE; 387 | } else { 388 | setAddress(value.string()); 389 | } 390 | param.remove(key); 391 | } 392 | key = String8("closing"); 393 | if (param.get(key, value) == NO_ERROR) { 394 | mClosing = (value == "true"); 395 | if (mClosing) { 396 | standby(); 397 | } 398 | param.remove(key); 399 | } 400 | key = AudioParameter::keyRouting; 401 | if (param.getInt(key, device) == NO_ERROR) { 402 | if (audio_is_a2dp_out_device(device)) { 403 | mDevice = device; 404 | status = NO_ERROR; 405 | } else { 406 | status = BAD_VALUE; 407 | } 408 | param.remove(key); 409 | } 410 | 411 | if (param.size()) { 412 | status = BAD_VALUE; 413 | } 414 | return status; 415 | } 416 | 417 | String8 A2dpAudioInterface::A2dpAudioStreamOut::getParameters(const String8& keys) 418 | { 419 | AudioParameter param = AudioParameter(keys); 420 | String8 value; 421 | String8 key = String8("a2dp_sink_address"); 422 | 423 | if (param.get(key, value) == NO_ERROR) { 424 | value = mA2dpAddress; 425 | param.add(key, value); 426 | } 427 | key = AudioParameter::keyRouting; 428 | if (param.get(key, value) == NO_ERROR) { 429 | param.addInt(key, (int)mDevice); 430 | } 431 | 432 | ALOGV("A2dpAudioStreamOut::getParameters() %s", param.toString().string()); 433 | return param.toString(); 434 | } 435 | 436 | status_t A2dpAudioInterface::A2dpAudioStreamOut::setAddress(const char* address) 437 | { 438 | Mutex::Autolock lock(mLock); 439 | 440 | if (strlen(address) != strlen("00:00:00:00:00:00")) 441 | return -EINVAL; 442 | 443 | strcpy(mA2dpAddress, address); 444 | if (mData) 445 | a2dp_set_sink(mData, mA2dpAddress); 446 | 447 | return NO_ERROR; 448 | } 449 | 450 | status_t A2dpAudioInterface::A2dpAudioStreamOut::setBluetoothEnabled(bool enabled) 451 | { 452 | ALOGD("setBluetoothEnabled %d", enabled); 453 | 454 | Mutex::Autolock lock(mLock); 455 | 456 | mBluetoothEnabled = enabled; 457 | if (!enabled) { 458 | return close_l(); 459 | } 460 | return NO_ERROR; 461 | } 462 | 463 | status_t A2dpAudioInterface::A2dpAudioStreamOut::setSuspended(bool onOff) 464 | { 465 | ALOGV("setSuspended %d", onOff); 466 | mSuspended = onOff; 467 | standby(); 468 | return NO_ERROR; 469 | } 470 | 471 | status_t A2dpAudioInterface::A2dpAudioStreamOut::close() 472 | { 473 | Mutex::Autolock lock(mLock); 474 | ALOGV("A2dpAudioStreamOut::close() calling close_l()"); 475 | return close_l(); 476 | } 477 | 478 | status_t A2dpAudioInterface::A2dpAudioStreamOut::close_l() 479 | { 480 | standby_l(); 481 | if (mData) { 482 | ALOGV("A2dpAudioStreamOut::close_l() calling a2dp_cleanup(mData)"); 483 | a2dp_cleanup(mData); 484 | mData = NULL; 485 | } 486 | return NO_ERROR; 487 | } 488 | 489 | status_t A2dpAudioInterface::A2dpAudioStreamOut::dump(int fd, const Vector& args) 490 | { 491 | return NO_ERROR; 492 | } 493 | 494 | status_t A2dpAudioInterface::A2dpAudioStreamOut::getRenderPosition(uint32_t *driverFrames) 495 | { 496 | //TODO: enable when supported by driver 497 | return INVALID_OPERATION; 498 | } 499 | 500 | }; // namespace android 501 | -------------------------------------------------------------------------------- /audio/A2dpAudioInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef A2DP_AUDIO_HARDWARE_H 18 | #define A2DP_AUDIO_HARDWARE_H 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | 27 | 28 | namespace android_audio_legacy { 29 | using android::Mutex; 30 | 31 | class A2dpAudioInterface : public AudioHardwareBase 32 | { 33 | class A2dpAudioStreamOut; 34 | 35 | public: 36 | A2dpAudioInterface(AudioHardwareInterface* hw); 37 | virtual ~A2dpAudioInterface(); 38 | virtual status_t initCheck(); 39 | 40 | virtual status_t setVoiceVolume(float volume); 41 | virtual status_t setMasterVolume(float volume); 42 | 43 | virtual status_t setMode(int mode); 44 | 45 | // mic mute 46 | virtual status_t setMicMute(bool state); 47 | virtual status_t getMicMute(bool* state); 48 | 49 | virtual status_t setParameters(const String8& keyValuePairs); 50 | virtual String8 getParameters(const String8& keys); 51 | 52 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); 53 | 54 | // create I/O streams 55 | virtual AudioStreamOut* openOutputStream( 56 | uint32_t devices, 57 | int *format=0, 58 | uint32_t *channels=0, 59 | uint32_t *sampleRate=0, 60 | status_t *status=0); 61 | virtual void closeOutputStream(AudioStreamOut* out); 62 | 63 | virtual AudioStreamIn* openInputStream( 64 | uint32_t devices, 65 | int *format, 66 | uint32_t *channels, 67 | uint32_t *sampleRate, 68 | status_t *status, 69 | AudioSystem::audio_in_acoustics acoustics); 70 | virtual void closeInputStream(AudioStreamIn* in); 71 | // static AudioHardwareInterface* createA2dpInterface(); 72 | 73 | protected: 74 | virtual status_t dump(int fd, const Vector& args); 75 | 76 | private: 77 | class A2dpAudioStreamOut : public AudioStreamOut { 78 | public: 79 | A2dpAudioStreamOut(); 80 | virtual ~A2dpAudioStreamOut(); 81 | status_t set(uint32_t device, 82 | int *pFormat, 83 | uint32_t *pChannels, 84 | uint32_t *pRate); 85 | virtual uint32_t sampleRate() const { return 44100; } 86 | // SBC codec wants a multiple of 512 87 | virtual size_t bufferSize() const { return 512 * 20; } 88 | virtual uint32_t channels() const { return AudioSystem::CHANNEL_OUT_STEREO; } 89 | virtual int format() const { return AudioSystem::PCM_16_BIT; } 90 | virtual uint32_t latency() const { return ((1000*bufferSize())/frameSize())/sampleRate() + 200; } 91 | virtual status_t setVolume(float left, float right) { return INVALID_OPERATION; } 92 | virtual ssize_t write(const void* buffer, size_t bytes); 93 | status_t standby(); 94 | virtual status_t dump(int fd, const Vector& args); 95 | virtual status_t setParameters(const String8& keyValuePairs); 96 | virtual String8 getParameters(const String8& keys); 97 | virtual status_t getRenderPosition(uint32_t *dspFrames); 98 | 99 | private: 100 | friend class A2dpAudioInterface; 101 | status_t init(); 102 | status_t close(); 103 | status_t close_l(); 104 | status_t setAddress(const char* address); 105 | status_t setBluetoothEnabled(bool enabled); 106 | status_t setSuspended(bool onOff); 107 | status_t standby_l(); 108 | 109 | private: 110 | int mFd; 111 | bool mStandby; 112 | int mStartCount; 113 | int mRetryCount; 114 | char mA2dpAddress[20]; 115 | void* mData; 116 | Mutex mLock; 117 | bool mBluetoothEnabled; 118 | uint32_t mDevice; 119 | bool mClosing; 120 | bool mSuspended; 121 | nsecs_t mLastWriteTime; 122 | uint32_t mBufferDurationUs; 123 | }; 124 | 125 | friend class A2dpAudioStreamOut; 126 | 127 | A2dpAudioStreamOut* mOutput; 128 | AudioHardwareInterface *mHardwareInterface; 129 | char mA2dpAddress[20]; 130 | bool mBluetoothEnabled; 131 | bool mSuspended; 132 | }; 133 | 134 | 135 | // ---------------------------------------------------------------------------- 136 | 137 | }; // namespace android 138 | 139 | #endif // A2DP_AUDIO_HARDWARE_H 140 | -------------------------------------------------------------------------------- /audio/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2011 The Android Open Source Project 2 | 3 | #AUDIO_POLICY_TEST := true 4 | #ENABLE_AUDIO_DUMP := true 5 | 6 | LOCAL_PATH := $(call my-dir) 7 | include $(CLEAR_VARS) 8 | 9 | LOCAL_SRC_FILES := \ 10 | AudioHardwareInterface.cpp \ 11 | audio_hw_hal.cpp 12 | 13 | LOCAL_MODULE := libaudiohw_legacy 14 | LOCAL_STATIC_LIBRARIES := libmedia_helper 15 | LOCAL_CFLAGS := -Wno-unused-parameter -Wno-gnu-designator 16 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include 17 | LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../include 18 | 19 | include $(BUILD_STATIC_LIBRARY) 20 | 21 | include $(CLEAR_VARS) 22 | 23 | LOCAL_SRC_FILES := \ 24 | AudioPolicyManagerBase.cpp \ 25 | AudioPolicyCompatClient.cpp \ 26 | audio_policy_hal.cpp 27 | 28 | ifeq ($(AUDIO_POLICY_TEST),true) 29 | LOCAL_CFLAGS += -DAUDIO_POLICY_TEST 30 | endif 31 | 32 | LOCAL_STATIC_LIBRARIES := libmedia_helper 33 | LOCAL_MODULE := libaudiopolicy_legacy 34 | LOCAL_CFLAGS += -Wno-unused-parameter 35 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include 36 | LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../include 37 | 38 | include $(BUILD_STATIC_LIBRARY) 39 | 40 | # The default audio policy, for now still implemented on top of legacy 41 | # policy code 42 | include $(CLEAR_VARS) 43 | 44 | LOCAL_SRC_FILES := \ 45 | AudioPolicyManagerDefault.cpp 46 | 47 | LOCAL_SHARED_LIBRARIES := \ 48 | libcutils \ 49 | libutils \ 50 | liblog 51 | 52 | LOCAL_STATIC_LIBRARIES := \ 53 | libmedia_helper 54 | 55 | LOCAL_WHOLE_STATIC_LIBRARIES := \ 56 | libaudiopolicy_legacy 57 | 58 | LOCAL_MODULE := audio_policy.default 59 | LOCAL_MODULE_RELATIVE_PATH := hw 60 | LOCAL_CFLAGS := -Wno-unused-parameter 61 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include 62 | 63 | include $(BUILD_SHARED_LIBRARY) 64 | 65 | #ifeq ($(ENABLE_AUDIO_DUMP),true) 66 | # LOCAL_SRC_FILES += AudioDumpInterface.cpp 67 | # LOCAL_CFLAGS += -DENABLE_AUDIO_DUMP 68 | #endif 69 | # 70 | #ifeq ($(strip $(BOARD_USES_GENERIC_AUDIO)),true) 71 | # LOCAL_CFLAGS += -D GENERIC_AUDIO 72 | #endif 73 | 74 | #ifeq ($(BOARD_HAVE_BLUETOOTH),true) 75 | # LOCAL_SRC_FILES += A2dpAudioInterface.cpp 76 | # LOCAL_SHARED_LIBRARIES += liba2dp 77 | # LOCAL_C_INCLUDES += $(call include-path-for, bluez) 78 | # 79 | # LOCAL_CFLAGS += \ 80 | # -DWITH_BLUETOOTH \ 81 | #endif 82 | # 83 | #include $(BUILD_SHARED_LIBRARY) 84 | 85 | # AudioHardwareGeneric.cpp \ 86 | # AudioHardwareStub.cpp \ 87 | -------------------------------------------------------------------------------- /audio/AudioDumpInterface.h: -------------------------------------------------------------------------------- 1 | /* //device/servers/AudioFlinger/AudioDumpInterface.h 2 | ** 3 | ** Copyright 2008, The Android Open Source Project 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | #ifndef ANDROID_AUDIO_DUMP_INTERFACE_H 19 | #define ANDROID_AUDIO_DUMP_INTERFACE_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | namespace android { 29 | 30 | #define AUDIO_DUMP_WAVE_HDR_SIZE 44 31 | 32 | class AudioDumpInterface; 33 | 34 | class AudioStreamOutDump : public AudioStreamOut { 35 | public: 36 | AudioStreamOutDump(AudioDumpInterface *interface, 37 | int id, 38 | AudioStreamOut* finalStream, 39 | uint32_t devices, 40 | int format, 41 | uint32_t channels, 42 | uint32_t sampleRate); 43 | ~AudioStreamOutDump(); 44 | 45 | virtual ssize_t write(const void* buffer, size_t bytes); 46 | virtual uint32_t sampleRate() const; 47 | virtual size_t bufferSize() const; 48 | virtual uint32_t channels() const; 49 | virtual int format() const; 50 | virtual uint32_t latency() const; 51 | virtual status_t setVolume(float left, float right); 52 | virtual status_t standby(); 53 | virtual status_t setParameters(const String8& keyValuePairs); 54 | virtual String8 getParameters(const String8& keys); 55 | virtual status_t dump(int fd, const Vector& args); 56 | void Close(void); 57 | AudioStreamOut* finalStream() { return mFinalStream; } 58 | uint32_t device() { return mDevice; } 59 | int getId() { return mId; } 60 | virtual status_t getRenderPosition(uint32_t *dspFrames); 61 | 62 | private: 63 | AudioDumpInterface *mInterface; 64 | int mId; 65 | uint32_t mSampleRate; // 66 | uint32_t mFormat; // 67 | uint32_t mChannels; // output configuration 68 | uint32_t mLatency; // 69 | uint32_t mDevice; // current device this output is routed to 70 | size_t mBufferSize; 71 | AudioStreamOut *mFinalStream; 72 | FILE *mFile; // output file 73 | int mFileCount; 74 | }; 75 | 76 | class AudioStreamInDump : public AudioStreamIn { 77 | public: 78 | AudioStreamInDump(AudioDumpInterface *interface, 79 | int id, 80 | AudioStreamIn* finalStream, 81 | uint32_t devices, 82 | int format, 83 | uint32_t channels, 84 | uint32_t sampleRate); 85 | ~AudioStreamInDump(); 86 | 87 | virtual uint32_t sampleRate() const; 88 | virtual size_t bufferSize() const; 89 | virtual uint32_t channels() const; 90 | virtual int format() const; 91 | 92 | virtual status_t setGain(float gain); 93 | virtual ssize_t read(void* buffer, ssize_t bytes); 94 | virtual status_t standby(); 95 | virtual status_t setParameters(const String8& keyValuePairs); 96 | virtual String8 getParameters(const String8& keys); 97 | virtual unsigned int getInputFramesLost() const; 98 | virtual status_t dump(int fd, const Vector& args); 99 | void Close(void); 100 | AudioStreamIn* finalStream() { return mFinalStream; } 101 | uint32_t device() { return mDevice; } 102 | 103 | private: 104 | AudioDumpInterface *mInterface; 105 | int mId; 106 | uint32_t mSampleRate; // 107 | uint32_t mFormat; // 108 | uint32_t mChannels; // output configuration 109 | uint32_t mDevice; // current device this output is routed to 110 | size_t mBufferSize; 111 | AudioStreamIn *mFinalStream; 112 | FILE *mFile; // output file 113 | int mFileCount; 114 | }; 115 | 116 | class AudioDumpInterface : public AudioHardwareBase 117 | { 118 | 119 | public: 120 | AudioDumpInterface(AudioHardwareInterface* hw); 121 | virtual AudioStreamOut* openOutputStream( 122 | uint32_t devices, 123 | int *format=0, 124 | uint32_t *channels=0, 125 | uint32_t *sampleRate=0, 126 | status_t *status=0); 127 | virtual void closeOutputStream(AudioStreamOut* out); 128 | 129 | virtual ~AudioDumpInterface(); 130 | 131 | virtual status_t initCheck() 132 | {return mFinalInterface->initCheck();} 133 | virtual status_t setVoiceVolume(float volume) 134 | {return mFinalInterface->setVoiceVolume(volume);} 135 | virtual status_t setMasterVolume(float volume) 136 | {return mFinalInterface->setMasterVolume(volume);} 137 | 138 | virtual status_t setMode(int mode); 139 | 140 | // mic mute 141 | virtual status_t setMicMute(bool state) 142 | {return mFinalInterface->setMicMute(state);} 143 | virtual status_t getMicMute(bool* state) 144 | {return mFinalInterface->getMicMute(state);} 145 | 146 | virtual status_t setParameters(const String8& keyValuePairs); 147 | virtual String8 getParameters(const String8& keys); 148 | 149 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); 150 | 151 | virtual AudioStreamIn* openInputStream(uint32_t devices, int *format, uint32_t *channels, 152 | uint32_t *sampleRate, status_t *status, AudioSystem::audio_in_acoustics acoustics); 153 | virtual void closeInputStream(AudioStreamIn* in); 154 | 155 | virtual status_t dump(int fd, const Vector& args) { return mFinalInterface->dumpState(fd, args); } 156 | 157 | String8 fileName() const { return mFileName; } 158 | protected: 159 | 160 | AudioHardwareInterface *mFinalInterface; 161 | SortedVector mOutputs; 162 | SortedVector mInputs; 163 | Mutex mLock; 164 | String8 mPolicyCommands; 165 | String8 mFileName; 166 | }; 167 | 168 | }; // namespace android 169 | 170 | #endif // ANDROID_AUDIO_DUMP_INTERFACE_H 171 | -------------------------------------------------------------------------------- /audio/AudioHardwareGeneric.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** 3 | ** Copyright 2007, The Android Open Source Project 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define LOG_TAG "AudioHardware" 29 | #include 30 | #include 31 | 32 | #include "AudioHardwareGeneric.h" 33 | #include 34 | 35 | #include 36 | 37 | namespace android_audio_legacy { 38 | 39 | // ---------------------------------------------------------------------------- 40 | 41 | static char const * const kAudioDeviceName = "/dev/eac"; 42 | 43 | // ---------------------------------------------------------------------------- 44 | 45 | AudioHardwareGeneric::AudioHardwareGeneric() 46 | : mOutput(0), mInput(0), mFd(-1), mMicMute(false) 47 | { 48 | mFd = ::open(kAudioDeviceName, O_RDWR); 49 | } 50 | 51 | AudioHardwareGeneric::~AudioHardwareGeneric() 52 | { 53 | if (mFd >= 0) ::close(mFd); 54 | closeOutputStream((AudioStreamOut *)mOutput); 55 | closeInputStream((AudioStreamIn *)mInput); 56 | } 57 | 58 | status_t AudioHardwareGeneric::initCheck() 59 | { 60 | if (mFd >= 0) { 61 | if (::access(kAudioDeviceName, O_RDWR) == NO_ERROR) 62 | return NO_ERROR; 63 | } 64 | return NO_INIT; 65 | } 66 | 67 | AudioStreamOut* AudioHardwareGeneric::openOutputStream( 68 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status) 69 | { 70 | AutoMutex lock(mLock); 71 | 72 | // only one output stream allowed 73 | if (mOutput) { 74 | if (status) { 75 | *status = INVALID_OPERATION; 76 | } 77 | return 0; 78 | } 79 | 80 | // create new output stream 81 | AudioStreamOutGeneric* out = new AudioStreamOutGeneric(); 82 | status_t lStatus = out->set(this, mFd, devices, format, channels, sampleRate); 83 | if (status) { 84 | *status = lStatus; 85 | } 86 | if (lStatus == NO_ERROR) { 87 | mOutput = out; 88 | } else { 89 | delete out; 90 | } 91 | return mOutput; 92 | } 93 | 94 | void AudioHardwareGeneric::closeOutputStream(AudioStreamOut* out) { 95 | if (mOutput && out == mOutput) { 96 | delete mOutput; 97 | mOutput = 0; 98 | } 99 | } 100 | 101 | AudioStreamIn* AudioHardwareGeneric::openInputStream( 102 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, 103 | status_t *status, AudioSystem::audio_in_acoustics acoustics) 104 | { 105 | // check for valid input source 106 | if (!AudioSystem::isInputDevice((AudioSystem::audio_devices)devices)) { 107 | return 0; 108 | } 109 | 110 | AutoMutex lock(mLock); 111 | 112 | // only one input stream allowed 113 | if (mInput) { 114 | if (status) { 115 | *status = INVALID_OPERATION; 116 | } 117 | return 0; 118 | } 119 | 120 | // create new output stream 121 | AudioStreamInGeneric* in = new AudioStreamInGeneric(); 122 | status_t lStatus = in->set(this, mFd, devices, format, channels, sampleRate, acoustics); 123 | if (status) { 124 | *status = lStatus; 125 | } 126 | if (lStatus == NO_ERROR) { 127 | mInput = in; 128 | } else { 129 | delete in; 130 | } 131 | return mInput; 132 | } 133 | 134 | void AudioHardwareGeneric::closeInputStream(AudioStreamIn* in) { 135 | if (mInput && in == mInput) { 136 | delete mInput; 137 | mInput = 0; 138 | } 139 | } 140 | 141 | status_t AudioHardwareGeneric::setVoiceVolume(float v) 142 | { 143 | // Implement: set voice volume 144 | return NO_ERROR; 145 | } 146 | 147 | status_t AudioHardwareGeneric::setMasterVolume(float v) 148 | { 149 | // Implement: set master volume 150 | // return error - software mixer will handle it 151 | return INVALID_OPERATION; 152 | } 153 | 154 | status_t AudioHardwareGeneric::setMicMute(bool state) 155 | { 156 | mMicMute = state; 157 | return NO_ERROR; 158 | } 159 | 160 | status_t AudioHardwareGeneric::getMicMute(bool* state) 161 | { 162 | *state = mMicMute; 163 | return NO_ERROR; 164 | } 165 | 166 | status_t AudioHardwareGeneric::dumpInternals(int fd, const Vector& args) 167 | { 168 | const size_t SIZE = 256; 169 | char buffer[SIZE]; 170 | String8 result; 171 | result.append("AudioHardwareGeneric::dumpInternals\n"); 172 | snprintf(buffer, SIZE, "\tmFd: %d mMicMute: %s\n", mFd, mMicMute? "true": "false"); 173 | result.append(buffer); 174 | ::write(fd, result.string(), result.size()); 175 | return NO_ERROR; 176 | } 177 | 178 | status_t AudioHardwareGeneric::dump(int fd, const Vector& args) 179 | { 180 | dumpInternals(fd, args); 181 | if (mInput) { 182 | mInput->dump(fd, args); 183 | } 184 | if (mOutput) { 185 | mOutput->dump(fd, args); 186 | } 187 | return NO_ERROR; 188 | } 189 | 190 | // ---------------------------------------------------------------------------- 191 | 192 | status_t AudioStreamOutGeneric::set( 193 | AudioHardwareGeneric *hw, 194 | int fd, 195 | uint32_t devices, 196 | int *pFormat, 197 | uint32_t *pChannels, 198 | uint32_t *pRate) 199 | { 200 | int lFormat = pFormat ? *pFormat : 0; 201 | uint32_t lChannels = pChannels ? *pChannels : 0; 202 | uint32_t lRate = pRate ? *pRate : 0; 203 | 204 | // fix up defaults 205 | if (lFormat == 0) lFormat = format(); 206 | if (lChannels == 0) lChannels = channels(); 207 | if (lRate == 0) lRate = sampleRate(); 208 | 209 | // check values 210 | if ((lFormat != format()) || 211 | (lChannels != channels()) || 212 | (lRate != sampleRate())) { 213 | if (pFormat) *pFormat = format(); 214 | if (pChannels) *pChannels = channels(); 215 | if (pRate) *pRate = sampleRate(); 216 | return BAD_VALUE; 217 | } 218 | 219 | if (pFormat) *pFormat = lFormat; 220 | if (pChannels) *pChannels = lChannels; 221 | if (pRate) *pRate = lRate; 222 | 223 | mAudioHardware = hw; 224 | mFd = fd; 225 | mDevice = devices; 226 | return NO_ERROR; 227 | } 228 | 229 | AudioStreamOutGeneric::~AudioStreamOutGeneric() 230 | { 231 | } 232 | 233 | ssize_t AudioStreamOutGeneric::write(const void* buffer, size_t bytes) 234 | { 235 | Mutex::Autolock _l(mLock); 236 | return ssize_t(::write(mFd, buffer, bytes)); 237 | } 238 | 239 | status_t AudioStreamOutGeneric::standby() 240 | { 241 | // Implement: audio hardware to standby mode 242 | return NO_ERROR; 243 | } 244 | 245 | status_t AudioStreamOutGeneric::dump(int fd, const Vector& args) 246 | { 247 | const size_t SIZE = 256; 248 | char buffer[SIZE]; 249 | String8 result; 250 | snprintf(buffer, SIZE, "AudioStreamOutGeneric::dump\n"); 251 | result.append(buffer); 252 | snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate()); 253 | result.append(buffer); 254 | snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize()); 255 | result.append(buffer); 256 | snprintf(buffer, SIZE, "\tchannels: %d\n", channels()); 257 | result.append(buffer); 258 | snprintf(buffer, SIZE, "\tformat: %d\n", format()); 259 | result.append(buffer); 260 | snprintf(buffer, SIZE, "\tdevice: %d\n", mDevice); 261 | result.append(buffer); 262 | snprintf(buffer, SIZE, "\tmAudioHardware: %p\n", mAudioHardware); 263 | result.append(buffer); 264 | snprintf(buffer, SIZE, "\tmFd: %d\n", mFd); 265 | result.append(buffer); 266 | ::write(fd, result.string(), result.size()); 267 | return NO_ERROR; 268 | } 269 | 270 | status_t AudioStreamOutGeneric::setParameters(const String8& keyValuePairs) 271 | { 272 | AudioParameter param = AudioParameter(keyValuePairs); 273 | String8 key = String8(AudioParameter::keyRouting); 274 | status_t status = NO_ERROR; 275 | int device; 276 | ALOGV("setParameters() %s", keyValuePairs.string()); 277 | 278 | if (param.getInt(key, device) == NO_ERROR) { 279 | mDevice = device; 280 | param.remove(key); 281 | } 282 | 283 | if (param.size()) { 284 | status = BAD_VALUE; 285 | } 286 | return status; 287 | } 288 | 289 | String8 AudioStreamOutGeneric::getParameters(const String8& keys) 290 | { 291 | AudioParameter param = AudioParameter(keys); 292 | String8 value; 293 | String8 key = String8(AudioParameter::keyRouting); 294 | 295 | if (param.get(key, value) == NO_ERROR) { 296 | param.addInt(key, (int)mDevice); 297 | } 298 | 299 | ALOGV("getParameters() %s", param.toString().string()); 300 | return param.toString(); 301 | } 302 | 303 | status_t AudioStreamOutGeneric::getRenderPosition(uint32_t *dspFrames) 304 | { 305 | return INVALID_OPERATION; 306 | } 307 | 308 | // ---------------------------------------------------------------------------- 309 | 310 | // record functions 311 | status_t AudioStreamInGeneric::set( 312 | AudioHardwareGeneric *hw, 313 | int fd, 314 | uint32_t devices, 315 | int *pFormat, 316 | uint32_t *pChannels, 317 | uint32_t *pRate, 318 | AudioSystem::audio_in_acoustics acoustics) 319 | { 320 | if (pFormat == 0 || pChannels == 0 || pRate == 0) return BAD_VALUE; 321 | ALOGV("AudioStreamInGeneric::set(%p, %d, %d, %d, %u)", hw, fd, *pFormat, *pChannels, *pRate); 322 | // check values 323 | if ((*pFormat != format()) || 324 | (*pChannels != channels()) || 325 | (*pRate != sampleRate())) { 326 | ALOGE("Error opening input channel"); 327 | *pFormat = format(); 328 | *pChannels = channels(); 329 | *pRate = sampleRate(); 330 | return BAD_VALUE; 331 | } 332 | 333 | mAudioHardware = hw; 334 | mFd = fd; 335 | mDevice = devices; 336 | return NO_ERROR; 337 | } 338 | 339 | AudioStreamInGeneric::~AudioStreamInGeneric() 340 | { 341 | } 342 | 343 | ssize_t AudioStreamInGeneric::read(void* buffer, ssize_t bytes) 344 | { 345 | AutoMutex lock(mLock); 346 | if (mFd < 0) { 347 | ALOGE("Attempt to read from unopened device"); 348 | return NO_INIT; 349 | } 350 | return ::read(mFd, buffer, bytes); 351 | } 352 | 353 | status_t AudioStreamInGeneric::dump(int fd, const Vector& args) 354 | { 355 | const size_t SIZE = 256; 356 | char buffer[SIZE]; 357 | String8 result; 358 | snprintf(buffer, SIZE, "AudioStreamInGeneric::dump\n"); 359 | result.append(buffer); 360 | snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate()); 361 | result.append(buffer); 362 | snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize()); 363 | result.append(buffer); 364 | snprintf(buffer, SIZE, "\tchannels: %d\n", channels()); 365 | result.append(buffer); 366 | snprintf(buffer, SIZE, "\tformat: %d\n", format()); 367 | result.append(buffer); 368 | snprintf(buffer, SIZE, "\tdevice: %d\n", mDevice); 369 | result.append(buffer); 370 | snprintf(buffer, SIZE, "\tmAudioHardware: %p\n", mAudioHardware); 371 | result.append(buffer); 372 | snprintf(buffer, SIZE, "\tmFd: %d\n", mFd); 373 | result.append(buffer); 374 | ::write(fd, result.string(), result.size()); 375 | return NO_ERROR; 376 | } 377 | 378 | status_t AudioStreamInGeneric::setParameters(const String8& keyValuePairs) 379 | { 380 | AudioParameter param = AudioParameter(keyValuePairs); 381 | String8 key = String8(AudioParameter::keyRouting); 382 | status_t status = NO_ERROR; 383 | int device; 384 | ALOGV("setParameters() %s", keyValuePairs.string()); 385 | 386 | if (param.getInt(key, device) == NO_ERROR) { 387 | mDevice = device; 388 | param.remove(key); 389 | } 390 | 391 | if (param.size()) { 392 | status = BAD_VALUE; 393 | } 394 | return status; 395 | } 396 | 397 | String8 AudioStreamInGeneric::getParameters(const String8& keys) 398 | { 399 | AudioParameter param = AudioParameter(keys); 400 | String8 value; 401 | String8 key = String8(AudioParameter::keyRouting); 402 | 403 | if (param.get(key, value) == NO_ERROR) { 404 | param.addInt(key, (int)mDevice); 405 | } 406 | 407 | ALOGV("getParameters() %s", param.toString().string()); 408 | return param.toString(); 409 | } 410 | 411 | // ---------------------------------------------------------------------------- 412 | 413 | }; // namespace android 414 | -------------------------------------------------------------------------------- /audio/AudioHardwareGeneric.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 3 | ** Copyright 2007, The Android Open Source Project 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | #ifndef ANDROID_AUDIO_HARDWARE_GENERIC_H 19 | #define ANDROID_AUDIO_HARDWARE_GENERIC_H 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | namespace android_audio_legacy { 30 | using android::Mutex; 31 | using android::AutoMutex; 32 | 33 | // ---------------------------------------------------------------------------- 34 | 35 | class AudioHardwareGeneric; 36 | 37 | class AudioStreamOutGeneric : public AudioStreamOut { 38 | public: 39 | AudioStreamOutGeneric() : mAudioHardware(0), mFd(-1) {} 40 | virtual ~AudioStreamOutGeneric(); 41 | 42 | virtual status_t set( 43 | AudioHardwareGeneric *hw, 44 | int mFd, 45 | uint32_t devices, 46 | int *pFormat, 47 | uint32_t *pChannels, 48 | uint32_t *pRate); 49 | 50 | virtual uint32_t sampleRate() const { return 44100; } 51 | virtual size_t bufferSize() const { return 4096; } 52 | virtual uint32_t channels() const { return AudioSystem::CHANNEL_OUT_STEREO; } 53 | virtual int format() const { return AudioSystem::PCM_16_BIT; } 54 | virtual uint32_t latency() const { return 20; } 55 | virtual status_t setVolume(float left, float right) { return INVALID_OPERATION; } 56 | virtual ssize_t write(const void* buffer, size_t bytes); 57 | virtual status_t standby(); 58 | virtual status_t dump(int fd, const Vector& args); 59 | virtual status_t setParameters(const String8& keyValuePairs); 60 | virtual String8 getParameters(const String8& keys); 61 | virtual status_t getRenderPosition(uint32_t *dspFrames); 62 | 63 | private: 64 | AudioHardwareGeneric *mAudioHardware; 65 | Mutex mLock; 66 | int mFd; 67 | uint32_t mDevice; 68 | }; 69 | 70 | class AudioStreamInGeneric : public AudioStreamIn { 71 | public: 72 | AudioStreamInGeneric() : mAudioHardware(0), mFd(-1) {} 73 | virtual ~AudioStreamInGeneric(); 74 | 75 | virtual status_t set( 76 | AudioHardwareGeneric *hw, 77 | int mFd, 78 | uint32_t devices, 79 | int *pFormat, 80 | uint32_t *pChannels, 81 | uint32_t *pRate, 82 | AudioSystem::audio_in_acoustics acoustics); 83 | 84 | virtual uint32_t sampleRate() const { return 8000; } 85 | virtual size_t bufferSize() const { return 320; } 86 | virtual uint32_t channels() const { return AudioSystem::CHANNEL_IN_MONO; } 87 | virtual int format() const { return AudioSystem::PCM_16_BIT; } 88 | virtual status_t setGain(float gain) { return INVALID_OPERATION; } 89 | virtual ssize_t read(void* buffer, ssize_t bytes); 90 | virtual status_t dump(int fd, const Vector& args); 91 | virtual status_t standby() { return NO_ERROR; } 92 | virtual status_t setParameters(const String8& keyValuePairs); 93 | virtual String8 getParameters(const String8& keys); 94 | virtual unsigned int getInputFramesLost() const { return 0; } 95 | virtual status_t addAudioEffect(effect_handle_t effect) { return NO_ERROR; } 96 | virtual status_t removeAudioEffect(effect_handle_t effect) { return NO_ERROR; } 97 | 98 | private: 99 | AudioHardwareGeneric *mAudioHardware; 100 | Mutex mLock; 101 | int mFd; 102 | uint32_t mDevice; 103 | }; 104 | 105 | 106 | class AudioHardwareGeneric : public AudioHardwareBase 107 | { 108 | public: 109 | AudioHardwareGeneric(); 110 | virtual ~AudioHardwareGeneric(); 111 | virtual status_t initCheck(); 112 | virtual status_t setVoiceVolume(float volume); 113 | virtual status_t setMasterVolume(float volume); 114 | 115 | // mic mute 116 | virtual status_t setMicMute(bool state); 117 | virtual status_t getMicMute(bool* state); 118 | 119 | // create I/O streams 120 | virtual AudioStreamOut* openOutputStream( 121 | uint32_t devices, 122 | int *format=0, 123 | uint32_t *channels=0, 124 | uint32_t *sampleRate=0, 125 | status_t *status=0); 126 | virtual void closeOutputStream(AudioStreamOut* out); 127 | 128 | virtual AudioStreamIn* openInputStream( 129 | uint32_t devices, 130 | int *format, 131 | uint32_t *channels, 132 | uint32_t *sampleRate, 133 | status_t *status, 134 | AudioSystem::audio_in_acoustics acoustics); 135 | virtual void closeInputStream(AudioStreamIn* in); 136 | 137 | void closeOutputStream(AudioStreamOutGeneric* out); 138 | void closeInputStream(AudioStreamInGeneric* in); 139 | protected: 140 | virtual status_t dump(int fd, const Vector& args); 141 | 142 | private: 143 | status_t dumpInternals(int fd, const Vector& args); 144 | 145 | Mutex mLock; 146 | AudioStreamOutGeneric *mOutput; 147 | AudioStreamInGeneric *mInput; 148 | int mFd; 149 | bool mMicMute; 150 | }; 151 | 152 | // ---------------------------------------------------------------------------- 153 | 154 | }; // namespace android 155 | 156 | #endif // ANDROID_AUDIO_HARDWARE_GENERIC_H 157 | -------------------------------------------------------------------------------- /audio/AudioHardwareInterface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** 3 | ** Copyright 2007, The Android Open Source Project 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | //#define LOG_NDEBUG 0 22 | 23 | #define LOG_TAG "AudioHardwareInterface" 24 | #include 25 | #include 26 | 27 | #include "AudioHardwareStub.h" 28 | #include "AudioHardwareGeneric.h" 29 | 30 | #ifdef ENABLE_AUDIO_DUMP 31 | #include "AudioDumpInterface.h" 32 | #endif 33 | 34 | 35 | // change to 1 to log routing calls 36 | #define LOG_ROUTING_CALLS 1 37 | 38 | namespace android_audio_legacy { 39 | 40 | #if LOG_ROUTING_CALLS 41 | static const char* routingModeStrings[] = 42 | { 43 | "OUT OF RANGE", 44 | "INVALID", 45 | "CURRENT", 46 | "NORMAL", 47 | "RINGTONE", 48 | "IN_CALL", 49 | "IN_COMMUNICATION" 50 | }; 51 | 52 | static const char* routeNone = "NONE"; 53 | 54 | static const char* displayMode(int mode) 55 | { 56 | if ((mode < AudioSystem::MODE_INVALID) || (mode >= AudioSystem::NUM_MODES)) 57 | return routingModeStrings[0]; 58 | return routingModeStrings[mode+3]; 59 | } 60 | #endif 61 | 62 | // ---------------------------------------------------------------------------- 63 | 64 | AudioHardwareInterface* AudioHardwareInterface::create() 65 | { 66 | return NULL; 67 | } 68 | 69 | AudioStreamOut::~AudioStreamOut() 70 | { 71 | } 72 | 73 | // default implementation is unsupported 74 | status_t AudioStreamOut::getNextWriteTimestamp(int64_t *timestamp) 75 | { 76 | return INVALID_OPERATION; 77 | } 78 | 79 | AudioStreamIn::~AudioStreamIn() {} 80 | 81 | AudioHardwareBase::AudioHardwareBase() 82 | { 83 | mMode = 0; 84 | } 85 | 86 | status_t AudioHardwareBase::setMode(int mode) 87 | { 88 | #if LOG_ROUTING_CALLS 89 | ALOGD("setMode(%s)", displayMode(mode)); 90 | #endif 91 | if ((mode < 0) || (mode >= AudioSystem::NUM_MODES)) 92 | return BAD_VALUE; 93 | if (mMode == mode) 94 | return ALREADY_EXISTS; 95 | mMode = mode; 96 | return NO_ERROR; 97 | } 98 | 99 | // default implementation 100 | status_t AudioHardwareBase::setParameters(const String8& keyValuePairs) 101 | { 102 | return NO_ERROR; 103 | } 104 | 105 | // default implementation 106 | String8 AudioHardwareBase::getParameters(const String8& keys) 107 | { 108 | AudioParameter param = AudioParameter(keys); 109 | return param.toString(); 110 | } 111 | 112 | // default implementation 113 | size_t AudioHardwareBase::getInputBufferSize(uint32_t sampleRate, int format, int channelCount) 114 | { 115 | if (sampleRate != 8000) { 116 | ALOGW("getInputBufferSize bad sampling rate: %d", sampleRate); 117 | return 0; 118 | } 119 | if (format != AudioSystem::PCM_16_BIT) { 120 | ALOGW("getInputBufferSize bad format: %d", format); 121 | return 0; 122 | } 123 | if (channelCount != 1) { 124 | ALOGW("getInputBufferSize bad channel count: %d", channelCount); 125 | return 0; 126 | } 127 | 128 | return 320; 129 | } 130 | 131 | // default implementation is unsupported 132 | status_t AudioHardwareBase::getMasterVolume(float *volume) 133 | { 134 | return INVALID_OPERATION; 135 | } 136 | 137 | status_t AudioHardwareBase::dumpState(int fd, const Vector& args) 138 | { 139 | const size_t SIZE = 256; 140 | char buffer[SIZE]; 141 | String8 result; 142 | snprintf(buffer, SIZE, "AudioHardwareBase::dumpState\n"); 143 | result.append(buffer); 144 | snprintf(buffer, SIZE, "\tmMode: %d\n", mMode); 145 | result.append(buffer); 146 | ::write(fd, result.string(), result.size()); 147 | dump(fd, args); // Dump the state of the concrete child. 148 | return NO_ERROR; 149 | } 150 | 151 | // default implementation calls its "without flags" counterpart 152 | AudioStreamOut* AudioHardwareInterface::openOutputStreamWithFlags(uint32_t devices, 153 | audio_output_flags_t flags, 154 | int *format, 155 | uint32_t *channels, 156 | uint32_t *sampleRate, 157 | status_t *status) 158 | { 159 | return openOutputStream(devices, format, channels, sampleRate, status); 160 | } 161 | 162 | // ---------------------------------------------------------------------------- 163 | 164 | }; // namespace android 165 | -------------------------------------------------------------------------------- /audio/AudioHardwareStub.cpp: -------------------------------------------------------------------------------- 1 | /* //device/servers/AudioFlinger/AudioHardwareStub.cpp 2 | ** 3 | ** Copyright 2007, The Android Open Source Project 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "AudioHardwareStub.h" 26 | #include 27 | 28 | namespace android_audio_legacy { 29 | 30 | // ---------------------------------------------------------------------------- 31 | 32 | AudioHardwareStub::AudioHardwareStub() : mMicMute(false) 33 | { 34 | } 35 | 36 | AudioHardwareStub::~AudioHardwareStub() 37 | { 38 | } 39 | 40 | status_t AudioHardwareStub::initCheck() 41 | { 42 | return NO_ERROR; 43 | } 44 | 45 | AudioStreamOut* AudioHardwareStub::openOutputStream( 46 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status) 47 | { 48 | AudioStreamOutStub* out = new AudioStreamOutStub(); 49 | status_t lStatus = out->set(format, channels, sampleRate); 50 | if (status) { 51 | *status = lStatus; 52 | } 53 | if (lStatus == NO_ERROR) 54 | return out; 55 | delete out; 56 | return 0; 57 | } 58 | 59 | void AudioHardwareStub::closeOutputStream(AudioStreamOut* out) 60 | { 61 | delete out; 62 | } 63 | 64 | AudioStreamIn* AudioHardwareStub::openInputStream( 65 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, 66 | status_t *status, AudioSystem::audio_in_acoustics acoustics) 67 | { 68 | // check for valid input source 69 | if (!AudioSystem::isInputDevice((AudioSystem::audio_devices)devices)) { 70 | return 0; 71 | } 72 | 73 | AudioStreamInStub* in = new AudioStreamInStub(); 74 | status_t lStatus = in->set(format, channels, sampleRate, acoustics); 75 | if (status) { 76 | *status = lStatus; 77 | } 78 | if (lStatus == NO_ERROR) 79 | return in; 80 | delete in; 81 | return 0; 82 | } 83 | 84 | void AudioHardwareStub::closeInputStream(AudioStreamIn* in) 85 | { 86 | delete in; 87 | } 88 | 89 | status_t AudioHardwareStub::setVoiceVolume(float volume) 90 | { 91 | return NO_ERROR; 92 | } 93 | 94 | status_t AudioHardwareStub::setMasterVolume(float volume) 95 | { 96 | return NO_ERROR; 97 | } 98 | 99 | status_t AudioHardwareStub::dumpInternals(int fd, const Vector& args) 100 | { 101 | const size_t SIZE = 256; 102 | char buffer[SIZE]; 103 | String8 result; 104 | result.append("AudioHardwareStub::dumpInternals\n"); 105 | snprintf(buffer, SIZE, "\tmMicMute: %s\n", mMicMute? "true": "false"); 106 | result.append(buffer); 107 | ::write(fd, result.string(), result.size()); 108 | return NO_ERROR; 109 | } 110 | 111 | status_t AudioHardwareStub::dump(int fd, const Vector& args) 112 | { 113 | dumpInternals(fd, args); 114 | return NO_ERROR; 115 | } 116 | 117 | // ---------------------------------------------------------------------------- 118 | 119 | status_t AudioStreamOutStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRate) 120 | { 121 | if (pFormat) *pFormat = format(); 122 | if (pChannels) *pChannels = channels(); 123 | if (pRate) *pRate = sampleRate(); 124 | 125 | return NO_ERROR; 126 | } 127 | 128 | ssize_t AudioStreamOutStub::write(const void* buffer, size_t bytes) 129 | { 130 | // fake timing for audio output 131 | usleep(bytes * 1000000 / sizeof(int16_t) / 132 | audio_channel_count_from_out_mask(channels()) / sampleRate()); 133 | return bytes; 134 | } 135 | 136 | status_t AudioStreamOutStub::standby() 137 | { 138 | return NO_ERROR; 139 | } 140 | 141 | status_t AudioStreamOutStub::dump(int fd, const Vector& args) 142 | { 143 | const size_t SIZE = 256; 144 | char buffer[SIZE]; 145 | String8 result; 146 | snprintf(buffer, SIZE, "AudioStreamOutStub::dump\n"); 147 | snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate()); 148 | snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize()); 149 | snprintf(buffer, SIZE, "\tchannels: %d\n", channels()); 150 | snprintf(buffer, SIZE, "\tformat: %d\n", format()); 151 | result.append(buffer); 152 | ::write(fd, result.string(), result.size()); 153 | return NO_ERROR; 154 | } 155 | 156 | String8 AudioStreamOutStub::getParameters(const String8& keys) 157 | { 158 | AudioParameter param = AudioParameter(keys); 159 | return param.toString(); 160 | } 161 | 162 | status_t AudioStreamOutStub::getRenderPosition(uint32_t *dspFrames) 163 | { 164 | return INVALID_OPERATION; 165 | } 166 | 167 | // ---------------------------------------------------------------------------- 168 | 169 | status_t AudioStreamInStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRate, 170 | AudioSystem::audio_in_acoustics acoustics) 171 | { 172 | return NO_ERROR; 173 | } 174 | 175 | ssize_t AudioStreamInStub::read(void* buffer, ssize_t bytes) 176 | { 177 | // fake timing for audio input 178 | usleep(bytes * 1000000 / sizeof(int16_t) / 179 | audio_channel_count_from_in_mask(channels()) / sampleRate()); 180 | memset(buffer, 0, bytes); 181 | return bytes; 182 | } 183 | 184 | status_t AudioStreamInStub::dump(int fd, const Vector& args) 185 | { 186 | const size_t SIZE = 256; 187 | char buffer[SIZE]; 188 | String8 result; 189 | snprintf(buffer, SIZE, "AudioStreamInStub::dump\n"); 190 | result.append(buffer); 191 | snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate()); 192 | result.append(buffer); 193 | snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize()); 194 | result.append(buffer); 195 | snprintf(buffer, SIZE, "\tchannels: %d\n", channels()); 196 | result.append(buffer); 197 | snprintf(buffer, SIZE, "\tformat: %d\n", format()); 198 | result.append(buffer); 199 | ::write(fd, result.string(), result.size()); 200 | return NO_ERROR; 201 | } 202 | 203 | String8 AudioStreamInStub::getParameters(const String8& keys) 204 | { 205 | AudioParameter param = AudioParameter(keys); 206 | return param.toString(); 207 | } 208 | 209 | AudioHardwareInterface* createAudioHardware(void) { 210 | return new AudioHardwareStub(); 211 | } 212 | 213 | // ---------------------------------------------------------------------------- 214 | 215 | }; // namespace android 216 | -------------------------------------------------------------------------------- /audio/AudioHardwareStub.h: -------------------------------------------------------------------------------- 1 | /* //device/servers/AudioFlinger/AudioHardwareStub.h 2 | ** 3 | ** Copyright 2007, The Android Open Source Project 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | #ifndef ANDROID_AUDIO_HARDWARE_STUB_H 19 | #define ANDROID_AUDIO_HARDWARE_STUB_H 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | namespace android_audio_legacy { 27 | 28 | // ---------------------------------------------------------------------------- 29 | 30 | class AudioStreamOutStub : public AudioStreamOut { 31 | public: 32 | virtual status_t set(int *pFormat, uint32_t *pChannels, uint32_t *pRate); 33 | virtual uint32_t sampleRate() const { return 44100; } 34 | virtual size_t bufferSize() const { return 4096; } 35 | virtual uint32_t channels() const { return AudioSystem::CHANNEL_OUT_STEREO; } 36 | virtual int format() const { return AudioSystem::PCM_16_BIT; } 37 | virtual uint32_t latency() const { return 0; } 38 | virtual status_t setVolume(float left, float right) { return NO_ERROR; } 39 | virtual ssize_t write(const void* buffer, size_t bytes); 40 | virtual status_t standby(); 41 | virtual status_t dump(int fd, const Vector& args); 42 | virtual status_t setParameters(const String8& keyValuePairs) { return NO_ERROR;} 43 | virtual String8 getParameters(const String8& keys); 44 | virtual status_t getRenderPosition(uint32_t *dspFrames); 45 | }; 46 | 47 | class AudioStreamInStub : public AudioStreamIn { 48 | public: 49 | virtual status_t set(int *pFormat, uint32_t *pChannels, uint32_t *pRate, AudioSystem::audio_in_acoustics acoustics); 50 | virtual uint32_t sampleRate() const { return 8000; } 51 | virtual size_t bufferSize() const { return 320; } 52 | virtual uint32_t channels() const { return AudioSystem::CHANNEL_IN_MONO; } 53 | virtual int format() const { return AudioSystem::PCM_16_BIT; } 54 | virtual status_t setGain(float gain) { return NO_ERROR; } 55 | virtual ssize_t read(void* buffer, ssize_t bytes); 56 | virtual status_t dump(int fd, const Vector& args); 57 | virtual status_t standby() { return NO_ERROR; } 58 | virtual status_t setParameters(const String8& keyValuePairs) { return NO_ERROR;} 59 | virtual String8 getParameters(const String8& keys); 60 | virtual unsigned int getInputFramesLost() const { return 0; } 61 | virtual status_t addAudioEffect(effect_handle_t effect) { return NO_ERROR; } 62 | virtual status_t removeAudioEffect(effect_handle_t effect) { return NO_ERROR; } 63 | }; 64 | 65 | class AudioHardwareStub : public AudioHardwareBase 66 | { 67 | public: 68 | AudioHardwareStub(); 69 | virtual ~AudioHardwareStub(); 70 | virtual status_t initCheck(); 71 | virtual status_t setVoiceVolume(float volume); 72 | virtual status_t setMasterVolume(float volume); 73 | 74 | // mic mute 75 | virtual status_t setMicMute(bool state) { mMicMute = state; return NO_ERROR; } 76 | virtual status_t getMicMute(bool* state) { *state = mMicMute ; return NO_ERROR; } 77 | 78 | // create I/O streams 79 | virtual AudioStreamOut* openOutputStream( 80 | uint32_t devices, 81 | int *format=0, 82 | uint32_t *channels=0, 83 | uint32_t *sampleRate=0, 84 | status_t *status=0); 85 | virtual void closeOutputStream(AudioStreamOut* out); 86 | 87 | virtual AudioStreamIn* openInputStream( 88 | uint32_t devices, 89 | int *format, 90 | uint32_t *channels, 91 | uint32_t *sampleRate, 92 | status_t *status, 93 | AudioSystem::audio_in_acoustics acoustics); 94 | virtual void closeInputStream(AudioStreamIn* in); 95 | 96 | protected: 97 | virtual status_t dump(int fd, const Vector& args); 98 | 99 | bool mMicMute; 100 | private: 101 | status_t dumpInternals(int fd, const Vector& args); 102 | }; 103 | 104 | // ---------------------------------------------------------------------------- 105 | 106 | }; // namespace android 107 | 108 | #endif // ANDROID_AUDIO_HARDWARE_STUB_H 109 | -------------------------------------------------------------------------------- /audio/AudioPolicyCompatClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 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 "AudioPolicyCompatClient" 18 | //#define LOG_NDEBUG 0 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "AudioPolicyCompatClient.h" 30 | 31 | namespace android_audio_legacy { 32 | 33 | audio_module_handle_t AudioPolicyCompatClient::loadHwModule(const char *moduleName) 34 | { 35 | return mServiceOps->load_hw_module(mService, moduleName); 36 | } 37 | 38 | audio_io_handle_t AudioPolicyCompatClient::openOutput(audio_module_handle_t module, 39 | audio_devices_t *pDevices, 40 | uint32_t *pSamplingRate, 41 | audio_format_t *pFormat, 42 | audio_channel_mask_t *pChannelMask, 43 | uint32_t *pLatencyMs, 44 | audio_output_flags_t flags, 45 | const audio_offload_info_t *offloadInfo) 46 | { 47 | return mServiceOps->open_output_on_module(mService, module, pDevices, pSamplingRate, 48 | pFormat, pChannelMask, pLatencyMs, 49 | flags, offloadInfo); 50 | } 51 | 52 | audio_io_handle_t AudioPolicyCompatClient::openDuplicateOutput(audio_io_handle_t output1, 53 | audio_io_handle_t output2) 54 | { 55 | return mServiceOps->open_duplicate_output(mService, output1, output2); 56 | } 57 | 58 | status_t AudioPolicyCompatClient::closeOutput(audio_io_handle_t output) 59 | { 60 | return mServiceOps->close_output(mService, output); 61 | } 62 | 63 | status_t AudioPolicyCompatClient::suspendOutput(audio_io_handle_t output) 64 | { 65 | return mServiceOps->suspend_output(mService, output); 66 | } 67 | 68 | status_t AudioPolicyCompatClient::restoreOutput(audio_io_handle_t output) 69 | { 70 | return mServiceOps->restore_output(mService, output); 71 | } 72 | 73 | audio_io_handle_t AudioPolicyCompatClient::openInput(audio_module_handle_t module, 74 | audio_devices_t *pDevices, 75 | uint32_t *pSamplingRate, 76 | audio_format_t *pFormat, 77 | audio_channel_mask_t *pChannelMask) 78 | { 79 | return mServiceOps->open_input_on_module(mService, module, pDevices, 80 | pSamplingRate, pFormat, pChannelMask); 81 | } 82 | 83 | status_t AudioPolicyCompatClient::closeInput(audio_io_handle_t input) 84 | { 85 | return mServiceOps->close_input(mService, input); 86 | } 87 | 88 | status_t AudioPolicyCompatClient::invalidateStream(AudioSystem::stream_type stream) 89 | { 90 | return mServiceOps->invalidate_stream(mService, (audio_stream_type_t)stream); 91 | } 92 | 93 | status_t AudioPolicyCompatClient::moveEffects(audio_session_t session, audio_io_handle_t srcOutput, 94 | audio_io_handle_t dstOutput) 95 | { 96 | return mServiceOps->move_effects(mService, session, srcOutput, dstOutput); 97 | } 98 | 99 | String8 AudioPolicyCompatClient::getParameters(audio_io_handle_t ioHandle, const String8& keys) 100 | { 101 | char *str; 102 | String8 out_str8; 103 | 104 | str = mServiceOps->get_parameters(mService, ioHandle, keys.string()); 105 | out_str8 = String8(str); 106 | free(str); 107 | 108 | return out_str8; 109 | } 110 | 111 | void AudioPolicyCompatClient::setParameters(audio_io_handle_t ioHandle, 112 | const String8& keyValuePairs, 113 | int delayMs) 114 | { 115 | mServiceOps->set_parameters(mService, ioHandle, keyValuePairs.string(), 116 | delayMs); 117 | } 118 | 119 | status_t AudioPolicyCompatClient::setStreamVolume( 120 | AudioSystem::stream_type stream, 121 | float volume, 122 | audio_io_handle_t output, 123 | int delayMs) 124 | { 125 | return mServiceOps->set_stream_volume(mService, (audio_stream_type_t)stream, 126 | volume, output, delayMs); 127 | } 128 | 129 | status_t AudioPolicyCompatClient::startTone(ToneGenerator::tone_type tone, 130 | AudioSystem::stream_type stream) 131 | { 132 | return mServiceOps->start_tone(mService, 133 | AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION, 134 | (audio_stream_type_t)stream); 135 | } 136 | 137 | status_t AudioPolicyCompatClient::stopTone() 138 | { 139 | return mServiceOps->stop_tone(mService); 140 | } 141 | 142 | status_t AudioPolicyCompatClient::setVoiceVolume(float volume, int delayMs) 143 | { 144 | return mServiceOps->set_voice_volume(mService, volume, delayMs); 145 | } 146 | 147 | }; // namespace android_audio_legacy 148 | -------------------------------------------------------------------------------- /audio/AudioPolicyCompatClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 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 | #ifndef ANDROID_AUDIOPOLICYCLIENTLEGACY_H 18 | #define ANDROID_AUDIOPOLICYCLIENTLEGACY_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | /************************************/ 28 | /* FOR BACKWARDS COMPATIBILITY ONLY */ 29 | /************************************/ 30 | namespace android_audio_legacy { 31 | 32 | class AudioPolicyCompatClient : public AudioPolicyClientInterface { 33 | public: 34 | AudioPolicyCompatClient(struct audio_policy_service_ops *serviceOps, 35 | void *service) : 36 | mServiceOps(serviceOps) , mService(service) {} 37 | 38 | virtual audio_module_handle_t loadHwModule(const char *moduleName); 39 | 40 | virtual audio_io_handle_t openOutput(audio_module_handle_t module, 41 | audio_devices_t *pDevices, 42 | uint32_t *pSamplingRate, 43 | audio_format_t *pFormat, 44 | audio_channel_mask_t *pChannelMask, 45 | uint32_t *pLatencyMs, 46 | audio_output_flags_t flags, 47 | const audio_offload_info_t *offloadInfo); 48 | virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, 49 | audio_io_handle_t output2); 50 | virtual status_t closeOutput(audio_io_handle_t output); 51 | virtual status_t suspendOutput(audio_io_handle_t output); 52 | virtual status_t restoreOutput(audio_io_handle_t output); 53 | virtual audio_io_handle_t openInput(audio_module_handle_t module, 54 | audio_devices_t *pDevices, 55 | uint32_t *pSamplingRate, 56 | audio_format_t *pFormat, 57 | audio_channel_mask_t *pChannelMask); 58 | virtual status_t closeInput(audio_io_handle_t input); 59 | virtual status_t invalidateStream(AudioSystem::stream_type stream); 60 | virtual status_t moveEffects(audio_session_t session, 61 | audio_io_handle_t srcOutput, 62 | audio_io_handle_t dstOutput); 63 | 64 | virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys); 65 | virtual void setParameters(audio_io_handle_t ioHandle, 66 | const String8& keyValuePairs, 67 | int delayMs = 0); 68 | virtual status_t setStreamVolume(AudioSystem::stream_type stream, 69 | float volume, 70 | audio_io_handle_t output, 71 | int delayMs = 0); 72 | virtual status_t startTone(ToneGenerator::tone_type tone, AudioSystem::stream_type stream); 73 | virtual status_t stopTone(); 74 | virtual status_t setVoiceVolume(float volume, int delayMs = 0); 75 | 76 | private: 77 | struct audio_policy_service_ops* mServiceOps; 78 | void* mService; 79 | }; 80 | 81 | }; // namespace android_audio_legacy 82 | 83 | #endif // ANDROID_AUDIOPOLICYCLIENTLEGACY_H 84 | -------------------------------------------------------------------------------- /audio/AudioPolicyManagerDefault.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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 "AudioPolicyManagerDefault" 18 | //#define LOG_NDEBUG 0 19 | 20 | #include "AudioPolicyManagerDefault.h" 21 | 22 | namespace android_audio_legacy { 23 | 24 | extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface) 25 | { 26 | return new AudioPolicyManagerDefault(clientInterface); 27 | } 28 | 29 | extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface) 30 | { 31 | delete interface; 32 | } 33 | 34 | }; // namespace android 35 | -------------------------------------------------------------------------------- /audio/AudioPolicyManagerDefault.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | namespace android_audio_legacy { 24 | 25 | class AudioPolicyManagerDefault: public AudioPolicyManagerBase 26 | { 27 | 28 | public: 29 | AudioPolicyManagerDefault(AudioPolicyClientInterface *clientInterface) 30 | : AudioPolicyManagerBase(clientInterface) {} 31 | 32 | virtual ~AudioPolicyManagerDefault() {} 33 | 34 | }; 35 | }; 36 | -------------------------------------------------------------------------------- /audio/audio_policy.conf: -------------------------------------------------------------------------------- 1 | # 2 | # Audio policy configuration for generic device builds (goldfish audio HAL - emulator) 3 | # 4 | 5 | # Global configuration section: lists input and output devices always present on the device 6 | # as well as the output device selected by default. 7 | # Devices are designated by a string that corresponds to the enum in audio.h 8 | 9 | global_configuration { 10 | attached_output_devices AUDIO_DEVICE_OUT_SPEAKER 11 | default_output_device AUDIO_DEVICE_OUT_SPEAKER 12 | attached_input_devices AUDIO_DEVICE_IN_BUILTIN_MIC|AUDIO_DEVICE_IN_REMOTE_SUBMIX 13 | } 14 | 15 | # audio hardware module section: contains descriptors for all audio hw modules present on the 16 | # device. Each hw module node is named after the corresponding hw module library base name. 17 | # For instance, "primary" corresponds to audio.primary..so. 18 | # The "primary" module is mandatory and must include at least one output with 19 | # AUDIO_OUTPUT_FLAG_PRIMARY flag. 20 | # Each module descriptor contains one or more output profile descriptors and zero or more 21 | # input profile descriptors. Each profile lists all the parameters supported by a given output 22 | # or input stream category. 23 | # The "channel_masks", "formats", "devices" and "flags" are specified using strings corresponding 24 | # to enums in audio.h and audio_policy.h. They are concatenated by use of "|" without space or "\n". 25 | 26 | audio_hw_modules { 27 | primary { 28 | outputs { 29 | primary { 30 | sampling_rates 44100 31 | channel_masks AUDIO_CHANNEL_OUT_STEREO 32 | formats AUDIO_FORMAT_PCM_16_BIT 33 | devices AUDIO_DEVICE_OUT_SPEAKER 34 | flags AUDIO_OUTPUT_FLAG_PRIMARY 35 | } 36 | } 37 | inputs { 38 | primary { 39 | sampling_rates 8000|16000 40 | channel_masks AUDIO_CHANNEL_IN_MONO 41 | formats AUDIO_FORMAT_PCM_16_BIT 42 | devices AUDIO_DEVICE_IN_BUILTIN_MIC 43 | } 44 | } 45 | } 46 | r_submix { 47 | outputs { 48 | submix { 49 | sampling_rates 48000 50 | channel_masks AUDIO_CHANNEL_OUT_STEREO 51 | formats AUDIO_FORMAT_PCM_16_BIT 52 | devices AUDIO_DEVICE_OUT_REMOTE_SUBMIX 53 | } 54 | } 55 | inputs { 56 | submix { 57 | sampling_rates 48000 58 | channel_masks AUDIO_CHANNEL_IN_STEREO 59 | formats AUDIO_FORMAT_PCM_16_BIT 60 | devices AUDIO_DEVICE_IN_REMOTE_SUBMIX 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /include/hardware_legacy/AudioHardwareBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 | #ifndef ANDROID_AUDIO_HARDWARE_BASE_H 18 | #define ANDROID_AUDIO_HARDWARE_BASE_H 19 | 20 | #include 21 | 22 | #include 23 | 24 | namespace android_audio_legacy { 25 | 26 | // ---------------------------------------------------------------------------- 27 | 28 | /** 29 | * AudioHardwareBase is a convenient base class used for implementing the 30 | * AudioHardwareInterface interface. 31 | */ 32 | class AudioHardwareBase : public AudioHardwareInterface 33 | { 34 | public: 35 | AudioHardwareBase(); 36 | virtual ~AudioHardwareBase() { } 37 | 38 | /** 39 | * setMode is called when the audio mode changes. NORMAL mode is for 40 | * standard audio playback, RINGTONE when a ringtone is playing, IN_CALL 41 | * when a telephony call is in progress, IN_COMMUNICATION when a VoIP call is in progress. 42 | */ 43 | virtual status_t setMode(int mode); 44 | 45 | virtual status_t setParameters(const String8& keyValuePairs); 46 | virtual String8 getParameters(const String8& keys); 47 | 48 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); 49 | virtual status_t getMasterVolume(float *volume); 50 | 51 | /**This method dumps the state of the audio hardware */ 52 | virtual status_t dumpState(int fd, const Vector& args); 53 | 54 | protected: 55 | /** returns true if the given mode maps to a telephony or VoIP call is in progress */ 56 | virtual bool isModeInCall(int mode) 57 | { return ((mode == AudioSystem::MODE_IN_CALL) 58 | || (mode == AudioSystem::MODE_IN_COMMUNICATION)); }; 59 | /** returns true if a telephony or VoIP call is in progress */ 60 | virtual bool isInCall() { return isModeInCall(mMode); }; 61 | int mMode; 62 | }; 63 | 64 | }; // namespace android 65 | 66 | #endif // ANDROID_AUDIO_HARDWARE_BASE_H 67 | -------------------------------------------------------------------------------- /include/hardware_legacy/AudioHardwareInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 | #ifndef ANDROID_AUDIO_HARDWARE_INTERFACE_H 18 | #define ANDROID_AUDIO_HARDWARE_INTERFACE_H 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | namespace android_audio_legacy { 37 | using android::Vector; 38 | using android::String16; 39 | using android::String8; 40 | 41 | // ---------------------------------------------------------------------------- 42 | 43 | /** 44 | * AudioStreamOut is the abstraction interface for the audio output hardware. 45 | * 46 | * It provides information about various properties of the audio output hardware driver. 47 | */ 48 | class AudioStreamOut { 49 | public: 50 | virtual ~AudioStreamOut() = 0; 51 | 52 | /** return audio sampling rate in hz - eg. 44100 */ 53 | virtual uint32_t sampleRate() const = 0; 54 | 55 | /** returns size of output buffer - eg. 4800 */ 56 | virtual size_t bufferSize() const = 0; 57 | 58 | /** 59 | * returns the output channel mask 60 | */ 61 | virtual uint32_t channels() const = 0; 62 | 63 | /** 64 | * return audio format in 8bit or 16bit PCM format - 65 | * eg. AudioSystem:PCM_16_BIT 66 | */ 67 | virtual int format() const = 0; 68 | 69 | /** 70 | * return the frame size (number of bytes per sample). 71 | */ 72 | uint32_t frameSize() const { return audio_channel_count_from_out_mask(channels())* 73 | ((format()==AUDIO_FORMAT_PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } 74 | 75 | /** 76 | * return the audio hardware driver latency in milli seconds. 77 | */ 78 | virtual uint32_t latency() const = 0; 79 | 80 | /** 81 | * Use this method in situations where audio mixing is done in the 82 | * hardware. This method serves as a direct interface with hardware, 83 | * allowing you to directly set the volume as apposed to via the framework. 84 | * This method might produce multiple PCM outputs or hardware accelerated 85 | * codecs, such as MP3 or AAC. 86 | */ 87 | virtual status_t setVolume(float left, float right) = 0; 88 | 89 | /** write audio buffer to driver. Returns number of bytes written */ 90 | virtual ssize_t write(const void* buffer, size_t bytes) = 0; 91 | 92 | /** 93 | * Put the audio hardware output into standby mode. Returns 94 | * status based on include/utils/Errors.h 95 | */ 96 | virtual status_t standby() = 0; 97 | 98 | /** dump the state of the audio output device */ 99 | virtual status_t dump(int fd, const Vector& args) = 0; 100 | 101 | // set/get audio output parameters. The function accepts a list of parameters 102 | // key value pairs in the form: key1=value1;key2=value2;... 103 | // Some keys are reserved for standard parameters (See AudioParameter class). 104 | // If the implementation does not accept a parameter change while the output is 105 | // active but the parameter is acceptable otherwise, it must return INVALID_OPERATION. 106 | // The audio flinger will put the output in standby and then change the parameter value. 107 | virtual status_t setParameters(const String8& keyValuePairs) = 0; 108 | virtual String8 getParameters(const String8& keys) = 0; 109 | 110 | // return the number of audio frames written by the audio dsp to DAC since 111 | // the output has exited standby 112 | virtual status_t getRenderPosition(uint32_t *dspFrames) = 0; 113 | 114 | /** 115 | * get the local time at which the next write to the audio driver will be 116 | * presented 117 | */ 118 | virtual status_t getNextWriteTimestamp(int64_t *timestamp); 119 | 120 | /** 121 | * Return a recent count of the number of audio frames presented to an external observer. 122 | */ 123 | virtual status_t getPresentationPosition(uint64_t *frames, struct timespec *timestamp) = 0; 124 | 125 | }; 126 | 127 | /** 128 | * AudioStreamIn is the abstraction interface for the audio input hardware. 129 | * 130 | * It defines the various properties of the audio hardware input driver. 131 | */ 132 | class AudioStreamIn { 133 | public: 134 | virtual ~AudioStreamIn() = 0; 135 | 136 | /** return audio sampling rate in hz - eg. 44100 */ 137 | virtual uint32_t sampleRate() const = 0; 138 | 139 | /** return the input buffer size allowed by audio driver */ 140 | virtual size_t bufferSize() const = 0; 141 | 142 | /** return input channel mask */ 143 | virtual uint32_t channels() const = 0; 144 | 145 | /** 146 | * return audio format in 8bit or 16bit PCM format - 147 | * eg. AudioSystem:PCM_16_BIT 148 | */ 149 | virtual int format() const = 0; 150 | 151 | /** 152 | * return the frame size (number of bytes per sample). 153 | */ 154 | uint32_t frameSize() const { return audio_channel_count_from_in_mask(channels())* 155 | ((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } 156 | 157 | /** set the input gain for the audio driver. This method is for 158 | * for future use */ 159 | virtual status_t setGain(float gain) = 0; 160 | 161 | /** read audio buffer in from audio driver */ 162 | virtual ssize_t read(void* buffer, ssize_t bytes) = 0; 163 | 164 | /** dump the state of the audio input device */ 165 | virtual status_t dump(int fd, const Vector& args) = 0; 166 | 167 | /** 168 | * Put the audio hardware input into standby mode. Returns 169 | * status based on include/utils/Errors.h 170 | */ 171 | virtual status_t standby() = 0; 172 | 173 | // set/get audio input parameters. The function accepts a list of parameters 174 | // key value pairs in the form: key1=value1;key2=value2;... 175 | // Some keys are reserved for standard parameters (See AudioParameter class). 176 | // If the implementation does not accept a parameter change while the output is 177 | // active but the parameter is acceptable otherwise, it must return INVALID_OPERATION. 178 | // The audio flinger will put the input in standby and then change the parameter value. 179 | virtual status_t setParameters(const String8& keyValuePairs) = 0; 180 | virtual String8 getParameters(const String8& keys) = 0; 181 | 182 | 183 | // Return the number of input frames lost in the audio driver since the last call of this function. 184 | // Audio driver is expected to reset the value to 0 and restart counting upon returning the current value by this function call. 185 | // Such loss typically occurs when the user space process is blocked longer than the capacity of audio driver buffers. 186 | // Unit: the number of input audio frames 187 | virtual unsigned int getInputFramesLost() const = 0; 188 | 189 | virtual status_t addAudioEffect(effect_handle_t effect) = 0; 190 | virtual status_t removeAudioEffect(effect_handle_t effect) = 0; 191 | }; 192 | 193 | /** 194 | * AudioHardwareInterface.h defines the interface to the audio hardware abstraction layer. 195 | * 196 | * The interface supports setting and getting parameters, selecting audio routing 197 | * paths, and defining input and output streams. 198 | * 199 | * AudioFlinger initializes the audio hardware and immediately opens an output stream. 200 | * You can set Audio routing to output to handset, speaker, Bluetooth, or a headset. 201 | * 202 | * The audio input stream is initialized when AudioFlinger is called to carry out 203 | * a record operation. 204 | */ 205 | class AudioHardwareInterface 206 | { 207 | public: 208 | virtual ~AudioHardwareInterface() {} 209 | 210 | /** 211 | * check to see if the audio hardware interface has been initialized. 212 | * return status based on values defined in include/utils/Errors.h 213 | */ 214 | virtual status_t initCheck() = 0; 215 | 216 | /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */ 217 | virtual status_t setVoiceVolume(float volume) = 0; 218 | 219 | /** 220 | * set the audio volume for all audio activities other than voice call. 221 | * Range between 0.0 and 1.0. If any value other than NO_ERROR is returned, 222 | * the software mixer will emulate this capability. 223 | */ 224 | virtual status_t setMasterVolume(float volume) = 0; 225 | 226 | /** 227 | * Get the current master volume value for the HAL, if the HAL supports 228 | * master volume control. AudioFlinger will query this value from the 229 | * primary audio HAL when the service starts and use the value for setting 230 | * the initial master volume across all HALs. 231 | */ 232 | virtual status_t getMasterVolume(float *volume) = 0; 233 | 234 | /** 235 | * setMode is called when the audio mode changes. NORMAL mode is for 236 | * standard audio playback, RINGTONE when a ringtone is playing, and IN_CALL 237 | * when a call is in progress. 238 | */ 239 | virtual status_t setMode(int mode) = 0; 240 | 241 | // mic mute 242 | virtual status_t setMicMute(bool state) = 0; 243 | virtual status_t getMicMute(bool* state) = 0; 244 | 245 | // set/get global audio parameters 246 | virtual status_t setParameters(const String8& keyValuePairs) = 0; 247 | virtual String8 getParameters(const String8& keys) = 0; 248 | 249 | // Returns audio input buffer size according to parameters passed or 0 if one of the 250 | // parameters is not supported 251 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount) = 0; 252 | 253 | /** This method creates and opens the audio hardware output stream */ 254 | virtual AudioStreamOut* openOutputStream( 255 | uint32_t devices, 256 | int *format=0, 257 | uint32_t *channels=0, 258 | uint32_t *sampleRate=0, 259 | status_t *status=0) = 0; 260 | virtual AudioStreamOut* openOutputStreamWithFlags( 261 | uint32_t devices, 262 | audio_output_flags_t flags=(audio_output_flags_t)0, 263 | int *format=0, 264 | uint32_t *channels=0, 265 | uint32_t *sampleRate=0, 266 | status_t *status=0) = 0; 267 | virtual void closeOutputStream(AudioStreamOut* out) = 0; 268 | 269 | /** This method creates and opens the audio hardware input stream */ 270 | virtual AudioStreamIn* openInputStream( 271 | uint32_t devices, 272 | int *format, 273 | uint32_t *channels, 274 | uint32_t *sampleRate, 275 | status_t *status, 276 | AudioSystem::audio_in_acoustics acoustics) = 0; 277 | virtual void closeInputStream(AudioStreamIn* in) = 0; 278 | 279 | /**This method dumps the state of the audio hardware */ 280 | virtual status_t dumpState(int fd, const Vector& args) = 0; 281 | 282 | virtual status_t setMasterMute(bool muted) = 0; 283 | 284 | static AudioHardwareInterface* create(); 285 | 286 | virtual int createAudioPatch(unsigned int num_sources, 287 | const struct audio_port_config *sources, 288 | unsigned int num_sinks, 289 | const struct audio_port_config *sinks, 290 | audio_patch_handle_t *handle) = 0; 291 | 292 | virtual int releaseAudioPatch(audio_patch_handle_t handle) = 0; 293 | 294 | virtual int getAudioPort(struct audio_port *port) = 0; 295 | 296 | virtual int setAudioPortConfig(const struct audio_port_config *config) = 0; 297 | 298 | protected: 299 | 300 | virtual status_t dump(int fd, const Vector& args) = 0; 301 | }; 302 | 303 | // ---------------------------------------------------------------------------- 304 | 305 | extern "C" AudioHardwareInterface* createAudioHardware(void); 306 | 307 | }; // namespace android 308 | 309 | #endif // ANDROID_AUDIO_HARDWARE_INTERFACE_H 310 | -------------------------------------------------------------------------------- /include/hardware_legacy/AudioPolicyInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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 | #ifndef ANDROID_AUDIOPOLICYINTERFACE_H 18 | #define ANDROID_AUDIOPOLICYINTERFACE_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | namespace android_audio_legacy { 28 | using android::Vector; 29 | using android::String8; 30 | using android::ToneGenerator; 31 | 32 | // ---------------------------------------------------------------------------- 33 | 34 | // The AudioPolicyInterface and AudioPolicyClientInterface classes define the communication interfaces 35 | // between the platform specific audio policy manager and Android generic audio policy manager. 36 | // The platform specific audio policy manager must implement methods of the AudioPolicyInterface class. 37 | // This implementation makes use of the AudioPolicyClientInterface to control the activity and 38 | // configuration of audio input and output streams. 39 | // 40 | // The platform specific audio policy manager is in charge of the audio routing and volume control 41 | // policies for a given platform. 42 | // The main roles of this module are: 43 | // - keep track of current system state (removable device connections, phone state, user requests...). 44 | // System state changes and user actions are notified to audio policy manager with methods of the AudioPolicyInterface. 45 | // - process getOutput() queries received when AudioTrack objects are created: Those queries 46 | // return a handler on an output that has been selected, configured and opened by the audio policy manager and that 47 | // must be used by the AudioTrack when registering to the AudioFlinger with the createTrack() method. 48 | // When the AudioTrack object is released, a putOutput() query is received and the audio policy manager can decide 49 | // to close or reconfigure the output depending on other streams using this output and current system state. 50 | // - similarly process getInput() and putInput() queries received from AudioRecord objects and configure audio inputs. 51 | // - process volume control requests: the stream volume is converted from an index value (received from UI) to a float value 52 | // applicable to each output as a function of platform specific settings and current output route (destination device). It 53 | // also make sure that streams are not muted if not allowed (e.g. camera shutter sound in some countries). 54 | // 55 | // The platform specific audio policy manager is provided as a shared library by platform vendors (as for libaudio.so) 56 | // and is linked with libaudioflinger.so 57 | 58 | 59 | // Audio Policy Manager Interface 60 | class AudioPolicyInterface 61 | { 62 | 63 | public: 64 | virtual ~AudioPolicyInterface() {} 65 | // 66 | // configuration functions 67 | // 68 | 69 | // indicate a change in device connection status 70 | virtual status_t setDeviceConnectionState(audio_devices_t device, 71 | AudioSystem::device_connection_state state, 72 | const char *device_address) = 0; 73 | // retrieve a device connection status 74 | virtual AudioSystem::device_connection_state getDeviceConnectionState(audio_devices_t device, 75 | const char *device_address) = 0; 76 | // indicate a change in phone state. Valid phones states are defined by AudioSystem::audio_mode 77 | virtual void setPhoneState(int state) = 0; 78 | // force using a specific device category for the specified usage 79 | virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config) = 0; 80 | // retrieve current device category forced for a given usage 81 | virtual AudioSystem::forced_config getForceUse(AudioSystem::force_use usage) = 0; 82 | // set a system property (e.g. camera sound always audible) 83 | virtual void setSystemProperty(const char* property, const char* value) = 0; 84 | // check proper initialization 85 | virtual status_t initCheck() = 0; 86 | 87 | // 88 | // Audio routing query functions 89 | // 90 | 91 | // request an output appropriate for playback of the supplied stream type and parameters 92 | virtual audio_io_handle_t getOutput(AudioSystem::stream_type stream, 93 | uint32_t samplingRate, 94 | audio_format_t format, 95 | audio_channel_mask_t channelMask, 96 | AudioSystem::output_flags flags, 97 | const audio_offload_info_t *offloadInfo) = 0; 98 | // indicates to the audio policy manager that the output starts being used by corresponding stream. 99 | virtual status_t startOutput(audio_io_handle_t output, 100 | AudioSystem::stream_type stream, 101 | audio_session_t session = AUDIO_SESSION_NONE) = 0; 102 | // indicates to the audio policy manager that the output stops being used by corresponding stream. 103 | virtual status_t stopOutput(audio_io_handle_t output, 104 | AudioSystem::stream_type stream, 105 | audio_session_t session = AUDIO_SESSION_NONE) = 0; 106 | // releases the output. 107 | virtual void releaseOutput(audio_io_handle_t output) = 0; 108 | 109 | // request an input appropriate for record from the supplied device with supplied parameters. 110 | virtual audio_io_handle_t getInput(int inputSource, 111 | uint32_t samplingRate, 112 | audio_format_t format, 113 | audio_channel_mask_t channelMask, 114 | AudioSystem::audio_in_acoustics acoustics) = 0; 115 | // indicates to the audio policy manager that the input starts being used. 116 | virtual status_t startInput(audio_io_handle_t input) = 0; 117 | // indicates to the audio policy manager that the input stops being used. 118 | virtual status_t stopInput(audio_io_handle_t input) = 0; 119 | // releases the input. 120 | virtual void releaseInput(audio_io_handle_t input) = 0; 121 | 122 | // 123 | // volume control functions 124 | // 125 | 126 | // initialises stream volume conversion parameters by specifying volume index range. 127 | virtual void initStreamVolume(AudioSystem::stream_type stream, 128 | int indexMin, 129 | int indexMax) = 0; 130 | 131 | // sets the new stream volume at a level corresponding to the supplied index for the 132 | // supplied device. By convention, specifying AUDIO_DEVICE_OUT_DEFAULT means 133 | // setting volume for all devices 134 | virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream, 135 | int index, 136 | audio_devices_t device) = 0; 137 | 138 | // retrieve current volume index for the specified stream and the 139 | // specified device. By convention, specifying AUDIO_DEVICE_OUT_DEFAULT means 140 | // querying the volume of the active device. 141 | virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream, 142 | int *index, 143 | audio_devices_t device) = 0; 144 | 145 | // return the strategy corresponding to a given stream type 146 | virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream) = 0; 147 | 148 | // return the enabled output devices for the given stream type 149 | virtual audio_devices_t getDevicesForStream(AudioSystem::stream_type stream) = 0; 150 | 151 | // Audio effect management 152 | virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) = 0; 153 | virtual status_t registerEffect(const effect_descriptor_t *desc, 154 | audio_io_handle_t io, 155 | uint32_t strategy, 156 | audio_session_t session, 157 | int id) = 0; 158 | virtual status_t unregisterEffect(int id) = 0; 159 | virtual status_t setEffectEnabled(int id, bool enabled) = 0; 160 | 161 | virtual bool isStreamActive(int stream, uint32_t inPastMs = 0) const = 0; 162 | virtual bool isStreamActiveRemotely(int stream, uint32_t inPastMs = 0) const = 0; 163 | virtual bool isSourceActive(audio_source_t source) const = 0; 164 | 165 | //dump state 166 | virtual status_t dump(int fd) = 0; 167 | 168 | virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo) = 0; 169 | }; 170 | 171 | 172 | // Audio Policy client Interface 173 | class AudioPolicyClientInterface 174 | { 175 | public: 176 | virtual ~AudioPolicyClientInterface() {} 177 | 178 | // 179 | // Audio HW module functions 180 | // 181 | 182 | // loads a HW module. 183 | virtual audio_module_handle_t loadHwModule(const char *name) = 0; 184 | 185 | // 186 | // Audio output Control functions 187 | // 188 | 189 | // opens an audio output with the requested parameters. The parameter values can indicate to use the default values 190 | // in case the audio policy manager has no specific requirements for the output being opened. 191 | // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream. 192 | // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly. 193 | virtual audio_io_handle_t openOutput(audio_module_handle_t module, 194 | audio_devices_t *pDevices, 195 | uint32_t *pSamplingRate, 196 | audio_format_t *pFormat, 197 | audio_channel_mask_t *pChannelMask, 198 | uint32_t *pLatencyMs, 199 | audio_output_flags_t flags, 200 | const audio_offload_info_t *offloadInfo = NULL) = 0; 201 | // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by 202 | // a special mixer thread in the AudioFlinger. 203 | virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2) = 0; 204 | // closes the output stream 205 | virtual status_t closeOutput(audio_io_handle_t output) = 0; 206 | // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in 207 | // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded. 208 | virtual status_t suspendOutput(audio_io_handle_t output) = 0; 209 | // restores a suspended output. 210 | virtual status_t restoreOutput(audio_io_handle_t output) = 0; 211 | 212 | // 213 | // Audio input Control functions 214 | // 215 | 216 | // opens an audio input 217 | virtual audio_io_handle_t openInput(audio_module_handle_t module, 218 | audio_devices_t *pDevices, 219 | uint32_t *pSamplingRate, 220 | audio_format_t *pFormat, 221 | audio_channel_mask_t *pChannelMask) = 0; 222 | // closes an audio input 223 | virtual status_t closeInput(audio_io_handle_t input) = 0; 224 | // 225 | // misc control functions 226 | // 227 | 228 | // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes 229 | // for each output (destination device) it is attached to. 230 | virtual status_t setStreamVolume(AudioSystem::stream_type stream, float volume, audio_io_handle_t output, int delayMs = 0) = 0; 231 | 232 | // invalidate a stream type, causing a reroute to an unspecified new output 233 | virtual status_t invalidateStream(AudioSystem::stream_type stream) = 0; 234 | 235 | // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface. 236 | virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0) = 0; 237 | // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager. 238 | virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) = 0; 239 | 240 | // request the playback of a tone on the specified stream: used for instance to replace notification sounds when playing 241 | // over a telephony device during a phone call. 242 | virtual status_t startTone(ToneGenerator::tone_type tone, AudioSystem::stream_type stream) = 0; 243 | virtual status_t stopTone() = 0; 244 | 245 | // set down link audio volume. 246 | virtual status_t setVoiceVolume(float volume, int delayMs = 0) = 0; 247 | 248 | // move effect to the specified output 249 | virtual status_t moveEffects(audio_session_t session, 250 | audio_io_handle_t srcOutput, 251 | audio_io_handle_t dstOutput) = 0; 252 | 253 | }; 254 | 255 | extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface); 256 | extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface); 257 | 258 | 259 | }; // namespace android 260 | 261 | #endif // ANDROID_AUDIOPOLICYINTERFACE_H 262 | -------------------------------------------------------------------------------- /include/hardware_legacy/IMountService.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 | // 18 | #ifndef ANDROID_HARDWARE_IMOUNTSERVICE_H 19 | #define ANDROID_HARDWARE_IMOUNTSERVICE_H 20 | 21 | #include 22 | #include 23 | 24 | namespace android { 25 | 26 | // ---------------------------------------------------------------------- 27 | 28 | class IMountService : public IInterface 29 | { 30 | public: 31 | static const int OperationSucceeded = 0; 32 | static const int OperationFailedInternalError = -1; 33 | static const int OperationFailedNoMedia = -2; 34 | static const int OperationFailedMediaBlank = -3; 35 | static const int OperationFailedMediaCorrupt = -4; 36 | static const int OperationFailedVolumeNotMounted = -5; 37 | 38 | 39 | public: 40 | DECLARE_META_INTERFACE(MountService); 41 | 42 | virtual void getShareMethodList() = 0; 43 | virtual bool getShareMethodAvailable(String16 method) = 0; 44 | virtual int shareVolume(String16 path, String16 method) = 0; 45 | virtual int unshareVolume(String16 path, String16 method) = 0; 46 | virtual bool getVolumeShared(String16 path, String16 method) = 0; 47 | virtual int mountVolume(String16 path) = 0; 48 | virtual int unmountVolume(String16 path) = 0; 49 | virtual int formatVolume(String16 path) = 0; 50 | virtual String16 getVolumeState(String16 mountPoint) = 0; 51 | virtual int createSecureContainer(String16 id, int sizeMb, String16 fstype, String16 key, int ownerUid) = 0; 52 | virtual int finalizeSecureContainer(String16 id) = 0; 53 | virtual int destroySecureContainer(String16 id) = 0; 54 | virtual int mountSecureContainer(String16 id, String16 key, int ownerUid) = 0; 55 | virtual int unmountSecureContainer(String16 id) = 0; 56 | virtual int renameSecureContainer(String16 oldId, String16 newId) = 0; 57 | virtual String16 getSecureContainerPath(String16 id) = 0; 58 | virtual void getSecureContainerList() = 0; 59 | virtual void shutdown() = 0; 60 | }; 61 | 62 | // ---------------------------------------------------------------------- 63 | 64 | }; // namespace android 65 | 66 | #endif // ANDROID_HARDWARE_IMOUNTSERVICE_H 67 | -------------------------------------------------------------------------------- /include/hardware_legacy/audio_policy_conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 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 | 18 | #ifndef ANDROID_AUDIO_POLICY_CONF_H 19 | #define ANDROID_AUDIO_POLICY_CONF_H 20 | 21 | 22 | ///////////////////////////////////////////////// 23 | // Definitions for audio policy configuration file (audio_policy.conf) 24 | ///////////////////////////////////////////////// 25 | 26 | #define AUDIO_HARDWARE_MODULE_ID_MAX_LEN 32 27 | 28 | #define AUDIO_POLICY_CONFIG_FILE "/system/etc/audio_policy.conf" 29 | #define AUDIO_POLICY_VENDOR_CONFIG_FILE "/vendor/etc/audio_policy.conf" 30 | 31 | // global configuration 32 | #define GLOBAL_CONFIG_TAG "global_configuration" 33 | 34 | #define ATTACHED_OUTPUT_DEVICES_TAG "attached_output_devices" 35 | #define DEFAULT_OUTPUT_DEVICE_TAG "default_output_device" 36 | #define ATTACHED_INPUT_DEVICES_TAG "attached_input_devices" 37 | #define SPEAKER_DRC_ENABLED_TAG "speaker_drc_enabled" 38 | 39 | // hw modules descriptions 40 | #define AUDIO_HW_MODULE_TAG "audio_hw_modules" 41 | 42 | #define OUTPUTS_TAG "outputs" 43 | #define INPUTS_TAG "inputs" 44 | 45 | #define SAMPLING_RATES_TAG "sampling_rates" 46 | #define FORMATS_TAG "formats" 47 | #define CHANNELS_TAG "channel_masks" 48 | #define DEVICES_TAG "devices" 49 | #define FLAGS_TAG "flags" 50 | 51 | #define DYNAMIC_VALUE_TAG "dynamic" // special value for "channel_masks", "sampling_rates" and 52 | // "formats" in outputs descriptors indicating that supported 53 | // values should be queried after opening the output. 54 | 55 | #endif // ANDROID_AUDIO_POLICY_CONF_H 56 | -------------------------------------------------------------------------------- /include/hardware_legacy/link_layer_stats.h: -------------------------------------------------------------------------------- 1 | #include "wifi_hal.h" 2 | 3 | #ifndef __WIFI_HAL_STATS_H 4 | #define __WIFI_HAL_STATS_H 5 | 6 | #ifdef __cplusplus 7 | extern "C" 8 | { 9 | #endif /* __cplusplus */ 10 | 11 | #define STATS_MAJOR_VERSION 1 12 | #define STATS_MINOR_VERSION 0 13 | #define STATS_MICRO_VERSION 0 14 | 15 | typedef enum { 16 | WIFI_DISCONNECTED = 0, 17 | WIFI_AUTHENTICATING = 1, 18 | WIFI_ASSOCIATING = 2, 19 | WIFI_ASSOCIATED = 3, 20 | WIFI_EAPOL_STARTED = 4, // if done by firmware/driver 21 | WIFI_EAPOL_COMPLETED = 5, // if done by firmware/driver 22 | } wifi_connection_state; 23 | 24 | typedef enum { 25 | WIFI_ROAMING_IDLE = 0, 26 | WIFI_ROAMING_ACTIVE = 1, 27 | } wifi_roam_state; 28 | 29 | typedef enum { 30 | WIFI_INTERFACE_STA = 0, 31 | WIFI_INTERFACE_SOFTAP = 1, 32 | WIFI_INTERFACE_IBSS = 2, 33 | WIFI_INTERFACE_P2P_CLIENT = 3, 34 | WIFI_INTERFACE_P2P_GO = 4, 35 | WIFI_INTERFACE_NAN = 5, 36 | WIFI_INTERFACE_MESH = 6, 37 | WIFI_INTERFACE_UNKNOWN = -1 38 | } wifi_interface_mode; 39 | 40 | #define WIFI_CAPABILITY_QOS 0x00000001 // set for QOS association 41 | #define WIFI_CAPABILITY_PROTECTED 0x00000002 // set for protected association (802.11 beacon frame control protected bit set) 42 | #define WIFI_CAPABILITY_INTERWORKING 0x00000004 // set if 802.11 Extended Capabilities element interworking bit is set 43 | #define WIFI_CAPABILITY_HS20 0x00000008 // set for HS20 association 44 | #define WIFI_CAPABILITY_SSID_UTF8 0x00000010 // set is 802.11 Extended Capabilities element UTF-8 SSID bit is set 45 | #define WIFI_CAPABILITY_COUNTRY 0x00000020 // set is 802.11 Country Element is present 46 | 47 | typedef struct { 48 | wifi_interface_mode mode; // interface mode 49 | u8 mac_addr[6]; // interface mac address (self) 50 | wifi_connection_state state; // connection state (valid for STA, CLI only) 51 | wifi_roam_state roaming; // roaming state 52 | u32 capabilities; // WIFI_CAPABILITY_XXX (self) 53 | u8 ssid[33]; // null terminated SSID 54 | u8 bssid[6]; // bssid 55 | u8 ap_country_str[3]; // country string advertised by AP 56 | u8 country_str[3]; // country string for this association 57 | } wifi_interface_link_layer_info; 58 | 59 | /* channel information */ 60 | typedef struct { 61 | wifi_channel_width width; // channel width (20, 40, 80, 80+80, 160) 62 | wifi_channel center_freq; // primary 20 MHz channel 63 | wifi_channel center_freq0; // center frequency (MHz) first segment 64 | wifi_channel center_freq1; // center frequency (MHz) second segment 65 | } wifi_channel_info; 66 | 67 | /* wifi rate */ 68 | typedef struct { 69 | u32 preamble :3; // 0: OFDM, 1:CCK, 2:HT 3:VHT 4..7 reserved 70 | u32 nss :2; // 0:1x1, 1:2x2, 3:3x3, 4:4x4 71 | u32 bw :3; // 0:20MHz, 1:40Mhz, 2:80Mhz, 3:160Mhz 72 | u32 rateMcsIdx :8; // OFDM/CCK rate code would be as per ieee std in the units of 0.5mbps 73 | // HT/VHT it would be mcs index 74 | u32 reserved :16; // reserved 75 | u32 bitrate; // units of 100 Kbps 76 | } wifi_rate; 77 | 78 | /* channel statistics */ 79 | typedef struct { 80 | wifi_channel_info channel; // channel 81 | u32 on_time; // msecs the radio is awake (32 bits number accruing over time) 82 | u32 cca_busy_time; // msecs the CCA register is busy (32 bits number accruing over time) 83 | } wifi_channel_stat; 84 | 85 | // Max number of tx power levels. The actual number vary per device and is specified by |num_tx_levels| 86 | #define RADIO_STAT_MAX_TX_LEVELS 256 87 | 88 | /* radio statistics */ 89 | typedef struct { 90 | wifi_radio radio; // wifi radio (if multiple radio supported) 91 | u32 on_time; // msecs the radio is awake (32 bits number accruing over time) 92 | u32 tx_time; // msecs the radio is transmitting (32 bits number accruing over time) 93 | u32 num_tx_levels; // number of radio transmit power levels 94 | u32 *tx_time_per_levels; // pointer to an array of radio transmit per power levels in 95 | // msecs accured over time 96 | u32 rx_time; // msecs the radio is in active receive (32 bits number accruing over time) 97 | u32 on_time_scan; // msecs the radio is awake due to all scan (32 bits number accruing over time) 98 | u32 on_time_nbd; // msecs the radio is awake due to NAN (32 bits number accruing over time) 99 | u32 on_time_gscan; // msecs the radio is awake due to G?scan (32 bits number accruing over time) 100 | u32 on_time_roam_scan; // msecs the radio is awake due to roam?scan (32 bits number accruing over time) 101 | u32 on_time_pno_scan; // msecs the radio is awake due to PNO scan (32 bits number accruing over time) 102 | u32 on_time_hs20; // msecs the radio is awake due to HS2.0 scans and GAS exchange (32 bits number accruing over time) 103 | u32 num_channels; // number of channels 104 | wifi_channel_stat channels[]; // channel statistics 105 | } wifi_radio_stat; 106 | 107 | /** 108 | * Packet statistics reporting by firmware is performed on MPDU basi (i.e. counters increase by 1 for each MPDU) 109 | * As well, "data packet" in associated comments, shall be interpreted as 802.11 data packet, 110 | * that is, 802.11 frame control subtype == 2 and excluding management and control frames. 111 | * 112 | * As an example, in the case of transmission of an MSDU fragmented in 16 MPDUs which are transmitted 113 | * OTA in a 16 units long a-mpdu, for which a block ack is received with 5 bits set: 114 | * tx_mpdu : shall increase by 5 115 | * retries : shall increase by 16 116 | * tx_ampdu : shall increase by 1 117 | * data packet counters shall not increase regardless of the number of BAR potentially sent by device for this a-mpdu 118 | * data packet counters shall not increase regardless of the number of BA received by device for this a-mpdu 119 | * 120 | * For each subsequent retransmission of the 11 remaining non ACK'ed mpdus 121 | * (regardless of the fact that they are transmitted in a-mpdu or not) 122 | * retries : shall increase by 1 123 | * 124 | * If no subsequent BA or ACK are received from AP, until packet lifetime expires for those 11 packet that were not ACK'ed 125 | * mpdu_lost : shall increase by 11 126 | */ 127 | 128 | /* per rate statistics */ 129 | typedef struct { 130 | wifi_rate rate; // rate information 131 | u32 tx_mpdu; // number of successfully transmitted data pkts (ACK rcvd) 132 | u32 rx_mpdu; // number of received data pkts 133 | u32 mpdu_lost; // number of data packet losses (no ACK) 134 | u32 retries; // total number of data pkt retries 135 | u32 retries_short; // number of short data pkt retries 136 | u32 retries_long; // number of long data pkt retries 137 | } wifi_rate_stat; 138 | 139 | /* access categories */ 140 | typedef enum { 141 | WIFI_AC_VO = 0, 142 | WIFI_AC_VI = 1, 143 | WIFI_AC_BE = 2, 144 | WIFI_AC_BK = 3, 145 | WIFI_AC_MAX = 4, 146 | } wifi_traffic_ac; 147 | 148 | /* wifi peer type */ 149 | typedef enum 150 | { 151 | WIFI_PEER_STA, 152 | WIFI_PEER_AP, 153 | WIFI_PEER_P2P_GO, 154 | WIFI_PEER_P2P_CLIENT, 155 | WIFI_PEER_NAN, 156 | WIFI_PEER_TDLS, 157 | WIFI_PEER_INVALID, 158 | } wifi_peer_type; 159 | 160 | /* per peer statistics */ 161 | typedef struct { 162 | wifi_peer_type type; // peer type (AP, TDLS, GO etc.) 163 | u8 peer_mac_address[6]; // mac address 164 | u32 capabilities; // peer WIFI_CAPABILITY_XXX 165 | u32 num_rate; // number of rates 166 | wifi_rate_stat rate_stats[]; // per rate statistics, number of entries = num_rate 167 | } wifi_peer_info; 168 | 169 | /* Per access category statistics */ 170 | typedef struct { 171 | wifi_traffic_ac ac; // access category (VI, VO, BE, BK) 172 | u32 tx_mpdu; // number of successfully transmitted unicast data pkts (ACK rcvd) 173 | u32 rx_mpdu; // number of received unicast data packets 174 | u32 tx_mcast; // number of succesfully transmitted multicast data packets 175 | // STA case: implies ACK received from AP for the unicast packet in which mcast pkt was sent 176 | u32 rx_mcast; // number of received multicast data packets 177 | u32 rx_ampdu; // number of received unicast a-mpdus; support of this counter is optional 178 | u32 tx_ampdu; // number of transmitted unicast a-mpdus; support of this counter is optional 179 | u32 mpdu_lost; // number of data pkt losses (no ACK) 180 | u32 retries; // total number of data pkt retries 181 | u32 retries_short; // number of short data pkt retries 182 | u32 retries_long; // number of long data pkt retries 183 | u32 contention_time_min; // data pkt min contention time (usecs) 184 | u32 contention_time_max; // data pkt max contention time (usecs) 185 | u32 contention_time_avg; // data pkt avg contention time (usecs) 186 | u32 contention_num_samples; // num of data pkts used for contention statistics 187 | } wifi_wmm_ac_stat; 188 | 189 | /* interface statistics */ 190 | typedef struct { 191 | wifi_interface_handle iface; // wifi interface 192 | wifi_interface_link_layer_info info; // current state of the interface 193 | u32 beacon_rx; // access point beacon received count from connected AP 194 | u64 average_tsf_offset; // average beacon offset encountered (beacon_TSF - TBTT) 195 | // The average_tsf_offset field is used so as to calculate the 196 | // typical beacon contention time on the channel as well may be 197 | // used to debug beacon synchronization and related power consumption issue 198 | u32 leaky_ap_detected; // indicate that this AP typically leaks packets beyond the driver guard time. 199 | u32 leaky_ap_avg_num_frames_leaked; // average number of frame leaked by AP after frame with PM bit set was ACK'ed by AP 200 | u32 leaky_ap_guard_time; // guard time currently in force (when implementing IEEE power management based on 201 | // frame control PM bit), How long driver waits before shutting down the radio and 202 | // after receiving an ACK for a data frame with PM bit set) 203 | u32 mgmt_rx; // access point mgmt frames received count from connected AP (including Beacon) 204 | u32 mgmt_action_rx; // action frames received count 205 | u32 mgmt_action_tx; // action frames transmit count 206 | wifi_rssi rssi_mgmt; // access Point Beacon and Management frames RSSI (averaged) 207 | wifi_rssi rssi_data; // access Point Data Frames RSSI (averaged) from connected AP 208 | wifi_rssi rssi_ack; // access Point ACK RSSI (averaged) from connected AP 209 | wifi_wmm_ac_stat ac[WIFI_AC_MAX]; // per ac data packet statistics 210 | u32 num_peers; // number of peers 211 | wifi_peer_info peer_info[]; // per peer statistics 212 | } wifi_iface_stat; 213 | 214 | /* configuration params */ 215 | typedef struct { 216 | u32 mpdu_size_threshold; // threshold to classify the pkts as short or long 217 | // packet size < mpdu_size_threshold => short 218 | u32 aggressive_statistics_gathering; // set for field debug mode. Driver should collect all statistics regardless of performance impact. 219 | } wifi_link_layer_params; 220 | 221 | /* API to trigger the link layer statistics collection. 222 | Unless his API is invoked - link layer statistics will not be collected. 223 | Radio statistics (once started) do not stop or get reset unless wifi_clear_link_stats is invoked 224 | Interface statistics (once started) reset and start afresh after each connection */ 225 | wifi_error wifi_set_link_stats(wifi_interface_handle iface, wifi_link_layer_params params); 226 | 227 | /* callback for reporting link layer stats */ 228 | typedef struct { 229 | void (*on_link_stats_results) (wifi_request_id id, wifi_iface_stat *iface_stat, 230 | int num_radios, wifi_radio_stat *radio_stat); 231 | } wifi_stats_result_handler; 232 | 233 | /* api to collect the link layer statistics for a given iface and all the radio stats */ 234 | wifi_error wifi_get_link_stats(wifi_request_id id, 235 | wifi_interface_handle iface, wifi_stats_result_handler handler); 236 | 237 | /* wifi statistics bitmap */ 238 | #define WIFI_STATS_RADIO 0x00000001 // all radio statistics 239 | #define WIFI_STATS_RADIO_CCA 0x00000002 // cca_busy_time (within radio statistics) 240 | #define WIFI_STATS_RADIO_CHANNELS 0x00000004 // all channel statistics (within radio statistics) 241 | #define WIFI_STATS_RADIO_SCAN 0x00000008 // all scan statistics (within radio statistics) 242 | #define WIFI_STATS_IFACE 0x00000010 // all interface statistics 243 | #define WIFI_STATS_IFACE_TXRATE 0x00000020 // all tx rate statistics (within interface statistics) 244 | #define WIFI_STATS_IFACE_AC 0x00000040 // all ac statistics (within interface statistics) 245 | #define WIFI_STATS_IFACE_CONTENTION 0x00000080 // all contention (min, max, avg) statistics (within ac statisctics) 246 | 247 | /* clear api to reset statistics, stats_clear_rsp_mask identifies what stats have been cleared 248 | stop_req = 1 will imply whether to stop the statistics collection. 249 | stop_rsp = 1 will imply that stop_req was honored and statistics collection was stopped. 250 | */ 251 | wifi_error wifi_clear_link_stats(wifi_interface_handle iface, 252 | u32 stats_clear_req_mask, u32 *stats_clear_rsp_mask, u8 stop_req, u8 *stop_rsp); 253 | 254 | #ifdef __cplusplus 255 | } 256 | #endif /* __cplusplus */ 257 | 258 | #endif /*__WIFI_HAL_STATS_ */ 259 | 260 | -------------------------------------------------------------------------------- /include/hardware_legacy/power.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef _HARDWARE_POWER_H 18 | #define _HARDWARE_POWER_H 19 | 20 | #include 21 | 22 | #if __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | enum { 27 | PARTIAL_WAKE_LOCK = 1, // the cpu stays on, but the screen is off 28 | FULL_WAKE_LOCK = 2 // the screen is also on 29 | }; 30 | 31 | // while you have a lock held, the device will stay on at least at the 32 | // level you request. 33 | int acquire_wake_lock(int lock, const char* id); 34 | int release_wake_lock(const char* id); 35 | 36 | 37 | #if __cplusplus 38 | } // extern "C" 39 | #endif 40 | 41 | #endif // _HARDWARE_POWER_H 42 | -------------------------------------------------------------------------------- /include/hardware_legacy/qemu_tracing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef _HARDWARE_QEMU_TRACING_H 18 | #define _HARDWARE_QEMU_TRACING_H 19 | 20 | #if __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | int qemu_start_tracing(); 25 | int qemu_stop_tracing(); 26 | int qemu_add_mapping(unsigned int addr, const char *name); 27 | int qemu_remove_mapping(unsigned int addr); 28 | 29 | #if __cplusplus 30 | } // extern "C" 31 | #endif 32 | 33 | #endif // _HARDWARE_QEMU_TRACING_H 34 | -------------------------------------------------------------------------------- /include/hardware_legacy/rtt.h: -------------------------------------------------------------------------------- 1 | 2 | #include "wifi_hal.h" 3 | #include "gscan.h" 4 | 5 | #ifndef __WIFI_HAL_RTT_H__ 6 | #define __WIFI_HAL_RTT_H__ 7 | 8 | /* Ranging status */ 9 | typedef enum { 10 | RTT_STATUS_SUCCESS = 0, 11 | RTT_STATUS_FAILURE = 1, // general failure status 12 | RTT_STATUS_FAIL_NO_RSP = 2, // target STA does not respond to request 13 | RTT_STATUS_FAIL_REJECTED = 3, // request rejected. Applies to 2-sided RTT only 14 | RTT_STATUS_FAIL_NOT_SCHEDULED_YET = 4, 15 | RTT_STATUS_FAIL_TM_TIMEOUT = 5, // timing measurement times out 16 | RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL = 6, // Target on different channel, cannot range 17 | RTT_STATUS_FAIL_NO_CAPABILITY = 7, // ranging not supported 18 | RTT_STATUS_ABORTED = 8, // request aborted for unknown reason 19 | RTT_STATUS_FAIL_INVALID_TS = 9, // Invalid T1-T4 timestamp 20 | RTT_STATUS_FAIL_PROTOCOL = 10, // 11mc protocol failed 21 | RTT_STATUS_FAIL_SCHEDULE = 11, // request could not be scheduled 22 | RTT_STATUS_FAIL_BUSY_TRY_LATER = 12, // responder cannot collaborate at time of request 23 | RTT_STATUS_INVALID_REQ = 13, // bad request args 24 | RTT_STATUS_NO_WIFI = 14, // WiFi not enabled 25 | RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE = 15 // Responder overrides param info, cannot range with new params 26 | } wifi_rtt_status; 27 | 28 | /* RTT peer type */ 29 | typedef enum { 30 | RTT_PEER_AP = 0x1, 31 | RTT_PEER_STA = 0x2, 32 | RTT_PEER_P2P_GO = 0x3, 33 | RTT_PEER_P2P_CLIENT = 0x4, 34 | RTT_PEER_NAN = 0x5 35 | } rtt_peer_type; 36 | 37 | /* RTT Measurement Bandwidth */ 38 | typedef enum { 39 | WIFI_RTT_BW_5 = 0x01, 40 | WIFI_RTT_BW_10 = 0x02, 41 | WIFI_RTT_BW_20 = 0x04, 42 | WIFI_RTT_BW_40 = 0x08, 43 | WIFI_RTT_BW_80 = 0x10, 44 | WIFI_RTT_BW_160 = 0x20 45 | } wifi_rtt_bw; 46 | 47 | /* RTT Measurement Preamble */ 48 | typedef enum { 49 | WIFI_RTT_PREAMBLE_LEGACY = 0x1, 50 | WIFI_RTT_PREAMBLE_HT = 0x2, 51 | WIFI_RTT_PREAMBLE_VHT = 0x4 52 | } wifi_rtt_preamble; 53 | 54 | /* RTT Type */ 55 | typedef enum { 56 | RTT_TYPE_1_SIDED = 0x1, 57 | RTT_TYPE_2_SIDED = 0x2, 58 | } wifi_rtt_type; 59 | 60 | /* RTT configuration */ 61 | typedef struct { 62 | mac_addr addr; // peer device mac address 63 | wifi_rtt_type type; // 1-sided or 2-sided RTT 64 | rtt_peer_type peer; // optional - peer device hint (STA, P2P, AP) 65 | wifi_channel_info channel; // Required for STA-AP mode, optional for P2P, NBD etc. 66 | unsigned burst_period; // Time interval between bursts (units: 100 ms). 67 | // Applies to 1-sided and 2-sided RTT multi-burst requests. 68 | // Range: 0-31, 0: no preference by initiator (2-sided RTT) 69 | unsigned num_burst; // Total number of RTT bursts to be executed. It will be 70 | // specified in the same way as the parameter "Number of 71 | // Burst Exponent" found in the FTM frame format. It 72 | // applies to both: 1-sided RTT and 2-sided RTT. Valid 73 | // values are 0 to 15 as defined in 802.11mc std. 74 | // 0 means single shot 75 | // The implication of this parameter on the maximum 76 | // number of RTT results is the following: 77 | // for 1-sided RTT: max num of RTT results = (2^num_burst)*(num_frames_per_burst) 78 | // for 2-sided RTT: max num of RTT results = (2^num_burst)*(num_frames_per_burst - 1) 79 | unsigned num_frames_per_burst; // num of frames per burst. 80 | // Minimum value = 1, Maximum value = 31 81 | // For 2-sided this equals the number of FTM frames 82 | // to be attempted in a single burst. This also 83 | // equals the number of FTM frames that the 84 | // initiator will request that the responder send 85 | // in a single frame. 86 | unsigned num_retries_per_rtt_frame; // number of retries for a failed RTT frame. Applies 87 | // to 1-sided RTT only. Minimum value = 0, Maximum value = 3 88 | 89 | //following fields are only valid for 2-side RTT 90 | unsigned num_retries_per_ftmr; // Maximum number of retries that the initiator can 91 | // retry an FTMR frame. 92 | // Minimum value = 0, Maximum value = 3 93 | byte LCI_request; // 1: request LCI, 0: do not request LCI 94 | byte LCR_request; // 1: request LCR, 0: do not request LCR 95 | unsigned burst_duration; // Applies to 1-sided and 2-sided RTT. Valid values will 96 | // be 2-11 and 15 as specified by the 802.11mc std for 97 | // the FTM parameter burst duration. In a multi-burst 98 | // request, if responder overrides with larger value, 99 | // the initiator will return failure. In a single-burst 100 | // request if responder overrides with larger value, 101 | // the initiator will sent TMR_STOP to terminate RTT 102 | // at the end of the burst_duration it requested. 103 | wifi_rtt_preamble preamble; // RTT preamble to be used in the RTT frames 104 | wifi_rtt_bw bw; // RTT BW to be used in the RTT frames 105 | } wifi_rtt_config; 106 | 107 | /* RTT results */ 108 | typedef struct { 109 | mac_addr addr; // device mac address 110 | unsigned burst_num; // burst number in a multi-burst request 111 | unsigned measurement_number; // Total RTT measurement frames attempted 112 | unsigned success_number; // Total successful RTT measurement frames 113 | byte number_per_burst_peer; // Maximum number of "FTM frames per burst" supported by 114 | // the responder STA. Applies to 2-sided RTT only. 115 | // If reponder overrides with larger value: 116 | // - for single-burst request initiator will truncate the 117 | // larger value and send a TMR_STOP after receiving as 118 | // many frames as originally requested. 119 | // - for multi-burst request, initiator will return 120 | // failure right away. 121 | wifi_rtt_status status; // ranging status 122 | byte retry_after_duration; // When status == RTT_STATUS_FAIL_BUSY_TRY_LATER, 123 | // this will be the time provided by the responder as to 124 | // when the request can be tried again. Applies to 2-sided 125 | // RTT only. In sec, 1-31sec. 126 | wifi_rtt_type type; // RTT type 127 | wifi_rssi rssi; // average rssi in 0.5 dB steps e.g. 143 implies -71.5 dB 128 | wifi_rssi rssi_spread; // rssi spread in 0.5 dB steps e.g. 5 implies 2.5 dB spread (optional) 129 | wifi_rate tx_rate; // 1-sided RTT: TX rate of RTT frame. 130 | // 2-sided RTT: TX rate of initiator's Ack in response to FTM frame. 131 | wifi_rate rx_rate; // 1-sided RTT: TX rate of Ack from other side. 132 | // 2-sided RTT: TX rate of FTM frame coming from responder. 133 | wifi_timespan rtt; // round trip time in picoseconds 134 | wifi_timespan rtt_sd; // rtt standard deviation in picoseconds 135 | wifi_timespan rtt_spread; // difference between max and min rtt times recorded in picoseconds 136 | int distance_mm; // distance in mm (optional) 137 | int distance_sd_mm; // standard deviation in mm (optional) 138 | int distance_spread_mm; // difference between max and min distance recorded in mm (optional) 139 | wifi_timestamp ts; // time of the measurement (in microseconds since boot) 140 | int burst_duration; // in ms, actual time taken by the FW to finish one burst 141 | // measurement. Applies to 1-sided and 2-sided RTT. 142 | int negotiated_burst_num; // Number of bursts allowed by the responder. Applies 143 | // to 2-sided RTT only. 144 | wifi_information_element *LCI; // for 11mc only 145 | wifi_information_element *LCR; // for 11mc only 146 | } wifi_rtt_result; 147 | 148 | /* RTT result callback */ 149 | typedef struct { 150 | void (*on_rtt_results) (wifi_request_id id, unsigned num_results, wifi_rtt_result *rtt_result[]); 151 | } wifi_rtt_event_handler; 152 | 153 | /* API to request RTT measurement */ 154 | wifi_error wifi_rtt_range_request(wifi_request_id id, wifi_interface_handle iface, 155 | unsigned num_rtt_config, wifi_rtt_config rtt_config[], wifi_rtt_event_handler handler); 156 | 157 | /* API to cancel RTT measurements */ 158 | wifi_error wifi_rtt_range_cancel(wifi_request_id id, wifi_interface_handle iface, 159 | unsigned num_devices, mac_addr addr[]); 160 | 161 | /* NBD ranging channel map */ 162 | typedef struct { 163 | wifi_channel availablity[32]; // specifies the channel map for each of the 16 TU windows 164 | // frequency of 0 => unspecified; which means firmware is 165 | // free to do whatever it wants in this window. 166 | } wifi_channel_map; 167 | 168 | /* API to start publishing the channel map on responder device in a NBD cluster. 169 | Responder device will take this request and schedule broadcasting the channel map 170 | in a NBD ranging attribute in a SDF. DE will automatically remove the ranging 171 | attribute from the OTA queue after number of DW specified by num_dw 172 | where Each DW is 512 TUs apart */ 173 | wifi_error wifi_rtt_channel_map_set(wifi_request_id id, 174 | wifi_interface_handle iface, wifi_channel_map *params, unsigned num_dw); 175 | 176 | /* API to clear the channel map on the responder device in a NBD cluster. 177 | Responder device will cancel future ranging channel request, starting from “next” 178 | DW interval and will also stop broadcasting NBD ranging attribute in SDF */ 179 | wifi_error wifi_rtt_channel_map_clear(wifi_request_id id, wifi_interface_handle iface); 180 | 181 | // Preamble definition for bit mask used in wifi_rtt_capabilities 182 | #define PREAMBLE_LEGACY 0x1 183 | #define PREAMBLE_HT 0x2 184 | #define PREAMBLE_VHT 0x4 185 | 186 | // BW definition for bit mask used in wifi_rtt_capabilities 187 | #define BW_5_SUPPORT 0x1 188 | #define BW_10_SUPPORT 0x2 189 | #define BW_20_SUPPORT 0x4 190 | #define BW_40_SUPPORT 0x8 191 | #define BW_80_SUPPORT 0x10 192 | #define BW_160_SUPPORT 0x20 193 | 194 | /* RTT Capabilities */ 195 | typedef struct { 196 | byte rtt_one_sided_supported; // if 1-sided rtt data collection is supported 197 | byte rtt_ftm_supported; // if ftm rtt data collection is supported 198 | byte lci_support; // if initiator supports LCI request. Applies to 2-sided RTT 199 | byte lcr_support; // if initiator supports LCR request. Applies to 2-sided RTT 200 | byte preamble_support; // bit mask indicates what preamble is supported by initiator 201 | byte bw_support; // bit mask indicates what BW is supported by initiator 202 | byte responder_supported; // if 11mc responder mode is supported 203 | byte mc_version; // draft 11mc spec version supported by chip. For instance, 204 | // version 4.0 should be 40 and version 4.3 should be 43 etc. 205 | } wifi_rtt_capabilities; 206 | 207 | /* RTT capabilities of the device */ 208 | wifi_error wifi_get_rtt_capabilities(wifi_interface_handle iface, wifi_rtt_capabilities *capabilities); 209 | 210 | /* debugging definitions */ 211 | enum { 212 | RTT_DEBUG_DISABLE, 213 | RTT_DEBUG_LOG, 214 | RTT_DEBUG_PROTO, 215 | RTT_DEBUG_BURST, 216 | RTT_DEBUG_ACCURACY, 217 | RTT_DEBUG_LOGDETAIL 218 | }; //rtt debug type 219 | 220 | enum { 221 | RTT_DEBUG_FORMAT_TXT, 222 | RTT_DEBUG_FORMAT_BINARY 223 | }; //rtt debug format 224 | 225 | typedef struct rtt_debug { 226 | unsigned version; 227 | unsigned len; // total length of after len field 228 | unsigned type; // rtt debug type 229 | unsigned format; //rtt debug format 230 | char dbuf[0]; // debug content 231 | } rtt_debug_t; 232 | 233 | /* set configuration for debug */ 234 | wifi_error wifi_rtt_debug_cfg(wifi_interface_handle h, unsigned rtt_dbg_type, char *cfgbuf, unsigned cfg_buf_size); 235 | /* get the debug information */ 236 | wifi_error wifi_rtt_debug_get(wifi_interface_handle h, rtt_debug_t **debugbuf); 237 | /* free the debug buffer */ 238 | wifi_error wifi_rtt_debug_free(wifi_interface_handle h, rtt_debug_t *debugbuf); 239 | 240 | /* API for setting LCI/LCR information to be provided to a requestor */ 241 | typedef enum { 242 | WIFI_MOTION_NOT_EXPECTED = 0, // Not expected to change location 243 | WIFI_MOTION_EXPECTED = 1, // Expected to change location 244 | WIFI_MOTION_UNKNOWN = 2, // Movement pattern unknown 245 | } wifi_motion_pattern; 246 | 247 | typedef struct { 248 | long latitude; // latitude in degrees * 2^25 , 2's complement 249 | long longitude; // latitude in degrees * 2^25 , 2's complement 250 | int altitude; // Altitude in units of 1/256 m 251 | byte latitude_unc; // As defined in Section 2.3.2 of IETF RFC 6225 252 | byte longitude_unc; // As defined in Section 2.3.2 of IETF RFC 6225 253 | byte altitude_unc; // As defined in Section 2.4.5 from IETF RFC 6225: 254 | 255 | //Following element for configuring the Z subelement 256 | wifi_motion_pattern motion_pattern; 257 | int floor; // floor in units of 1/16th of floor. 0x80000000 if unknown. 258 | int height_above_floor; // in units of 1/64 m 259 | int height_unc; // in units of 1/64 m. 0 if unknown 260 | } wifi_lci_information; 261 | 262 | typedef struct { 263 | char country_code[2]; // country code 264 | int length; // length of the info field 265 | char civic_info[256]; // Civic info to be copied in FTM frame 266 | } wifi_lcr_information; 267 | 268 | // API to configure the LCI. Used in RTT Responder mode only 269 | wifi_error wifi_set_lci(wifi_request_id id, wifi_interface_handle iface, 270 | wifi_lci_information *lci); 271 | 272 | // API to configure the LCR. Used in RTT Responder mode only. 273 | wifi_error wifi_set_lcr(wifi_request_id id, wifi_interface_handle iface, 274 | wifi_lcr_information *lcr); 275 | 276 | /** 277 | * RTT Responder information 278 | */ 279 | typedef struct { 280 | wifi_channel_info channel; 281 | wifi_rtt_preamble preamble; 282 | } wifi_rtt_responder; 283 | 284 | /** 285 | * Get RTT responder information e.g. WiFi channel to enable responder on. 286 | */ 287 | wifi_error wifi_rtt_get_responder_info(wifi_interface_handle iface, 288 | wifi_rtt_responder *responder_info); 289 | 290 | /** 291 | * Enable RTT responder mode. 292 | * channel_hint - hint of the channel information where RTT responder should be enabled on. 293 | * max_duration_seconds - timeout of responder mode. 294 | * channel_used - channel used for RTT responder, NULL if responder is not enabled. 295 | */ 296 | wifi_error wifi_enable_responder(wifi_request_id id, wifi_interface_handle iface, 297 | wifi_channel_info channel_hint, unsigned max_duration_seconds, 298 | wifi_rtt_responder *responder_info); 299 | 300 | /** 301 | * Disable RTT responder mode. 302 | */ 303 | wifi_error wifi_disable_responder(wifi_request_id id, wifi_interface_handle iface); 304 | 305 | #endif 306 | -------------------------------------------------------------------------------- /include/hardware_legacy/tdls.h: -------------------------------------------------------------------------------- 1 | 2 | #include "wifi_hal.h" 3 | 4 | #ifndef _TDLS_H_ 5 | #define _TDLS_H_ 6 | 7 | typedef enum { 8 | WIFI_TDLS_DISABLED = 1, /* TDLS is not enabled, default status for all STAs */ 9 | WIFI_TDLS_ENABLED, /* TDLS is enabled, but not yet tried */ 10 | WIFI_TDLS_ESTABLISHED, /* Direct link is established */ 11 | WIFI_TDLS_ESTABLISHED_OFF_CHANNEL, /* Direct link is established using MCC */ 12 | WIFI_TDLS_DROPPED, /* Direct link was established, 13 | * but is temporarily dropped now */ 14 | WIFI_TDLS_FAILED /* TDLS permanent failed. Inform error to upper layer 15 | * and go back to WIFI_TDLS_DISABLED */ 16 | } wifi_tdls_state; 17 | 18 | typedef enum { 19 | WIFI_TDLS_SUCCESS, /* Success */ 20 | WIFI_TDLS_UNSPECIFIED = -1, /* Unspecified reason */ 21 | WIFI_TDLS_NOT_SUPPORTED = -2, /* Remote side doesn't support TDLS */ 22 | WIFI_TDLS_UNSUPPORTED_BAND = -3, /* Remote side doesn't support this band */ 23 | WIFI_TDLS_NOT_BENEFICIAL = -4, /* Going to AP is better than going direct */ 24 | WIFI_TDLS_DROPPED_BY_REMOTE = -5 /* Remote side doesn't want it anymore */ 25 | } wifi_tdls_reason; 26 | 27 | typedef struct { 28 | int channel; /* channel hint, in channel number (NOT frequency ) */ 29 | int global_operating_class; /* operating class to use */ 30 | int max_latency_ms; /* max latency that can be tolerated by apps */ 31 | int min_bandwidth_kbps; /* bandwidth required by apps, in kilo bits per second */ 32 | } wifi_tdls_params; 33 | 34 | typedef struct { 35 | int channel; 36 | int global_operating_class; 37 | wifi_tdls_state state; 38 | wifi_tdls_reason reason; 39 | } wifi_tdls_status; 40 | 41 | typedef struct { 42 | int max_concurrent_tdls_session_num; /* Maximum TDLS session number can be supported by the 43 | * Firmware and hardware*/ 44 | int is_global_tdls_supported; /* 1 -- support, 0 -- not support */ 45 | int is_per_mac_tdls_supported; /* 1 -- support, 0 -- not support */ 46 | int is_off_channel_tdls_supported; /* 1 -- support, 0 -- not support */ 47 | } wifi_tdls_capabilities; 48 | 49 | typedef struct { 50 | /* on_tdls_state_changed - reports state of TDLS link to framework 51 | * Report this event when the state of TDLS link changes */ 52 | void (*on_tdls_state_changed)(mac_addr addr, wifi_tdls_status status); 53 | } wifi_tdls_handler; 54 | 55 | 56 | /* wifi_enable_tdls - enables TDLS-auto mode for a specific route 57 | * 58 | * params specifies hints, which provide more information about 59 | * why TDLS is being sought. The firmware should do its best to 60 | * honor the hints before downgrading regular AP link 61 | * If upper layer has no specific values, this should be NULL 62 | * 63 | * handler is used to inform the upper layer about the status change and the corresponding reason 64 | */ 65 | wifi_error wifi_enable_tdls(wifi_interface_handle iface, mac_addr addr, 66 | wifi_tdls_params *params, wifi_tdls_handler handler); 67 | 68 | /* wifi_disable_tdls - disables TDLS-auto mode for a specific route 69 | * 70 | * This terminates any existing TDLS with addr device, and frees the 71 | * device resources to make TDLS connections on new routes. 72 | * 73 | * DON'T fire any more events on 'handler' specified in earlier call to 74 | * wifi_enable_tdls after this action. 75 | */ 76 | wifi_error wifi_disable_tdls(wifi_interface_handle iface, mac_addr addr); 77 | 78 | /* wifi_get_tdls_status - allows getting the status of TDLS for a specific route */ 79 | wifi_error wifi_get_tdls_status(wifi_interface_handle iface, mac_addr addr, 80 | wifi_tdls_status *status); 81 | 82 | /* return the current HW + Firmware combination's TDLS capabilities */ 83 | wifi_error wifi_get_tdls_capabilities(wifi_interface_handle iface, 84 | wifi_tdls_capabilities *capabilities); 85 | #endif 86 | -------------------------------------------------------------------------------- /include/hardware_legacy/uevent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef _HARDWARE_UEVENT_H 18 | #define _HARDWARE_UEVENT_H 19 | 20 | #if __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | int uevent_init(); 25 | int uevent_get_fd(); 26 | int uevent_next_event(char* buffer, int buffer_length); 27 | int uevent_add_native_handler(void (*handler)(void *data, const char *msg, int msg_len), 28 | void *handler_data); 29 | int uevent_remove_native_handler(void (*handler)(void *data, const char *msg, int msg_len)); 30 | 31 | #if __cplusplus 32 | } // extern "C" 33 | #endif 34 | 35 | #endif // _HARDWARE_UEVENT_H 36 | -------------------------------------------------------------------------------- /include/hardware_legacy/wifi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef _WIFI_H 18 | #define _WIFI_H 19 | 20 | #if __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /** 25 | * Load the Wi-Fi driver. 26 | * 27 | * @return 0 on success, < 0 on failure. 28 | */ 29 | int wifi_load_driver(); 30 | 31 | /** 32 | * Unload the Wi-Fi driver. 33 | * 34 | * @return 0 on success, < 0 on failure. 35 | */ 36 | int wifi_unload_driver(); 37 | 38 | /** 39 | * Check if the Wi-Fi driver is loaded. 40 | * Check if the Wi-Fi driver is loaded. 41 | 42 | * @return 0 on success, < 0 on failure. 43 | */ 44 | int is_wifi_driver_loaded(); 45 | 46 | 47 | /** 48 | * Start supplicant. 49 | * 50 | * @return 0 on success, < 0 on failure. 51 | */ 52 | int wifi_start_supplicant(int p2pSupported); 53 | 54 | /** 55 | * Stop supplicant. 56 | * 57 | * @return 0 on success, < 0 on failure. 58 | */ 59 | int wifi_stop_supplicant(int p2pSupported); 60 | 61 | /** 62 | * Open a connection to supplicant 63 | * 64 | * @return 0 on success, < 0 on failure. 65 | */ 66 | int wifi_connect_to_supplicant(); 67 | 68 | /** 69 | * Close connection to supplicant 70 | * 71 | * @return 0 on success, < 0 on failure. 72 | */ 73 | void wifi_close_supplicant_connection(); 74 | 75 | /** 76 | * wifi_wait_for_event() performs a blocking call to 77 | * get a Wi-Fi event and returns a string representing 78 | * a Wi-Fi event when it occurs. 79 | * 80 | * @param buf is the buffer that receives the event 81 | * @param len is the maximum length of the buffer 82 | * 83 | * @returns number of bytes in buffer, 0 if no 84 | * event (for instance, no connection), and less than 0 85 | * if there is an error. 86 | */ 87 | int wifi_wait_for_event(char *buf, size_t len); 88 | 89 | /** 90 | * wifi_command() issues a command to the Wi-Fi driver. 91 | * 92 | * Android extends the standard commands listed at 93 | * /link http://hostap.epitest.fi/wpa_supplicant/devel/ctrl_iface_page.html 94 | * to include support for sending commands to the driver: 95 | * 96 | * See wifi/java/android/net/wifi/WifiNative.java for the details of 97 | * driver commands that are supported 98 | * 99 | * @param command is the string command (preallocated with 32 bytes) 100 | * @param commandlen is command buffer length 101 | * @param reply is a buffer to receive a reply string 102 | * @param reply_len on entry, this is the maximum length of 103 | * the reply buffer. On exit, the number of 104 | * bytes in the reply buffer. 105 | * 106 | * @return 0 if successful, < 0 if an error. 107 | */ 108 | int wifi_command(const char *command, char *reply, size_t *reply_len); 109 | 110 | /** 111 | * do_dhcp_request() issues a dhcp request and returns the acquired 112 | * information. 113 | * 114 | * All IPV4 addresses/mask are in network byte order. 115 | * 116 | * @param ipaddr return the assigned IPV4 address 117 | * @param gateway return the gateway being used 118 | * @param mask return the IPV4 mask 119 | * @param dns1 return the IPV4 address of a DNS server 120 | * @param dns2 return the IPV4 address of a DNS server 121 | * @param server return the IPV4 address of DHCP server 122 | * @param lease return the length of lease in seconds. 123 | * 124 | * @return 0 if successful, < 0 if error. 125 | */ 126 | int do_dhcp_request(int *ipaddr, int *gateway, int *mask, 127 | int *dns1, int *dns2, int *server, int *lease); 128 | 129 | /** 130 | * Return the error string of the last do_dhcp_request(). 131 | */ 132 | const char *get_dhcp_error_string(); 133 | 134 | /** 135 | * Return the path to requested firmware 136 | */ 137 | #define WIFI_GET_FW_PATH_STA 0 138 | #define WIFI_GET_FW_PATH_AP 1 139 | #define WIFI_GET_FW_PATH_P2P 2 140 | const char *wifi_get_fw_path(int fw_type); 141 | 142 | /** 143 | * Change the path to firmware for the wlan driver 144 | */ 145 | int wifi_change_fw_path(const char *fwpath); 146 | 147 | /** 148 | * Set the wifi mode (0 = normal, 1 = ap) 149 | */ 150 | int wifi_set_mode(int mode); 151 | 152 | /** 153 | * Check and create if necessary initial entropy file 154 | */ 155 | #define WIFI_ENTROPY_FILE "/data/misc/wifi/entropy.bin" 156 | int ensure_entropy_file_exists(); 157 | 158 | /** 159 | * Check and create if necessary the desired configuration file 160 | */ 161 | int ensure_config_file_exists(const char *config_file, const char *config_file_template); 162 | 163 | #if __cplusplus 164 | }; // extern "C" 165 | #endif 166 | 167 | #endif // _WIFI_H 168 | -------------------------------------------------------------------------------- /include/hardware_legacy/wifi_config.h: -------------------------------------------------------------------------------- 1 | #include "wifi_hal.h" 2 | 3 | #ifndef __WIFI_HAL_CONFIG_H 4 | #define __WIFI_HAL_CONFIG_H 5 | 6 | #ifdef __cplusplus 7 | extern "C" 8 | { 9 | #endif /* __cplusplus */ 10 | 11 | #define CONFIG_MAJOR_VERSION 1 12 | #define CONFIG_MINOR_VERSION 0 13 | #define CONFIG_MICRO_VERSION 0 14 | 15 | typedef int wifi_radio; 16 | 17 | // whether the wifi chipset wakes at every dtim beacon or a multiple of the dtim period 18 | // if extended_dtim is set to 3, the STA shall wake up every 3 DTIM beacons 19 | wifi_error wifi_extended_dtim_config_set(wifi_request_id id, 20 | wifi_interface_handle iface, int extended_dtim); 21 | 22 | //set the country code to driver 23 | wifi_error wifi_set_country_code(wifi_interface_handle iface, const char* country_code); 24 | 25 | //set the wifi_iface stats averaging factor used to calculate 26 | // statistics like average the TSF offset or average number of frame leaked 27 | // For instance, upon beacon reception: 28 | // current_avg = ((beacon_TSF - TBTT) * factor + previous_avg * (0x10000 - factor) ) / 0x10000 29 | // For instance, when evaluating leaky APs: 30 | // current_avg = ((num frame received within guard time) * factor + previous_avg * (0x10000 - factor)) / 0x10000 31 | 32 | wifi_error wifi_set_beacon_wifi_iface_stats_averaging_factor(wifi_request_id id, wifi_interface_handle iface, 33 | u16 factor); 34 | 35 | // configure guard time, i.e. when implementing IEEE power management based on 36 | // frame control PM bit, how long driver waits before shutting down the radio and 37 | // after receiving an ACK for a data frame with PM bit set 38 | wifi_error wifi_set_guard_time(wifi_request_id id, wifi_interface_handle iface, 39 | u32 guard_time); 40 | 41 | #ifdef __cplusplus 42 | } 43 | 44 | #endif /* __cplusplus */ 45 | 46 | #endif /*__WIFI_HAL_STATS_ */ 47 | 48 | -------------------------------------------------------------------------------- /include/hardware_legacy/wifi_offload.h: -------------------------------------------------------------------------------- 1 | #include "wifi_hal.h" 2 | 3 | #ifndef __WIFI_HAL_OFFLOAD_H 4 | #define __WIFI_HAL_OFFLOAD_H 5 | 6 | #ifdef __cplusplus 7 | extern "C" 8 | { 9 | #endif /* __cplusplus */ 10 | 11 | #define ETHER_ADDR_LEN 6 // Ethernet frame address length 12 | #define N_AVAIL_ID 3 // available mkeep_alive IDs from 1 to 3 13 | #define MKEEP_ALIVE_IP_PKT_MAX 256 // max size of IP packet for keep alive 14 | 15 | /** 16 | * Send specified keep alive packet periodically. 17 | */ 18 | wifi_error wifi_start_sending_offloaded_packet(wifi_request_id id, wifi_interface_handle iface, 19 | u8 *ip_packet, u16 ip_packet_len, u8 *src_mac_addr, u8 *dst_mac_addr, u32 period_msec); 20 | 21 | /** 22 | * Stop sending keep alive packet. 23 | */ 24 | wifi_error wifi_stop_sending_offloaded_packet(wifi_request_id id, wifi_interface_handle iface); 25 | 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif /* __cplusplus */ 30 | 31 | #endif /*__WIFI_HAL_OFFLOAD_H */ 32 | -------------------------------------------------------------------------------- /power/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2006 The Android Open Source Project 2 | 3 | LOCAL_SRC_FILES += power/power.c 4 | -------------------------------------------------------------------------------- /power/power.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define LOG_TAG "power" 29 | #include 30 | 31 | enum { 32 | ACQUIRE_PARTIAL_WAKE_LOCK = 0, 33 | RELEASE_WAKE_LOCK, 34 | OUR_FD_COUNT 35 | }; 36 | 37 | const char * const OLD_PATHS[] = { 38 | "/sys/android_power/acquire_partial_wake_lock", 39 | "/sys/android_power/release_wake_lock", 40 | }; 41 | 42 | const char * const NEW_PATHS[] = { 43 | "/sys/power/wake_lock", 44 | "/sys/power/wake_unlock", 45 | }; 46 | 47 | //XXX static pthread_once_t g_initialized = THREAD_ONCE_INIT; 48 | static int g_initialized = 0; 49 | static int g_fds[OUR_FD_COUNT]; 50 | static int g_error = -1; 51 | 52 | static int 53 | open_file_descriptors(const char * const paths[]) 54 | { 55 | int i; 56 | for (i=0; i 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #define QEMU_DEBUG 0 32 | 33 | #if QEMU_DEBUG 34 | # define D(...) ALOGD(__VA_ARGS__) 35 | #else 36 | # define D(...) ((void)0) 37 | #endif 38 | 39 | #include "hardware/qemu_pipe.h" 40 | 41 | int 42 | qemu_check(void) 43 | { 44 | static int in_qemu = -1; 45 | 46 | if (__builtin_expect(in_qemu < 0,0)) { 47 | char propBuf[PROPERTY_VALUE_MAX]; 48 | property_get("ro.kernel.qemu", propBuf, ""); 49 | in_qemu = (propBuf[0] == '1'); 50 | } 51 | return in_qemu; 52 | } 53 | 54 | static int 55 | qemu_fd_write( int fd, const char* cmd, int len ) 56 | { 57 | int len2; 58 | do { 59 | len2 = write(fd, cmd, len); 60 | } while (len2 < 0 && errno == EINTR); 61 | return len2; 62 | } 63 | 64 | static int 65 | qemu_fd_read( int fd, char* buff, int len ) 66 | { 67 | int len2; 68 | do { 69 | len2 = read(fd, buff, len); 70 | } while (len2 < 0 && errno == EINTR); 71 | return len2; 72 | } 73 | 74 | static int 75 | qemu_channel_open_qemud_pipe( QemuChannel* channel, 76 | const char* name ) 77 | { 78 | int fd; 79 | char pipe_name[512]; 80 | 81 | snprintf(pipe_name, sizeof(pipe_name), "qemud:%s", name); 82 | fd = qemu_pipe_open(pipe_name); 83 | if (fd < 0) { 84 | D("no qemud pipe: %s", strerror(errno)); 85 | return -1; 86 | } 87 | 88 | channel->is_qemud = 1; 89 | channel->fd = fd; 90 | return 0; 91 | } 92 | 93 | static int 94 | qemu_channel_open_qemud( QemuChannel* channel, 95 | const char* name ) 96 | { 97 | int fd, ret, namelen = strlen(name); 98 | char answer[2]; 99 | 100 | fd = socket_local_client( "qemud", 101 | ANDROID_SOCKET_NAMESPACE_RESERVED, 102 | SOCK_STREAM ); 103 | if (fd < 0) { 104 | D("no qemud control socket: %s", strerror(errno)); 105 | return -1; 106 | } 107 | 108 | /* send service name to connect */ 109 | if (qemu_fd_write(fd, name, namelen) != namelen) { 110 | D("can't send service name to qemud: %s", 111 | strerror(errno)); 112 | close(fd); 113 | return -1; 114 | } 115 | 116 | /* read answer from daemon */ 117 | if (qemu_fd_read(fd, answer, 2) != 2 || 118 | answer[0] != 'O' || answer[1] != 'K') { 119 | D("cant' connect to %s service through qemud", name); 120 | close(fd); 121 | return -1; 122 | } 123 | 124 | channel->is_qemud = 1; 125 | channel->fd = fd; 126 | return 0; 127 | } 128 | 129 | 130 | static int 131 | qemu_channel_open_qemud_old( QemuChannel* channel, 132 | const char* name ) 133 | { 134 | int fd; 135 | 136 | snprintf(channel->device, sizeof channel->device, 137 | "qemud_%s", name); 138 | 139 | fd = socket_local_client( channel->device, 140 | ANDROID_SOCKET_NAMESPACE_RESERVED, 141 | SOCK_STREAM ); 142 | if (fd < 0) { 143 | D("no '%s' control socket available: %s", 144 | channel->device, strerror(errno)); 145 | return -1; 146 | } 147 | 148 | close(fd); 149 | channel->is_qemud_old = 1; 150 | return 0; 151 | } 152 | 153 | 154 | static int 155 | qemu_channel_open_tty( QemuChannel* channel, 156 | const char* name, 157 | int mode ) 158 | { 159 | char key[PROPERTY_KEY_MAX]; 160 | char prop[PROPERTY_VALUE_MAX]; 161 | int ret; 162 | 163 | ret = snprintf(key, sizeof key, "ro.kernel.android.%s", name); 164 | if (ret >= (int)sizeof key) 165 | return -1; 166 | 167 | if (property_get(key, prop, "") == 0) { 168 | D("no kernel-provided %s device name", name); 169 | return -1; 170 | } 171 | 172 | ret = snprintf(channel->device, sizeof channel->device, 173 | "/dev/%s", prop); 174 | if (ret >= (int)sizeof channel->device) { 175 | D("%s device name too long: '%s'", name, prop); 176 | return -1; 177 | } 178 | 179 | channel->is_tty = !memcmp("/dev/tty", channel->device, 8); 180 | return 0; 181 | } 182 | 183 | int 184 | qemu_channel_open( QemuChannel* channel, 185 | const char* name, 186 | int mode ) 187 | { 188 | int fd = -1; 189 | 190 | /* initialize the channel is needed */ 191 | if (!channel->is_inited) 192 | { 193 | channel->is_inited = 1; 194 | 195 | do { 196 | if (qemu_channel_open_qemud_pipe(channel, name) == 0) 197 | break; 198 | 199 | if (qemu_channel_open_qemud(channel, name) == 0) 200 | break; 201 | 202 | if (qemu_channel_open_qemud_old(channel, name) == 0) 203 | break; 204 | 205 | if (qemu_channel_open_tty(channel, name, mode) == 0) 206 | break; 207 | 208 | channel->is_available = 0; 209 | return -1; 210 | } while (0); 211 | 212 | channel->is_available = 1; 213 | } 214 | 215 | /* try to open the file */ 216 | if (!channel->is_available) { 217 | errno = ENOENT; 218 | return -1; 219 | } 220 | 221 | if (channel->is_qemud) { 222 | return dup(channel->fd); 223 | } 224 | 225 | if (channel->is_qemud_old) { 226 | do { 227 | fd = socket_local_client( channel->device, 228 | ANDROID_SOCKET_NAMESPACE_RESERVED, 229 | SOCK_STREAM ); 230 | } while (fd < 0 && errno == EINTR); 231 | } 232 | else /* /dev/ttySn ? */ 233 | { 234 | do { 235 | fd = open(channel->device, mode); 236 | } while (fd < 0 && errno == EINTR); 237 | 238 | /* disable ECHO on serial lines */ 239 | if (fd >= 0 && channel->is_tty) { 240 | struct termios ios; 241 | tcgetattr( fd, &ios ); 242 | ios.c_lflag = 0; /* disable ECHO, ICANON, etc... */ 243 | tcsetattr( fd, TCSANOW, &ios ); 244 | } 245 | } 246 | return fd; 247 | } 248 | 249 | 250 | static int 251 | qemu_command_vformat( char* buffer, 252 | int buffer_size, 253 | const char* format, 254 | va_list args ) 255 | { 256 | char header[5]; 257 | int len; 258 | 259 | if (buffer_size < 6) 260 | return -1; 261 | 262 | len = vsnprintf(buffer+4, buffer_size-4, format, args); 263 | if (len >= buffer_size-4) 264 | return -1; 265 | 266 | snprintf(header, sizeof header, "%04x", len); 267 | memcpy(buffer, header, 4); 268 | return len + 4; 269 | } 270 | 271 | extern int 272 | qemu_command_format( char* buffer, 273 | int buffer_size, 274 | const char* format, 275 | ... ) 276 | { 277 | va_list args; 278 | int ret; 279 | 280 | va_start(args, format); 281 | ret = qemu_command_vformat(buffer, buffer_size, format, args); 282 | va_end(args); 283 | return ret; 284 | } 285 | 286 | 287 | static int 288 | qemu_control_fd(void) 289 | { 290 | static QemuChannel channel[1]; 291 | int fd; 292 | 293 | fd = qemu_channel_open( channel, "hw-control", O_RDWR ); 294 | if (fd < 0) { 295 | D("%s: could not open control channel: %s", __FUNCTION__, 296 | strerror(errno)); 297 | } 298 | return fd; 299 | } 300 | 301 | static int 302 | qemu_control_send(const char* cmd, int len) 303 | { 304 | int fd, len2; 305 | 306 | if (len < 0) { 307 | errno = EINVAL; 308 | return -1; 309 | } 310 | 311 | fd = qemu_control_fd(); 312 | if (fd < 0) 313 | return -1; 314 | 315 | len2 = qemu_fd_write(fd, cmd, len); 316 | close(fd); 317 | if (len2 != len) { 318 | D("%s: could not send everything %d < %d", 319 | __FUNCTION__, len2, len); 320 | return -1; 321 | } 322 | return 0; 323 | } 324 | 325 | 326 | int 327 | qemu_control_command( const char* fmt, ... ) 328 | { 329 | va_list args; 330 | char command[256]; 331 | int len, fd; 332 | 333 | va_start(args, fmt); 334 | len = qemu_command_vformat( command, sizeof command, fmt, args ); 335 | va_end(args); 336 | 337 | if (len < 0 || len >= (int)sizeof command) { 338 | if (len < 0) { 339 | D("%s: could not send: %s", __FUNCTION__, strerror(errno)); 340 | } else { 341 | D("%s: too large %d > %d", __FUNCTION__, len, (int)(sizeof command)); 342 | } 343 | errno = EINVAL; 344 | return -1; 345 | } 346 | 347 | return qemu_control_send( command, len ); 348 | } 349 | 350 | extern int qemu_control_query( const char* question, int questionlen, 351 | char* answer, int answersize ) 352 | { 353 | int ret, fd, len, result = -1; 354 | char header[5], *end; 355 | 356 | if (questionlen <= 0) { 357 | errno = EINVAL; 358 | return -1; 359 | } 360 | 361 | fd = qemu_control_fd(); 362 | if (fd < 0) 363 | return -1; 364 | 365 | ret = qemu_fd_write( fd, question, questionlen ); 366 | if (ret != questionlen) { 367 | D("%s: could not write all: %d < %d", __FUNCTION__, 368 | ret, questionlen); 369 | goto Exit; 370 | } 371 | 372 | /* read a 4-byte header giving the length of the following content */ 373 | ret = qemu_fd_read( fd, header, 4 ); 374 | if (ret != 4) { 375 | D("%s: could not read header (%d != 4)", 376 | __FUNCTION__, ret); 377 | goto Exit; 378 | } 379 | 380 | header[4] = 0; 381 | len = strtol( header, &end, 16 ); 382 | if ( len < 0 || end == NULL || end != header+4 || len > answersize ) { 383 | D("%s: could not parse header: '%s'", 384 | __FUNCTION__, header); 385 | goto Exit; 386 | } 387 | 388 | /* read the answer */ 389 | ret = qemu_fd_read( fd, answer, len ); 390 | if (ret != len) { 391 | D("%s: could not read all of answer %d < %d", 392 | __FUNCTION__, ret, len); 393 | goto Exit; 394 | } 395 | 396 | result = len; 397 | 398 | Exit: 399 | close(fd); 400 | return result; 401 | } 402 | -------------------------------------------------------------------------------- /qemu_tracing/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2007 The Android Open Source Project 2 | 3 | LOCAL_SRC_FILES += qemu_tracing/qemu_tracing.c 4 | 5 | -------------------------------------------------------------------------------- /qemu_tracing/qemu_tracing.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | // This is the pathname to the sysfs file that enables and disables 25 | // tracing on the qemu emulator. 26 | #define SYS_QEMU_TRACE_STATE "/sys/qemu_trace/state" 27 | 28 | 29 | // This is the pathname to the sysfs file that adds new (address, symbol) 30 | // pairs to the trace. 31 | #define SYS_QEMU_TRACE_SYMBOL "/sys/qemu_trace/symbol" 32 | 33 | // The maximum length of a symbol name 34 | #define MAX_SYMBOL_NAME_LENGTH (4 * 1024) 35 | 36 | // Allow space in the buffer for the address plus whitespace. 37 | #define MAX_BUF_SIZE (MAX_SYMBOL_NAME_LENGTH + 20) 38 | 39 | // return 0 on success, or an error if the qemu driver cannot be opened 40 | int qemu_start_tracing() 41 | { 42 | int fd = open(SYS_QEMU_TRACE_STATE, O_WRONLY); 43 | if (fd < 0) 44 | return fd; 45 | write(fd, "1\n", 2); 46 | close(fd); 47 | return 0; 48 | } 49 | 50 | int qemu_stop_tracing() 51 | { 52 | int fd = open(SYS_QEMU_TRACE_STATE, O_WRONLY); 53 | if (fd < 0) 54 | return fd; 55 | write(fd, "0\n", 2); 56 | close(fd); 57 | return 0; 58 | } 59 | 60 | int qemu_add_mapping(unsigned int addr, const char *name) 61 | { 62 | char buf[MAX_BUF_SIZE]; 63 | 64 | if (strlen(name) > MAX_SYMBOL_NAME_LENGTH) 65 | return EINVAL; 66 | int fd = open(SYS_QEMU_TRACE_SYMBOL, O_WRONLY); 67 | if (fd < 0) 68 | return fd; 69 | sprintf(buf, "%x %s\n", addr, name); 70 | write(fd, buf, strlen(buf)); 71 | close(fd); 72 | return 0; 73 | } 74 | 75 | int qemu_remove_mapping(unsigned int addr) 76 | { 77 | char buf[MAX_BUF_SIZE]; 78 | 79 | int fd = open(SYS_QEMU_TRACE_SYMBOL, O_WRONLY); 80 | if (fd < 0) 81 | return fd; 82 | sprintf(buf, "%x\n", addr); 83 | write(fd, buf, strlen(buf)); 84 | close(fd); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /uevent/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2008 The Android Open Source Project 2 | 3 | LOCAL_SRC_FILES += uevent/uevent.c 4 | -------------------------------------------------------------------------------- /uevent/uevent.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | LIST_HEAD(uevent_handler_head, uevent_handler) uevent_handler_list; 32 | pthread_mutex_t uevent_handler_list_lock = PTHREAD_MUTEX_INITIALIZER; 33 | 34 | struct uevent_handler { 35 | void (*handler)(void *data, const char *msg, int msg_len); 36 | void *handler_data; 37 | LIST_ENTRY(uevent_handler) list; 38 | }; 39 | 40 | static int fd = -1; 41 | 42 | /* Returns 0 on failure, 1 on success */ 43 | int uevent_init() 44 | { 45 | struct sockaddr_nl addr; 46 | int sz = 64*1024; 47 | int s; 48 | 49 | memset(&addr, 0, sizeof(addr)); 50 | addr.nl_family = AF_NETLINK; 51 | addr.nl_pid = 0; 52 | addr.nl_groups = 0xffffffff; 53 | 54 | s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); 55 | if(s < 0) 56 | return 0; 57 | 58 | setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz)); 59 | 60 | if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { 61 | close(s); 62 | return 0; 63 | } 64 | 65 | fd = s; 66 | return (fd > 0); 67 | } 68 | 69 | int uevent_get_fd() 70 | { 71 | return fd; 72 | } 73 | 74 | int uevent_next_event(char* buffer, int buffer_length) 75 | { 76 | while (1) { 77 | struct pollfd fds; 78 | int nr; 79 | 80 | fds.fd = fd; 81 | fds.events = POLLIN; 82 | fds.revents = 0; 83 | nr = poll(&fds, 1, -1); 84 | 85 | if(nr > 0 && (fds.revents & POLLIN)) { 86 | int count = recv(fd, buffer, buffer_length, 0); 87 | if (count > 0) { 88 | struct uevent_handler *h; 89 | pthread_mutex_lock(&uevent_handler_list_lock); 90 | LIST_FOREACH(h, &uevent_handler_list, list) 91 | h->handler(h->handler_data, buffer, buffer_length); 92 | pthread_mutex_unlock(&uevent_handler_list_lock); 93 | 94 | return count; 95 | } 96 | } 97 | } 98 | 99 | // won't get here 100 | return 0; 101 | } 102 | 103 | int uevent_add_native_handler(void (*handler)(void *data, const char *msg, int msg_len), 104 | void *handler_data) 105 | { 106 | struct uevent_handler *h; 107 | 108 | h = malloc(sizeof(struct uevent_handler)); 109 | if (h == NULL) 110 | return -1; 111 | h->handler = handler; 112 | h->handler_data = handler_data; 113 | 114 | pthread_mutex_lock(&uevent_handler_list_lock); 115 | LIST_INSERT_HEAD(&uevent_handler_list, h, list); 116 | pthread_mutex_unlock(&uevent_handler_list_lock); 117 | 118 | return 0; 119 | } 120 | 121 | int uevent_remove_native_handler(void (*handler)(void *data, const char *msg, int msg_len)) 122 | { 123 | struct uevent_handler *h; 124 | int err = -1; 125 | 126 | pthread_mutex_lock(&uevent_handler_list_lock); 127 | LIST_FOREACH(h, &uevent_handler_list, list) { 128 | if (h->handler == handler) { 129 | LIST_REMOVE(h, list); 130 | err = 0; 131 | break; 132 | } 133 | } 134 | pthread_mutex_unlock(&uevent_handler_list_lock); 135 | 136 | return err; 137 | } 138 | -------------------------------------------------------------------------------- /wifi/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2006 The Android Open Source Project 2 | 3 | ifdef WIFI_DRIVER_MODULE_PATH 4 | LOCAL_CFLAGS += -DWIFI_DRIVER_MODULE_PATH=\"$(WIFI_DRIVER_MODULE_PATH)\" 5 | endif 6 | ifdef WIFI_DRIVER_MODULE_ARG 7 | LOCAL_CFLAGS += -DWIFI_DRIVER_MODULE_ARG=\"$(WIFI_DRIVER_MODULE_ARG)\" 8 | endif 9 | ifdef WIFI_DRIVER_MODULE_AP_ARG 10 | LOCAL_CFLAGS += -DWIFI_DRIVER_MODULE_AP_ARG=\"$(WIFI_DRIVER_MODULE_AP_ARG)\" 11 | endif 12 | ifdef WIFI_DRIVER_MODULE_NAME 13 | LOCAL_CFLAGS += -DWIFI_DRIVER_MODULE_NAME=\"$(WIFI_DRIVER_MODULE_NAME)\" 14 | endif 15 | ifdef WIFI_FIRMWARE_LOADER 16 | LOCAL_CFLAGS += -DWIFI_FIRMWARE_LOADER=\"$(WIFI_FIRMWARE_LOADER)\" 17 | endif 18 | ifdef WIFI_DRIVER_FW_PATH_STA 19 | LOCAL_CFLAGS += -DWIFI_DRIVER_FW_PATH_STA=\"$(WIFI_DRIVER_FW_PATH_STA)\" 20 | endif 21 | ifdef WIFI_DRIVER_FW_PATH_AP 22 | LOCAL_CFLAGS += -DWIFI_DRIVER_FW_PATH_AP=\"$(WIFI_DRIVER_FW_PATH_AP)\" 23 | endif 24 | ifdef WIFI_DRIVER_FW_PATH_P2P 25 | LOCAL_CFLAGS += -DWIFI_DRIVER_FW_PATH_P2P=\"$(WIFI_DRIVER_FW_PATH_P2P)\" 26 | endif 27 | ifdef WIFI_DRIVER_FW_PATH_PARAM 28 | LOCAL_CFLAGS += -DWIFI_DRIVER_FW_PATH_PARAM=\"$(WIFI_DRIVER_FW_PATH_PARAM)\" 29 | endif 30 | ifdef WIFI_EXT_MODULE_PATH 31 | LOCAL_CFLAGS += -DWIFI_EXT_MODULE_PATH=\"$(WIFI_EXT_MODULE_PATH)\" 32 | endif 33 | ifdef WIFI_EXT_MODULE_ARG 34 | LOCAL_CFLAGS += -DWIFI_EXT_MODULE_ARG=\"$(WIFI_EXT_MODULE_ARG)\" 35 | endif 36 | ifdef WIFI_EXT_MODULE_NAME 37 | LOCAL_CFLAGS += -DWIFI_EXT_MODULE_NAME=\"$(WIFI_EXT_MODULE_NAME)\" 38 | endif 39 | 40 | ifdef WIFI_DRIVER_STATE_CTRL_PARAM 41 | LOCAL_CFLAGS += -DWIFI_DRIVER_STATE_CTRL_PARAM=\"$(WIFI_DRIVER_STATE_CTRL_PARAM)\" 42 | endif 43 | ifdef WIFI_DRIVER_STATE_ON 44 | LOCAL_CFLAGS += -DWIFI_DRIVER_STATE_ON=\"$(WIFI_DRIVER_STATE_ON)\" 45 | endif 46 | ifdef WIFI_DRIVER_STATE_OFF 47 | LOCAL_CFLAGS += -DWIFI_DRIVER_STATE_OFF=\"$(WIFI_DRIVER_STATE_OFF)\" 48 | endif 49 | 50 | ifdef WIFI_FST_DRIVER_MODULE_PATH 51 | LOCAL_CFLAGS += -DWIFI_FST_DRIVER_MODULE_PATH=\"$(WIFI_FST_DRIVER_MODULE_PATH)\" 52 | endif 53 | ifdef WIFI_FST_DRIVER_MODULE_ARG 54 | LOCAL_CFLAGS += -DWIFI_FST_DRIVER_MODULE_ARG=\"$(WIFI_FST_DRIVER_MODULE_ARG)\" 55 | endif 56 | ifdef WIFI_FST_DRIVER_MODULE_NAME 57 | LOCAL_CFLAGS += -DWIFI_FST_DRIVER_MODULE_NAME=\"$(WIFI_FST_DRIVER_MODULE_NAME)\" 58 | endif 59 | 60 | LOCAL_SRC_FILES += wifi/wifi.c wifi/wifi_fst.c 61 | 62 | ifdef WPA_SUPPLICANT_VERSION 63 | LOCAL_CFLAGS += -DLIBWPA_CLIENT_EXISTS 64 | LOCAL_SHARED_LIBRARIES += libwpa_client 65 | endif 66 | 67 | ifeq ($(BOARD_HAVE_SAMSUNG_WIFI),true) 68 | LOCAL_CFLAGS += -DSAMSUNG_WIFI 69 | endif 70 | 71 | LOCAL_SHARED_LIBRARIES += libnetutils 72 | -------------------------------------------------------------------------------- /wifi/wifi_fst.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, The Linux Foundation. All rights reserved. 3 | * 4 | * Not a Contribution. 5 | * Copyright 2008, The Android Open Source Project 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #define LOG_TAG "WifiFST" 25 | #include "cutils/log.h" 26 | #include "cutils/properties.h" 27 | 28 | #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ 29 | #include 30 | 31 | #include "hardware_legacy/wifi.h" 32 | 33 | #ifndef WIFI_FST_DRIVER_MODULE_PATH 34 | #define WIFI_FST_DRIVER_MODULE_PATH "" 35 | #endif 36 | #ifndef WIFI_FST_DRIVER_MODULE_ARG 37 | #define WIFI_FST_DRIVER_MODULE_ARG "" 38 | #endif 39 | #ifndef WIFI_FST_DRIVER_MODULE_NAME 40 | #define WIFI_FST_DRIVER_MODULE_NAME "" 41 | #endif 42 | 43 | static const char WIFI_FST_DRIVER_MODULE_TAG[] = WIFI_FST_DRIVER_MODULE_NAME " "; 44 | static const char FST_DRIVER_PROP_NAME[] = "wlan.fst.driver.status"; 45 | 46 | static const char FSTMAN_IFNAME[] = "wlan0"; 47 | static const char FSTMAN_NAME[] = "fstman"; 48 | static const char FSTMAN_START_PROP_NAME[] = "netd.fstman.start"; 49 | static const char FSTMAN_CONFIG_TEMPLATE[] = "/system/etc/wifi/fstman.ini"; 50 | static const char FSTMAN_CONFIG_FILE[] = "/data/misc/wifi/fstman.ini"; 51 | static const char FST_RATE_UPGRADE_ENABLED_PROP_NAME[] = "persist.fst.rate.upgrade.en"; 52 | static const char FST_SOFTAP_ENABLED_PROP_NAME[] = "persist.fst.softap.en"; 53 | 54 | static const char MODULE_FILE[] = "/proc/modules"; 55 | 56 | #if __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | extern int insmod(const char *filename, const char *args); 61 | extern int rmmod(const char *modname); 62 | extern int ensure_config_file_exists(const char *config_file, const char *config_file_template); 63 | 64 | #if __cplusplus 65 | }; // extern "C" 66 | #endif 67 | 68 | int is_fst_enabled() 69 | { 70 | char prop_value[PROPERTY_VALUE_MAX] = { '\0' }; 71 | 72 | if (property_get(FST_RATE_UPGRADE_ENABLED_PROP_NAME, prop_value, NULL) && 73 | strcmp(prop_value, "1") == 0) { 74 | return 1; 75 | } 76 | 77 | return 0; 78 | } 79 | 80 | int is_fst_softap_enabled() { 81 | char prop_value[PROPERTY_VALUE_MAX] = { '\0' }; 82 | 83 | if (is_fst_enabled() && 84 | property_get(FST_SOFTAP_ENABLED_PROP_NAME, prop_value, NULL) && 85 | strcmp(prop_value, "1") == 0) { 86 | return 1; 87 | } 88 | 89 | return 0; 90 | } 91 | 92 | int is_fst_driver_loaded() 93 | { 94 | char driver_status[PROPERTY_VALUE_MAX]; 95 | FILE *proc; 96 | char line[sizeof(WIFI_FST_DRIVER_MODULE_TAG)+10]; 97 | 98 | if (!is_fst_enabled()) 99 | return 1; 100 | 101 | if (!property_get(FST_DRIVER_PROP_NAME, driver_status, NULL) || 102 | strcmp(driver_status, "ok") != 0) 103 | return 0; /* driver not loaded */ 104 | 105 | /* 106 | * If the property says the driver is loaded, check to 107 | * make sure that the property setting isn't just left 108 | * over from a previous manual shutdown or a runtime 109 | * crash. 110 | */ 111 | if ((proc = fopen(MODULE_FILE, "r")) == NULL) { 112 | ALOGW("Could not open %s: %s", MODULE_FILE, strerror(errno)); 113 | property_set(FST_DRIVER_PROP_NAME, "unloaded"); 114 | return 0; 115 | } 116 | while ((fgets(line, sizeof(line), proc)) != NULL) 117 | if (strncmp(line, WIFI_FST_DRIVER_MODULE_TAG, 118 | strlen(WIFI_FST_DRIVER_MODULE_TAG)) == 0) { 119 | fclose(proc); 120 | return 1; 121 | } 122 | 123 | fclose(proc); 124 | property_set(FST_DRIVER_PROP_NAME, "unloaded"); 125 | return 0; 126 | } 127 | 128 | int wifi_fst_load_driver() 129 | { 130 | if (!is_fst_enabled()) 131 | return 0; 132 | 133 | if (is_fst_driver_loaded()) 134 | return 0; 135 | 136 | if (insmod(WIFI_FST_DRIVER_MODULE_PATH, WIFI_FST_DRIVER_MODULE_ARG) < 0) 137 | return -1; 138 | 139 | property_set(FST_DRIVER_PROP_NAME, "ok"); 140 | 141 | return 0; 142 | } 143 | 144 | int wifi_fst_unload_driver() 145 | { 146 | int count = 20; /* wait at most 10 seconds for completion */ 147 | 148 | if (!is_fst_enabled()) 149 | return 0; 150 | 151 | if (rmmod(WIFI_FST_DRIVER_MODULE_NAME) != 0) 152 | return -1; 153 | 154 | while (count-- > 0) { 155 | if (!is_fst_driver_loaded()) 156 | break; 157 | usleep(500000); 158 | } 159 | usleep(500000); /* allow card removal */ 160 | if (count) 161 | return 0; 162 | 163 | return -1; 164 | } 165 | 166 | static void get_fstman_props(int softap_mode, 167 | char *fstman_svc_name, int fstman_svc_name_len, 168 | char *fstman_init_prop, int fstman_init_prop_len) 169 | { 170 | if (softap_mode) 171 | strlcpy(fstman_svc_name, FSTMAN_NAME, fstman_svc_name_len); 172 | else 173 | snprintf(fstman_svc_name, fstman_svc_name_len, "%s_%s", 174 | FSTMAN_NAME, FSTMAN_IFNAME); 175 | snprintf(fstman_init_prop, fstman_init_prop_len, "init.svc.%s", 176 | fstman_svc_name); 177 | } 178 | 179 | int wifi_start_fstman(int softap_mode) 180 | { 181 | char fstman_status[PROPERTY_VALUE_MAX] = { '\0' }; 182 | char fstman_svc_name[PROPERTY_VALUE_MAX] = { '\0' }; 183 | char fstman_init_prop[PROPERTY_VALUE_MAX] = { '\0' }; 184 | int count = 50; /* wait at most 5 seconds for completion */ 185 | 186 | if (!is_fst_enabled() || 187 | (softap_mode && !is_fst_softap_enabled())) { 188 | return 0; 189 | } 190 | 191 | if (ensure_config_file_exists(FSTMAN_CONFIG_FILE, FSTMAN_CONFIG_TEMPLATE) < 0) { 192 | ALOGE("Failed to create fstman config file"); 193 | return -1; 194 | } 195 | 196 | get_fstman_props(softap_mode, fstman_svc_name, sizeof(fstman_svc_name), 197 | fstman_init_prop, sizeof(fstman_init_prop)); 198 | 199 | /* Check whether already running */ 200 | if (property_get(fstman_init_prop, fstman_status, NULL) && 201 | strcmp(fstman_status, "running") == 0) 202 | return 0; 203 | 204 | ALOGD("Starting FST Manager"); 205 | /* when invoked from netd, use different property because of different 206 | selinux permissions */ 207 | if (softap_mode) { 208 | property_set(FSTMAN_START_PROP_NAME, "true"); 209 | } else { 210 | property_set("ctl.start", fstman_svc_name); 211 | } 212 | sched_yield(); 213 | 214 | while (count-- > 0) { 215 | if (property_get(fstman_init_prop, fstman_status, NULL) && 216 | strcmp(fstman_status, "running") == 0) 217 | return 0; 218 | usleep(100000); 219 | } 220 | 221 | ALOGE("Failed to start FST Manager"); 222 | return -1; 223 | } 224 | 225 | int wifi_stop_fstman(int softap_mode) 226 | { 227 | char fstman_status[PROPERTY_VALUE_MAX] = { '\0' }; 228 | char fstman_svc_name[PROPERTY_VALUE_MAX] = { '\0' }; 229 | char fstman_init_prop[PROPERTY_VALUE_MAX] = { '\0' }; 230 | int count = 50; /* wait at most 5 seconds for completion */ 231 | 232 | if (!is_fst_enabled() || 233 | (softap_mode && !is_fst_softap_enabled())) { 234 | return 0; 235 | } 236 | 237 | get_fstman_props(softap_mode, fstman_svc_name, sizeof(fstman_svc_name), 238 | fstman_init_prop, sizeof(fstman_init_prop)); 239 | 240 | /* Check whether already stopped */ 241 | if (property_get(fstman_init_prop, fstman_status, NULL) && 242 | strcmp(fstman_status, "stopped") == 0) 243 | return 0; 244 | 245 | ALOGD("Stopping FST Manager"); 246 | /* when invoked from netd, use different property because of different 247 | selinux permissions */ 248 | if (softap_mode) 249 | property_set(FSTMAN_START_PROP_NAME, "false"); 250 | else 251 | property_set("ctl.stop", fstman_svc_name); 252 | sched_yield(); 253 | 254 | while (count-- > 0) { 255 | if (property_get(fstman_init_prop, fstman_status, NULL) && 256 | strcmp(fstman_status, "stopped") == 0) 257 | return 0; 258 | usleep(100000); 259 | } 260 | 261 | ALOGE("Failed to stop fstman"); 262 | return -1; 263 | } 264 | -------------------------------------------------------------------------------- /wifi/wifi_fst.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, The Linux Foundation. All rights reserved. 3 | * 4 | * Not a Contribution. 5 | * Copyright (C) 2008 The Android Open Source Project 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | #ifndef _WIFI_FST_H 21 | #define _WIFI_FST_H 22 | 23 | #if __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /** 28 | * returns whether FST is enabled or not according to 29 | * persist.fst.rate.upgrade.en system property 30 | * 31 | * @return 1 if FST enabled. 32 | */ 33 | int is_fst_enabled(); 34 | 35 | /** 36 | * returns whether FST Soft AP is enabled or not according to 37 | * persist.fst.softap.en system property 38 | * 39 | * @return 1 if FST Soft AP enabled. 40 | */ 41 | int is_fst_softap_enabled(); 42 | 43 | /** 44 | * Load the Wi-Fi driver for FST rate upgrade. 45 | * 46 | * @return 0 on success, < 0 on failure. 47 | */ 48 | int wifi_fst_load_driver(); 49 | 50 | /** 51 | * Unload the Wi-Fi driver for FST rate upgrade. 52 | * 53 | * @return 0 on success, < 0 on failure. 54 | */ 55 | int wifi_fst_unload_driver(); 56 | 57 | /** 58 | * Check if the Wi-Fi driver for FST rate upgrade is loaded. 59 | 60 | * @return 0 on success, < 0 on failure. 61 | */ 62 | int is_fst_driver_loaded(); 63 | 64 | /** 65 | * Start FST Manager. 66 | * 67 | * @return 0 on success, < 0 on failure. 68 | */ 69 | int wifi_start_fstman(int softap_mode); 70 | 71 | /** 72 | * Stop FST Manager. 73 | * 74 | * @return 0 on success, < 0 on failure. 75 | */ 76 | int wifi_stop_fstman(int softap_mode); 77 | 78 | #if __cplusplus 79 | }; // extern "C" 80 | #endif 81 | 82 | #endif // _WIFI_FST_H 83 | --------------------------------------------------------------------------------