├── MODULE_LICENSE_APACHE2 ├── qemu ├── Android.mk └── qemu.c ├── vibrator ├── Android.mk └── vibrator.c ├── qemu_tracing ├── Android.mk └── qemu_tracing.c ├── uevent ├── Android.mk ├── uevent_stub.c └── uevent.c ├── power ├── Android.mk ├── power_qemu.h ├── power_qemu.c └── power.c ├── wifi ├── Android.mk └── wifi.c ├── include └── hardware_legacy │ ├── uevent.h │ ├── qemu_tracing.h │ ├── vibrator.h │ ├── power.h │ ├── AudioHardwareBase.h │ ├── IMountService.h │ ├── wifi.h │ ├── AudioHardwareInterface.h │ ├── AudioPolicyInterface.h │ └── AudioPolicyManagerBase.h ├── Android.mk ├── CleanSpec.mk ├── qemu.h └── NOTICE /MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /qemu/Android.mk: -------------------------------------------------------------------------------- 1 | ifeq ($(QEMU_HARDWARE),true) 2 | LOCAL_SRC_FILES += qemu/qemu.c 3 | endif 4 | -------------------------------------------------------------------------------- /vibrator/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2006 The Android Open Source Project 2 | 3 | LOCAL_SRC_FILES += vibrator/vibrator.c 4 | 5 | -------------------------------------------------------------------------------- /qemu_tracing/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2007 The Android Open Source Project 2 | 3 | LOCAL_SRC_FILES += qemu_tracing/qemu_tracing.c 4 | 5 | -------------------------------------------------------------------------------- /uevent/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2008 The Android Open Source Project 2 | 3 | ifeq ($(TARGET_SIMULATOR),true) 4 | LOCAL_SRC_FILES += uevent/uevent_stub.c 5 | else 6 | LOCAL_SRC_FILES += uevent/uevent.c 7 | endif 8 | -------------------------------------------------------------------------------- /power/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2006 The Android Open Source Project 2 | 3 | LOCAL_SRC_FILES += power/power.c 4 | 5 | ifeq ($(QEMU_HARDWARE),true) 6 | LOCAL_SRC_FILES += power/power_qemu.c 7 | LOCAL_CFLAGS += -DQEMU_POWER=1 8 | endif 9 | -------------------------------------------------------------------------------- /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_NAME 10 | LOCAL_CFLAGS += -DWIFI_DRIVER_MODULE_NAME=\"$(WIFI_DRIVER_MODULE_NAME)\" 11 | endif 12 | ifdef WIFI_FIRMWARE_LOADER 13 | LOCAL_CFLAGS += -DWIFI_FIRMWARE_LOADER=\"$(WIFI_FIRMWARE_LOADER)\" 14 | endif 15 | 16 | LOCAL_SRC_FILES += wifi/wifi.c 17 | 18 | LOCAL_SHARED_LIBRARIES += libnetutils 19 | -------------------------------------------------------------------------------- /power/power_qemu.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 | #ifndef _power_qemu_h 17 | #define _power_qemu_h 18 | 19 | #include 20 | 21 | extern int 22 | qemu_set_screen_state(int on); 23 | 24 | #endif /* _power_qemu_h */ 25 | -------------------------------------------------------------------------------- /power/power_qemu.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 "qemu.h" 17 | #include "power_qemu.h" 18 | #include 19 | #include 20 | #include 21 | 22 | int 23 | qemu_set_screen_state(int on) 24 | { 25 | qemu_control_command( "power:screen_state:%s", on ? "wake" : "standby" ); 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /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_next_event(char* buffer, int buffer_length); 26 | 27 | #if __cplusplus 28 | } // extern "C" 29 | #endif 30 | 31 | #endif // _HARDWARE_UEVENT_H 32 | -------------------------------------------------------------------------------- /uevent/uevent_stub.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 | #include 19 | 20 | int uevent_init() 21 | { 22 | return 1; 23 | } 24 | 25 | int uevent_next_event(char* buffer, int buffer_length) 26 | { 27 | while (1) { 28 | sleep(10000); 29 | } 30 | 31 | // won't get here 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /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 | SAVE_MAKEFILES := $(call all-subdir-makefiles) 5 | 6 | LOCAL_PATH:= $(call my-dir) 7 | include $(CLEAR_VARS) 8 | 9 | LOCAL_SHARED_LIBRARIES := libutils libbinder libcutils libwpa_client 10 | 11 | LOCAL_INCLUDES += $(LOCAL_PATH) 12 | 13 | ifneq ($(TARGET_SIMULATOR),true) 14 | LOCAL_CFLAGS += -DQEMU_HARDWARE 15 | QEMU_HARDWARE := true 16 | endif 17 | 18 | ifneq ($(TARGET_SIMULATOR),true) 19 | LOCAL_SHARED_LIBRARIES += libdl 20 | endif 21 | 22 | include $(SAVE_MAKEFILES) 23 | 24 | # need "-lrt" on Linux simulator to pick up clock_gettime 25 | ifeq ($(TARGET_SIMULATOR),true) 26 | ifeq ($(HOST_OS),linux) 27 | LOCAL_LDLIBS += -lrt -lpthread -ldl 28 | endif 29 | endif 30 | 31 | LOCAL_MODULE:= libhardware_legacy 32 | 33 | include $(BUILD_SHARED_LIBRARY) 34 | 35 | # static library for librpc 36 | include $(CLEAR_VARS) 37 | 38 | LOCAL_MODULE:= libpower 39 | 40 | LOCAL_SRC_FILES += power/power.c 41 | 42 | include $(BUILD_STATIC_LIBRARY) 43 | -------------------------------------------------------------------------------- /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/vibrator.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_VIBRATOR_H 18 | #define _HARDWARE_VIBRATOR_H 19 | 20 | #if __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /** 25 | * Turn on vibrator 26 | * 27 | * @param timeout_ms number of milliseconds to vibrate 28 | * 29 | * @return 0 if successful, -1 if error 30 | */ 31 | int vibrator_on(int timeout_ms); 32 | 33 | /** 34 | * Turn off vibrator 35 | * 36 | * @return 0 if successful, -1 if error 37 | */ 38 | int vibrator_off(); 39 | 40 | #if __cplusplus 41 | } // extern "C" 42 | #endif 43 | 44 | #endif // _HARDWARE_VIBRATOR_H 45 | -------------------------------------------------------------------------------- /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 | // true if you want the screen on, false if you want it off 37 | int set_screen_state(int on); 38 | 39 | // set how long to stay awake after the last user activity in seconds 40 | int set_last_user_activity_timeout(int64_t delay); 41 | 42 | 43 | #if __cplusplus 44 | } // extern "C" 45 | #endif 46 | 47 | #endif // _HARDWARE_POWER_H 48 | -------------------------------------------------------------------------------- /vibrator/vibrator.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 "qemu.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #define THE_DEVICE "/sys/class/timed_output/vibrator/enable" 25 | 26 | static int sendit(int timeout_ms) 27 | { 28 | int nwr, ret, fd; 29 | char value[20]; 30 | 31 | #ifdef QEMU_HARDWARE 32 | if (qemu_check()) { 33 | return qemu_control_command( "vibrator:%d", timeout_ms ); 34 | } 35 | #endif 36 | 37 | fd = open(THE_DEVICE, O_RDWR); 38 | if(fd < 0) 39 | return errno; 40 | 41 | nwr = sprintf(value, "%d\n", timeout_ms); 42 | ret = write(fd, value, nwr); 43 | 44 | close(fd); 45 | 46 | return (ret == nwr) ? 0 : -1; 47 | } 48 | 49 | int vibrator_on(int timeout_ms) 50 | { 51 | /* constant on, up to maximum allowed time */ 52 | return sendit(timeout_ms); 53 | } 54 | 55 | int vibrator_off() 56 | { 57 | return sendit(0); 58 | } 59 | -------------------------------------------------------------------------------- /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 "hardware_legacy/AudioHardwareInterface.h" 21 | 22 | 23 | namespace android { 24 | 25 | // ---------------------------------------------------------------------------- 26 | 27 | /** 28 | * AudioHardwareBase is a convenient base class used for implementing the 29 | * AudioHardwareInterface interface. 30 | */ 31 | class AudioHardwareBase : public AudioHardwareInterface 32 | { 33 | public: 34 | AudioHardwareBase(); 35 | virtual ~AudioHardwareBase() { } 36 | 37 | /** 38 | * setMode is called when the audio mode changes. NORMAL mode is for 39 | * standard audio playback, RINGTONE when a ringtone is playing, and IN_CALL 40 | * when a call is in progress. 41 | */ 42 | virtual status_t setMode(int mode); 43 | 44 | virtual status_t setParameters(const String8& keyValuePairs); 45 | virtual String8 getParameters(const String8& keys); 46 | 47 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); 48 | 49 | /**This method dumps the state of the audio hardware */ 50 | virtual status_t dumpState(int fd, const Vector& args); 51 | 52 | protected: 53 | int mMode; 54 | }; 55 | 56 | }; // namespace android 57 | 58 | #endif // ANDROID_AUDIO_HARDWARE_BASE_H 59 | -------------------------------------------------------------------------------- /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 | 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | static int fd = -1; 29 | 30 | /* Returns 0 on failure, 1 on success */ 31 | int uevent_init() 32 | { 33 | struct sockaddr_nl addr; 34 | int sz = 64*1024; 35 | int s; 36 | 37 | memset(&addr, 0, sizeof(addr)); 38 | addr.nl_family = AF_NETLINK; 39 | addr.nl_pid = getpid(); 40 | addr.nl_groups = 0xffffffff; 41 | 42 | s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); 43 | if(s < 0) 44 | return 0; 45 | 46 | setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz)); 47 | 48 | if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { 49 | close(s); 50 | return 0; 51 | } 52 | 53 | fd = s; 54 | return (fd > 0); 55 | } 56 | 57 | int uevent_next_event(char* buffer, int buffer_length) 58 | { 59 | while (1) { 60 | struct pollfd fds; 61 | int nr; 62 | 63 | fds.fd = fd; 64 | fds.events = POLLIN; 65 | fds.revents = 0; 66 | nr = poll(&fds, 1, -1); 67 | 68 | if(nr > 0 && fds.revents == POLLIN) { 69 | int count = recv(fd, buffer, buffer_length, 0); 70 | if (count > 0) { 71 | return count; 72 | } 73 | } 74 | } 75 | 76 | // won't get here 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /qemu.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 | #ifndef _libs_hardware_qemu_h 17 | #define _libs_hardware_qemu_h 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #ifdef QEMU_HARDWARE 24 | 25 | /* returns 1 iff we're running in the emulator */ 26 | extern int qemu_check(void); 27 | 28 | /* a structure used to hold enough state to connect to a given 29 | * QEMU communication channel, either through a qemud socket or 30 | * a serial port. 31 | * 32 | * initialize the structure by zero-ing it out 33 | */ 34 | typedef struct { 35 | char is_inited; 36 | char is_available; 37 | char is_qemud; 38 | char is_qemud_old; 39 | char is_tty; 40 | int fd; 41 | char device[32]; 42 | } QemuChannel; 43 | 44 | /* try to open a qemu communication channel. 45 | * returns a file descriptor on success, or -1 in case of 46 | * error. 47 | * 48 | * 'channel' must be a QemuChannel structure that is empty 49 | * on the first call. You can call this function several 50 | * time to re-open the channel using the same 'channel' 51 | * object to speed things a bit. 52 | */ 53 | extern int qemu_channel_open( QemuChannel* channel, 54 | const char* name, 55 | int mode ); 56 | 57 | /* create a command made of a 4-hexchar prefix followed 58 | * by the content. the prefix contains the content's length 59 | * in hexadecimal coding. 60 | * 61 | * 'buffer' must be at last 6 bytes 62 | * returns -1 in case of overflow, or the command's total length 63 | * otherwise (i.e. content length + 4) 64 | */ 65 | extern int qemu_command_format( char* buffer, 66 | int buffer_size, 67 | const char* format, 68 | ... ); 69 | 70 | /* directly sends a command through the 'hw-control' channel. 71 | * this will open the channel, send the formatted command, then 72 | * close the channel automatically. 73 | * returns 0 on success, or -1 on error. 74 | */ 75 | extern int qemu_control_command( const char* fmt, ... ); 76 | 77 | /* sends a question to the hw-control channel, then receive an answer in 78 | * a user-allocated buffer. returns the length of the answer, or -1 79 | * in case of error. 80 | * 81 | * 'question' *must* have been formatted through qemu_command_format 82 | */ 83 | extern int qemu_control_query( const char* question, int questionlen, 84 | char* answer, int answersize ); 85 | 86 | #endif /* QEMU_HARDWARE */ 87 | 88 | /* use QEMU_FALLBACK(call) to call a QEMU-specific callback */ 89 | /* use QEMU_FALLBACK_VOID(call) if the function returns void */ 90 | #ifdef QEMU_HARDWARE 91 | # define QEMU_FALLBACK(x) \ 92 | do { \ 93 | if (qemu_check()) \ 94 | return qemu_ ## x ; \ 95 | } while (0) 96 | # define QEMU_FALLBACK_VOID(x) \ 97 | do { \ 98 | if (qemu_check()) { \ 99 | qemu_ ## x ; \ 100 | return; \ 101 | } \ 102 | } while (0) 103 | #else 104 | # define QEMU_FALLBACK(x) ((void)0) 105 | # define QEMU_FALLBACK_VOID(x) ((void)0) 106 | #endif 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* _libs_hardware_qemu_h */ 113 | -------------------------------------------------------------------------------- /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 | #include 28 | #include 29 | 30 | #define LOG_TAG "power" 31 | #include 32 | 33 | #include "qemu.h" 34 | #ifdef QEMU_POWER 35 | #include "power_qemu.h" 36 | #endif 37 | 38 | enum { 39 | ACQUIRE_PARTIAL_WAKE_LOCK = 0, 40 | RELEASE_WAKE_LOCK, 41 | REQUEST_STATE, 42 | OUR_FD_COUNT 43 | }; 44 | 45 | const char * const OLD_PATHS[] = { 46 | "/sys/android_power/acquire_partial_wake_lock", 47 | "/sys/android_power/release_wake_lock", 48 | "/sys/android_power/request_state" 49 | }; 50 | 51 | const char * const NEW_PATHS[] = { 52 | "/sys/power/wake_lock", 53 | "/sys/power/wake_unlock", 54 | "/sys/power/state" 55 | }; 56 | 57 | const char * const AUTO_OFF_TIMEOUT_DEV = "/sys/android_power/auto_off_timeout"; 58 | 59 | //XXX static pthread_once_t g_initialized = THREAD_ONCE_INIT; 60 | static int g_initialized = 0; 61 | static int g_fds[OUR_FD_COUNT]; 62 | static int g_error = 1; 63 | 64 | static const char *off_state = "mem"; 65 | static const char *on_state = "on"; 66 | 67 | static int64_t systemTime() 68 | { 69 | struct timespec t; 70 | t.tv_sec = t.tv_nsec = 0; 71 | clock_gettime(CLOCK_MONOTONIC, &t); 72 | return t.tv_sec*1000000000LL + t.tv_nsec; 73 | } 74 | 75 | static int 76 | open_file_descriptors(const char * const paths[]) 77 | { 78 | int i; 79 | for (i=0; i= 0; 141 | } 142 | 143 | int 144 | set_last_user_activity_timeout(int64_t delay) 145 | { 146 | // LOGI("set_last_user_activity_timeout delay=%d\n", ((int)(delay))); 147 | 148 | int fd = open(AUTO_OFF_TIMEOUT_DEV, O_RDWR); 149 | if (fd >= 0) { 150 | char buf[32]; 151 | ssize_t len; 152 | len = snprintf(buf, sizeof(buf), "%d", ((int)(delay))); 153 | buf[sizeof(buf) - 1] = '\0'; 154 | len = write(fd, buf, len); 155 | close(fd); 156 | return 0; 157 | } else { 158 | return errno; 159 | } 160 | } 161 | 162 | int 163 | set_screen_state(int on) 164 | { 165 | QEMU_FALLBACK(set_screen_state(on)); 166 | 167 | LOGI("*** set_screen_state %d", on); 168 | 169 | initialize_fds(); 170 | 171 | //LOGI("go_to_sleep eventTime=%lld now=%lld g_error=%s\n", eventTime, 172 | // systemTime(), strerror(g_error)); 173 | 174 | if (g_error) return g_error; 175 | 176 | char buf[32]; 177 | int len; 178 | if(on) 179 | len = snprintf(buf, sizeof(buf), "%s", on_state); 180 | else 181 | len = snprintf(buf, sizeof(buf), "%s", off_state); 182 | 183 | buf[sizeof(buf) - 1] = '\0'; 184 | len = write(g_fds[REQUEST_STATE], buf, len); 185 | if(len < 0) { 186 | LOGE("Failed setting last user activity: g_error=%d\n", g_error); 187 | } 188 | return 0; 189 | } 190 | -------------------------------------------------------------------------------- /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 | * Start supplicant. 40 | * 41 | * @return 0 on success, < 0 on failure. 42 | */ 43 | int wifi_start_supplicant(); 44 | 45 | /** 46 | * Stop supplicant. 47 | * 48 | * @return 0 on success, < 0 on failure. 49 | */ 50 | int wifi_stop_supplicant(); 51 | 52 | /** 53 | * Open a connection to supplicant. 54 | * 55 | * @return 0 on success, < 0 on failure. 56 | */ 57 | int wifi_connect_to_supplicant(); 58 | 59 | /** 60 | * Close connection supplicant. 61 | * 62 | * @return 0 on success, < 0 on failure. 63 | */ 64 | void wifi_close_supplicant_connection(); 65 | 66 | /** 67 | * wifi_wait_for_event() performs a blocking call to 68 | * get a Wi-Fi event and returns a string representing 69 | * a Wi-Fi event when it occurs. 70 | * 71 | * @param buf is the buffer that receives the event 72 | * @param len is the maximum length of the buffer 73 | * 74 | * @returns number of bytes in buffer, 0 if no 75 | * event (for instance, no connection), and less than 0 76 | * if there is an error. 77 | */ 78 | int wifi_wait_for_event(char *buf, size_t len); 79 | 80 | /** 81 | * wifi_command() issues a command to the Wi-Fi driver. 82 | * 83 | * Android extends the standard commands listed at 84 | * /link http://hostap.epitest.fi/wpa_supplicant/devel/ctrl_iface_page.html 85 | * to include support for sending commands to the driver: 86 | * 87 | * 88 | * 89 | * 90 | * 91 | * 92 | * 93 | * 94 | * 95 | * 96 | * 97 | * 98 | * 99 | * 100 | * 101 | * 102 | * 103 | * 104 | * 105 | * 106 | * 107 | * 108 | * 109 | * 110 | * 111 | * 112 | * 113 | * 114 | * 115 | * 116 | * 117 | * 118 | * 119 | * 120 | * 121 | * 122 | * 123 | * 124 | * 125 | * 126 | * 127 | * 128 | *
Command / Command summaryForm of ResponseProcessing
DRIVER START
  Turn on Wi-Fi Hardware
OK if successfulOK ? true : false
DRIVER STOP
  Turn off Wi-Fi hardware
OK if successfulOK ? true : false
DRIVER RSSI
  Return received signal strength indicator in -db for current AP
<ssid> Rssi xx%*s %*s %d", &rssi
DRIVER LINKSPEED
  Return link speed in MBPS
LinkSpeed xx%*s %d", &linkspd
DRIVER MACADDR
  Return mac address of the station
Macaddr = xx.xx.xx.xx.xx.xx"%*s = %s", &macadr
DRIVER SCAN-ACTIVE
  Set scan type to active
"OK" if successful"OK" ? true : false
DRIVER SCAN-PASSIVE
  Set scan type to passive
"OK" if successful"OK" ? true : false
129 | * 130 | * See libs/android_runtime/android_net_wifi_Wifi.cpp for more information 131 | * describing how these and other commands are invoked. 132 | * 133 | * @param command is the string command 134 | * @param reply is a buffer to receive a reply string 135 | * @param reply_len on entry, this is the maximum length of 136 | * the reply buffer. On exit, the number of 137 | * bytes in the reply buffer. 138 | * 139 | * @return 0 if successful, < 0 if an error. 140 | */ 141 | int wifi_command(const char *command, char *reply, size_t *reply_len); 142 | 143 | /** 144 | * do_dhcp_request() issues a dhcp request and returns the acquired 145 | * information. 146 | * 147 | * All IPV4 addresses/mask are in network byte order. 148 | * 149 | * @param ipaddr return the assigned IPV4 address 150 | * @param gateway return the gateway being used 151 | * @param mask return the IPV4 mask 152 | * @param dns1 return the IPV4 address of a DNS server 153 | * @param dns2 return the IPV4 address of a DNS server 154 | * @param server return the IPV4 address of DHCP server 155 | * @param lease return the length of lease in seconds. 156 | * 157 | * @return 0 if successful, < 0 if error. 158 | */ 159 | int do_dhcp_request(int *ipaddr, int *gateway, int *mask, 160 | int *dns1, int *dns2, int *server, int *lease); 161 | 162 | /** 163 | * Return the error string of the last do_dhcp_request(). 164 | */ 165 | const char *get_dhcp_error_string(); 166 | 167 | #if __cplusplus 168 | }; // extern "C" 169 | #endif 170 | 171 | #endif // _WIFI_H 172 | -------------------------------------------------------------------------------- /qemu/qemu.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 | /* this file contains various functions used by all libhardware modules 18 | * that support QEMU emulation 19 | */ 20 | #include "qemu.h" 21 | #define LOG_TAG "hardware-qemu" 22 | #include 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(...) LOGD(__VA_ARGS__) 35 | #else 36 | # define D(...) ((void)0) 37 | #endif 38 | 39 | 40 | int 41 | qemu_check(void) 42 | { 43 | static int in_qemu = -1; 44 | 45 | if (__builtin_expect(in_qemu < 0,0)) { 46 | char propBuf[PROPERTY_VALUE_MAX]; 47 | property_get("ro.kernel.qemu", propBuf, ""); 48 | in_qemu = (propBuf[0] == '1'); 49 | } 50 | return in_qemu; 51 | } 52 | 53 | static int 54 | qemu_fd_write( int fd, const char* cmd, int len ) 55 | { 56 | int len2; 57 | do { 58 | len2 = write(fd, cmd, len); 59 | } while (len2 < 0 && errno == EINTR); 60 | return len2; 61 | } 62 | 63 | static int 64 | qemu_fd_read( int fd, char* buff, int len ) 65 | { 66 | int len2; 67 | do { 68 | len2 = read(fd, buff, len); 69 | } while (len2 < 0 && errno == EINTR); 70 | return len2; 71 | } 72 | 73 | 74 | static int 75 | qemu_channel_open_qemud( QemuChannel* channel, 76 | const char* name ) 77 | { 78 | int fd, ret, namelen = strlen(name); 79 | char answer[2]; 80 | 81 | fd = socket_local_client( "qemud", 82 | ANDROID_SOCKET_NAMESPACE_RESERVED, 83 | SOCK_STREAM ); 84 | if (fd < 0) { 85 | D("no qemud control socket: %s", strerror(errno)); 86 | return -1; 87 | } 88 | 89 | /* send service name to connect */ 90 | if (qemu_fd_write(fd, name, namelen) != namelen) { 91 | D("can't send service name to qemud: %s", 92 | strerror(errno)); 93 | close(fd); 94 | return -1; 95 | } 96 | 97 | /* read answer from daemon */ 98 | if (qemu_fd_read(fd, answer, 2) != 2 || 99 | answer[0] != 'O' || answer[1] != 'K') { 100 | D("cant' connect to %s service through qemud", name); 101 | close(fd); 102 | return -1; 103 | } 104 | 105 | channel->is_qemud = 1; 106 | channel->fd = fd; 107 | return 0; 108 | } 109 | 110 | 111 | static int 112 | qemu_channel_open_qemud_old( QemuChannel* channel, 113 | const char* name ) 114 | { 115 | int fd; 116 | 117 | snprintf(channel->device, sizeof channel->device, 118 | "qemud_%s", name); 119 | 120 | fd = socket_local_client( channel->device, 121 | ANDROID_SOCKET_NAMESPACE_RESERVED, 122 | SOCK_STREAM ); 123 | if (fd < 0) { 124 | D("no '%s' control socket available: %s", 125 | channel->device, strerror(errno)); 126 | return -1; 127 | } 128 | 129 | close(fd); 130 | channel->is_qemud_old = 1; 131 | return 0; 132 | } 133 | 134 | 135 | static int 136 | qemu_channel_open_tty( QemuChannel* channel, 137 | const char* name, 138 | int mode ) 139 | { 140 | char key[PROPERTY_KEY_MAX]; 141 | char prop[PROPERTY_VALUE_MAX]; 142 | int ret; 143 | 144 | ret = snprintf(key, sizeof key, "ro.kernel.android.%s", name); 145 | if (ret >= (int)sizeof key) 146 | return -1; 147 | 148 | if (property_get(key, prop, "") == 0) { 149 | D("no kernel-provided %s device name", name); 150 | return -1; 151 | } 152 | 153 | ret = snprintf(channel->device, sizeof channel->device, 154 | "/dev/%s", prop); 155 | if (ret >= (int)sizeof channel->device) { 156 | D("%s device name too long: '%s'", name, prop); 157 | return -1; 158 | } 159 | 160 | channel->is_tty = !memcmp("/dev/tty", channel->device, 8); 161 | return 0; 162 | } 163 | 164 | int 165 | qemu_channel_open( QemuChannel* channel, 166 | const char* name, 167 | int mode ) 168 | { 169 | int fd = -1; 170 | 171 | /* initialize the channel is needed */ 172 | if (!channel->is_inited) 173 | { 174 | channel->is_inited = 1; 175 | 176 | do { 177 | if (qemu_channel_open_qemud(channel, name) == 0) 178 | break; 179 | 180 | if (qemu_channel_open_qemud_old(channel, name) == 0) 181 | break; 182 | 183 | if (qemu_channel_open_tty(channel, name, mode) == 0) 184 | break; 185 | 186 | channel->is_available = 0; 187 | return -1; 188 | } while (0); 189 | 190 | channel->is_available = 1; 191 | } 192 | 193 | /* try to open the file */ 194 | if (!channel->is_available) { 195 | errno = ENOENT; 196 | return -1; 197 | } 198 | 199 | if (channel->is_qemud) { 200 | return dup(channel->fd); 201 | } 202 | 203 | if (channel->is_qemud_old) { 204 | do { 205 | fd = socket_local_client( channel->device, 206 | ANDROID_SOCKET_NAMESPACE_RESERVED, 207 | SOCK_STREAM ); 208 | } while (fd < 0 && errno == EINTR); 209 | } 210 | else /* /dev/ttySn ? */ 211 | { 212 | do { 213 | fd = open(channel->device, mode); 214 | } while (fd < 0 && errno == EINTR); 215 | 216 | /* disable ECHO on serial lines */ 217 | if (fd >= 0 && channel->is_tty) { 218 | struct termios ios; 219 | tcgetattr( fd, &ios ); 220 | ios.c_lflag = 0; /* disable ECHO, ICANON, etc... */ 221 | tcsetattr( fd, TCSANOW, &ios ); 222 | } 223 | } 224 | return fd; 225 | } 226 | 227 | 228 | static int 229 | qemu_command_vformat( char* buffer, 230 | int buffer_size, 231 | const char* format, 232 | va_list args ) 233 | { 234 | char header[5]; 235 | int len; 236 | 237 | if (buffer_size < 6) 238 | return -1; 239 | 240 | len = vsnprintf(buffer+4, buffer_size-4, format, args); 241 | if (len >= buffer_size-4) 242 | return -1; 243 | 244 | snprintf(header, sizeof header, "%04x", len); 245 | memcpy(buffer, header, 4); 246 | return len + 4; 247 | } 248 | 249 | extern int 250 | qemu_command_format( char* buffer, 251 | int buffer_size, 252 | const char* format, 253 | ... ) 254 | { 255 | va_list args; 256 | int ret; 257 | 258 | va_start(args, format); 259 | ret = qemu_command_format(buffer, buffer_size, format, args); 260 | va_end(args); 261 | return ret; 262 | } 263 | 264 | 265 | static int 266 | qemu_control_fd(void) 267 | { 268 | static QemuChannel channel[1]; 269 | int fd; 270 | 271 | fd = qemu_channel_open( channel, "hw-control", O_RDWR ); 272 | if (fd < 0) { 273 | D("%s: could not open control channel: %s", __FUNCTION__, 274 | strerror(errno)); 275 | } 276 | return fd; 277 | } 278 | 279 | static int 280 | qemu_control_send(const char* cmd, int len) 281 | { 282 | int fd, len2; 283 | 284 | if (len < 0) { 285 | errno = EINVAL; 286 | return -1; 287 | } 288 | 289 | fd = qemu_control_fd(); 290 | if (fd < 0) 291 | return -1; 292 | 293 | len2 = qemu_fd_write(fd, cmd, len); 294 | close(fd); 295 | if (len2 != len) { 296 | D("%s: could not send everything %d < %d", 297 | __FUNCTION__, len2, len); 298 | return -1; 299 | } 300 | return 0; 301 | } 302 | 303 | 304 | int 305 | qemu_control_command( const char* fmt, ... ) 306 | { 307 | va_list args; 308 | char command[256]; 309 | int len, fd; 310 | 311 | va_start(args, fmt); 312 | len = qemu_command_vformat( command, sizeof command, fmt, args ); 313 | va_end(args); 314 | 315 | if (len < 0 || len >= (int)sizeof command) { 316 | if (len < 0) { 317 | D("%s: could not send: %s", __FUNCTION__, strerror(errno)); 318 | } else { 319 | D("%s: too large %d > %d", __FUNCTION__, len, (int)(sizeof command)); 320 | } 321 | errno = EINVAL; 322 | return -1; 323 | } 324 | 325 | return qemu_control_send( command, len ); 326 | } 327 | 328 | extern int qemu_control_query( const char* question, int questionlen, 329 | char* answer, int answersize ) 330 | { 331 | int ret, fd, len, result = -1; 332 | char header[5], *end; 333 | 334 | if (questionlen <= 0) { 335 | errno = EINVAL; 336 | return -1; 337 | } 338 | 339 | fd = qemu_control_fd(); 340 | if (fd < 0) 341 | return -1; 342 | 343 | ret = qemu_fd_write( fd, question, questionlen ); 344 | if (ret != questionlen) { 345 | D("%s: could not write all: %d < %d", __FUNCTION__, 346 | ret, questionlen); 347 | goto Exit; 348 | } 349 | 350 | /* read a 4-byte header giving the length of the following content */ 351 | ret = qemu_fd_read( fd, header, 4 ); 352 | if (ret != 4) { 353 | D("%s: could not read header (%d != 4)", 354 | __FUNCTION__, ret); 355 | goto Exit; 356 | } 357 | 358 | header[4] = 0; 359 | len = strtol( header, &end, 16 ); 360 | if ( len < 0 || end == NULL || end != header+4 || len > answersize ) { 361 | D("%s: could not parse header: '%s'", 362 | __FUNCTION__, header); 363 | goto Exit; 364 | } 365 | 366 | /* read the answer */ 367 | ret = qemu_fd_read( fd, answer, len ); 368 | if (ret != len) { 369 | D("%s: could not read all of answer %d < %d", 370 | __FUNCTION__, ret, len); 371 | goto Exit; 372 | } 373 | 374 | result = len; 375 | 376 | Exit: 377 | close(fd); 378 | return result; 379 | } 380 | -------------------------------------------------------------------------------- /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 | #define HAVE_FM_RADIO 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include "media/AudioSystem.h" 32 | 33 | 34 | namespace android { 35 | 36 | // ---------------------------------------------------------------------------- 37 | 38 | /** 39 | * AudioStreamOut is the abstraction interface for the audio output hardware. 40 | * 41 | * It provides information about various properties of the audio output hardware driver. 42 | */ 43 | class AudioStreamOut { 44 | public: 45 | virtual ~AudioStreamOut() = 0; 46 | 47 | /** return audio sampling rate in hz - eg. 44100 */ 48 | virtual uint32_t sampleRate() const = 0; 49 | 50 | /** returns size of output buffer - eg. 4800 */ 51 | virtual size_t bufferSize() const = 0; 52 | 53 | /** 54 | * returns the output channel nask 55 | */ 56 | virtual uint32_t channels() const = 0; 57 | 58 | /** 59 | * return audio format in 8bit or 16bit PCM format - 60 | * eg. AudioSystem:PCM_16_BIT 61 | */ 62 | virtual int format() const = 0; 63 | 64 | /** 65 | * return the frame size (number of bytes per sample). 66 | */ 67 | uint32_t frameSize() const { return AudioSystem::popCount(channels())*((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } 68 | 69 | /** 70 | * return the audio hardware driver latency in milli seconds. 71 | */ 72 | virtual uint32_t latency() const = 0; 73 | 74 | /** 75 | * Use this method in situations where audio mixing is done in the 76 | * hardware. This method serves as a direct interface with hardware, 77 | * allowing you to directly set the volume as apposed to via the framework. 78 | * This method might produce multiple PCM outputs or hardware accelerated 79 | * codecs, such as MP3 or AAC. 80 | */ 81 | virtual status_t setVolume(float left, float right) = 0; 82 | 83 | /** write audio buffer to driver. Returns number of bytes written */ 84 | virtual ssize_t write(const void* buffer, size_t bytes) = 0; 85 | 86 | /** 87 | * Put the audio hardware output into standby mode. Returns 88 | * status based on include/utils/Errors.h 89 | */ 90 | virtual status_t standby() = 0; 91 | 92 | /** dump the state of the audio output device */ 93 | virtual status_t dump(int fd, const Vector& args) = 0; 94 | 95 | // set/get audio output parameters. The function accepts a list of parameters 96 | // key value pairs in the form: key1=value1;key2=value2;... 97 | // Some keys are reserved for standard parameters (See AudioParameter class). 98 | // If the implementation does not accept a parameter change while the output is 99 | // active but the parameter is acceptable otherwise, it must return INVALID_OPERATION. 100 | // The audio flinger will put the output in standby and then change the parameter value. 101 | virtual status_t setParameters(const String8& keyValuePairs) = 0; 102 | virtual String8 getParameters(const String8& keys) = 0; 103 | 104 | // return the number of audio frames written by the audio dsp to DAC since 105 | // the output has exited standby 106 | virtual status_t getRenderPosition(uint32_t *dspFrames) = 0; 107 | }; 108 | 109 | /** 110 | * AudioStreamIn is the abstraction interface for the audio input hardware. 111 | * 112 | * It defines the various properties of the audio hardware input driver. 113 | */ 114 | class AudioStreamIn { 115 | public: 116 | virtual ~AudioStreamIn() = 0; 117 | 118 | /** return audio sampling rate in hz - eg. 44100 */ 119 | virtual uint32_t sampleRate() const = 0; 120 | 121 | /** return the input buffer size allowed by audio driver */ 122 | virtual size_t bufferSize() const = 0; 123 | 124 | /** return input channel mask */ 125 | virtual uint32_t channels() const = 0; 126 | 127 | /** 128 | * return audio format in 8bit or 16bit PCM format - 129 | * eg. AudioSystem:PCM_16_BIT 130 | */ 131 | virtual int format() const = 0; 132 | 133 | /** 134 | * return the frame size (number of bytes per sample). 135 | */ 136 | uint32_t frameSize() const { return AudioSystem::popCount(channels())*((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } 137 | 138 | /** set the input gain for the audio driver. This method is for 139 | * for future use */ 140 | virtual status_t setGain(float gain) = 0; 141 | 142 | /** read audio buffer in from audio driver */ 143 | virtual ssize_t read(void* buffer, ssize_t bytes) = 0; 144 | 145 | /** dump the state of the audio input device */ 146 | virtual status_t dump(int fd, const Vector& args) = 0; 147 | 148 | /** 149 | * Put the audio hardware input into standby mode. Returns 150 | * status based on include/utils/Errors.h 151 | */ 152 | virtual status_t standby() = 0; 153 | 154 | // set/get audio input parameters. The function accepts a list of parameters 155 | // key value pairs in the form: key1=value1;key2=value2;... 156 | // Some keys are reserved for standard parameters (See AudioParameter class). 157 | // If the implementation does not accept a parameter change while the output is 158 | // active but the parameter is acceptable otherwise, it must return INVALID_OPERATION. 159 | // The audio flinger will put the input in standby and then change the parameter value. 160 | virtual status_t setParameters(const String8& keyValuePairs) = 0; 161 | virtual String8 getParameters(const String8& keys) = 0; 162 | 163 | 164 | // Return the amount of input frames lost in the audio driver since the last call of this function. 165 | // Audio driver is expected to reset the value to 0 and restart counting upon returning the current value by this function call. 166 | // Such loss typically occurs when the user space process is blocked longer than the capacity of audio driver buffers. 167 | // Unit: the number of input audio frames 168 | virtual unsigned int getInputFramesLost() const = 0; 169 | 170 | }; 171 | 172 | /** 173 | * AudioHardwareInterface.h defines the interface to the audio hardware abstraction layer. 174 | * 175 | * The interface supports setting and getting parameters, selecting audio routing 176 | * paths, and defining input and output streams. 177 | * 178 | * AudioFlinger initializes the audio hardware and immediately opens an output stream. 179 | * You can set Audio routing to output to handset, speaker, Bluetooth, or a headset. 180 | * 181 | * The audio input stream is initialized when AudioFlinger is called to carry out 182 | * a record operation. 183 | */ 184 | class AudioHardwareInterface 185 | { 186 | public: 187 | virtual ~AudioHardwareInterface() {} 188 | 189 | /** 190 | * check to see if the audio hardware interface has been initialized. 191 | * return status based on values defined in include/utils/Errors.h 192 | */ 193 | virtual status_t initCheck() = 0; 194 | 195 | /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */ 196 | virtual status_t setVoiceVolume(float volume) = 0; 197 | 198 | /** 199 | * set the audio volume for all audio activities other than voice call. 200 | * Range between 0.0 and 1.0. If any value other than NO_ERROR is returned, 201 | * the software mixer will emulate this capability. 202 | */ 203 | virtual status_t setMasterVolume(float volume) = 0; 204 | 205 | /** 206 | * setMode is called when the audio mode changes. NORMAL mode is for 207 | * standard audio playback, RINGTONE when a ringtone is playing, and IN_CALL 208 | * when a call is in progress. 209 | */ 210 | virtual status_t setMode(int mode) = 0; 211 | 212 | // mic mute 213 | virtual status_t setMicMute(bool state) = 0; 214 | virtual status_t getMicMute(bool* state) = 0; 215 | 216 | // set/get global audio parameters 217 | virtual status_t setParameters(const String8& keyValuePairs) = 0; 218 | virtual String8 getParameters(const String8& keys) = 0; 219 | 220 | // Returns audio input buffer size according to parameters passed or 0 if one of the 221 | // parameters is not supported 222 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount) = 0; 223 | 224 | /** This method creates and opens the audio hardware output stream */ 225 | virtual AudioStreamOut* openOutputStream( 226 | uint32_t devices, 227 | int *format=0, 228 | uint32_t *channels=0, 229 | uint32_t *sampleRate=0, 230 | status_t *status=0) = 0; 231 | virtual void closeOutputStream(AudioStreamOut* out) = 0; 232 | /** This method creates and opens the audio hardware input stream */ 233 | virtual AudioStreamIn* openInputStream( 234 | uint32_t devices, 235 | int *format, 236 | uint32_t *channels, 237 | uint32_t *sampleRate, 238 | status_t *status, 239 | AudioSystem::audio_in_acoustics acoustics) = 0; 240 | virtual void closeInputStream(AudioStreamIn* in) = 0; 241 | 242 | /**This method dumps the state of the audio hardware */ 243 | virtual status_t dumpState(int fd, const Vector& args) = 0; 244 | 245 | static AudioHardwareInterface* create(); 246 | 247 | protected: 248 | 249 | virtual status_t dump(int fd, const Vector& args) = 0; 250 | 251 | #ifdef HAVE_FM_RADIO 252 | public: 253 | /** set the fm volume. Range is between 0.0 and 1.0 */ 254 | virtual status_t setFmVolume(float volume) { return 0; } 255 | #endif 256 | }; 257 | 258 | // ---------------------------------------------------------------------------- 259 | 260 | extern "C" AudioHardwareInterface* createAudioHardware(void); 261 | 262 | }; // namespace android 263 | 264 | #endif // ANDROID_AUDIO_HARDWARE_INTERFACE_H 265 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | #define HAVE_FM_RADIO 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace android { 27 | 28 | 29 | // ---------------------------------------------------------------------------- 30 | 31 | // The AudioPolicyInterface and AudioPolicyClientInterface classes define the communication interfaces 32 | // between the platform specific audio policy manager and Android generic audio policy manager. 33 | // The platform specific audio policy manager must implement methods of the AudioPolicyInterface class. 34 | // This implementation makes use of the AudioPolicyClientInterface to control the activity and 35 | // configuration of audio input and output streams. 36 | // 37 | // The platform specific audio policy manager is in charge of the audio routing and volume control 38 | // policies for a given platform. 39 | // The main roles of this module are: 40 | // - keep track of current system state (removable device connections, phone state, user requests...). 41 | // System state changes and user actions are notified to audio policy manager with methods of the AudioPolicyInterface. 42 | // - process getOutput() queries received when AudioTrack objects are created: Those queries 43 | // return a handler on an output that has been selected, configured and opened by the audio policy manager and that 44 | // must be used by the AudioTrack when registering to the AudioFlinger with the createTrack() method. 45 | // When the AudioTrack object is released, a putOutput() query is received and the audio policy manager can decide 46 | // to close or reconfigure the output depending on other streams using this output and current system state. 47 | // - similarly process getInput() and putInput() queries received from AudioRecord objects and configure audio inputs. 48 | // - process volume control requests: the stream volume is converted from an index value (received from UI) to a float value 49 | // applicable to each output as a function of platform specific settings and current output route (destination device). It 50 | // also make sure that streams are not muted if not allowed (e.g. camera shutter sound in some countries). 51 | // 52 | // The platform specific audio policy manager is provided as a shared library by platform vendors (as for libaudio.so) 53 | // and is linked with libaudioflinger.so 54 | 55 | 56 | // Audio Policy Manager Interface 57 | class AudioPolicyInterface 58 | { 59 | 60 | public: 61 | virtual ~AudioPolicyInterface() {} 62 | // 63 | // configuration functions 64 | // 65 | 66 | // indicate a change in device connection status 67 | virtual status_t setDeviceConnectionState(AudioSystem::audio_devices device, 68 | AudioSystem::device_connection_state state, 69 | const char *device_address) = 0; 70 | // retreive a device connection status 71 | virtual AudioSystem::device_connection_state getDeviceConnectionState(AudioSystem::audio_devices device, 72 | const char *device_address) = 0; 73 | // indicate a change in phone state. Valid phones states are defined by AudioSystem::audio_mode 74 | virtual void setPhoneState(int state) = 0; 75 | // indicate a change in ringer mode 76 | virtual void setRingerMode(uint32_t mode, uint32_t mask) = 0; 77 | // force using a specific device category for the specified usage 78 | virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config) = 0; 79 | // retreive current device category forced for a given usage 80 | virtual AudioSystem::forced_config getForceUse(AudioSystem::force_use usage) = 0; 81 | // set a system property (e.g. camera sound always audible) 82 | virtual void setSystemProperty(const char* property, const char* value) = 0; 83 | 84 | 85 | // 86 | // Audio routing query functions 87 | // 88 | 89 | // request an output appriate for playback of the supplied stream type and parameters 90 | virtual audio_io_handle_t getOutput(AudioSystem::stream_type stream, 91 | uint32_t samplingRate = 0, 92 | uint32_t format = AudioSystem::FORMAT_DEFAULT, 93 | uint32_t channels = 0, 94 | AudioSystem::output_flags flags = AudioSystem::OUTPUT_FLAG_INDIRECT) = 0; 95 | // indicates to the audio policy manager that the output starts being used by corresponding stream. 96 | virtual status_t startOutput(audio_io_handle_t output, 97 | AudioSystem::stream_type stream, 98 | int session = 0) = 0; 99 | // indicates to the audio policy manager that the output stops being used by corresponding stream. 100 | virtual status_t stopOutput(audio_io_handle_t output, 101 | AudioSystem::stream_type stream, 102 | int session = 0) = 0; 103 | // releases the output. 104 | virtual void releaseOutput(audio_io_handle_t output) = 0; 105 | 106 | // request an input appriate for record from the supplied device with supplied parameters. 107 | virtual audio_io_handle_t getInput(int inputSource, 108 | uint32_t samplingRate = 0, 109 | uint32_t Format = AudioSystem::FORMAT_DEFAULT, 110 | uint32_t channels = 0, 111 | AudioSystem::audio_in_acoustics acoustics = (AudioSystem::audio_in_acoustics)0) = 0; 112 | // indicates to the audio policy manager that the input starts being used. 113 | virtual status_t startInput(audio_io_handle_t input) = 0; 114 | // indicates to the audio policy manager that the input stops being used. 115 | virtual status_t stopInput(audio_io_handle_t input) = 0; 116 | // releases the input. 117 | virtual void releaseInput(audio_io_handle_t input) = 0; 118 | 119 | // 120 | // volume control functions 121 | // 122 | 123 | // initialises stream volume conversion parameters by specifying volume index range. 124 | virtual void initStreamVolume(AudioSystem::stream_type stream, 125 | int indexMin, 126 | int indexMax) = 0; 127 | 128 | // sets the new stream volume at a level corresponding to the supplied index 129 | virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream, int index) = 0; 130 | // retreive current volume index for the specified stream 131 | virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream, int *index) = 0; 132 | 133 | // return the strategy corresponding to a given stream type 134 | virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream) = 0; 135 | 136 | // Audio effect management 137 | virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc) = 0; 138 | virtual status_t registerEffect(effect_descriptor_t *desc, 139 | audio_io_handle_t output, 140 | uint32_t strategy, 141 | int session, 142 | int id) = 0; 143 | virtual status_t unregisterEffect(int id) = 0; 144 | 145 | //dump state 146 | virtual status_t dump(int fd) = 0; 147 | }; 148 | 149 | 150 | // Audio Policy client Interface 151 | class AudioPolicyClientInterface 152 | { 153 | public: 154 | virtual ~AudioPolicyClientInterface() {} 155 | 156 | // 157 | // Audio output Control functions 158 | // 159 | 160 | // opens an audio output with the requested parameters. The parameter values can indicate to use the default values 161 | // in case the audio policy manager has no specific requirements for the output being opened. 162 | // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream. 163 | // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly. 164 | virtual audio_io_handle_t openOutput(uint32_t *pDevices, 165 | uint32_t *pSamplingRate, 166 | uint32_t *pFormat, 167 | uint32_t *pChannels, 168 | uint32_t *pLatencyMs, 169 | AudioSystem::output_flags flags) = 0; 170 | // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by 171 | // a special mixer thread in the AudioFlinger. 172 | virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2) = 0; 173 | // closes the output stream 174 | virtual status_t closeOutput(audio_io_handle_t output) = 0; 175 | // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in 176 | // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded. 177 | virtual status_t suspendOutput(audio_io_handle_t output) = 0; 178 | // restores a suspended output. 179 | virtual status_t restoreOutput(audio_io_handle_t output) = 0; 180 | 181 | // 182 | // Audio input Control functions 183 | // 184 | 185 | // opens an audio input 186 | virtual audio_io_handle_t openInput(uint32_t *pDevices, 187 | uint32_t *pSamplingRate, 188 | uint32_t *pFormat, 189 | uint32_t *pChannels, 190 | uint32_t acoustics) = 0; 191 | // closes an audio input 192 | virtual status_t closeInput(audio_io_handle_t input) = 0; 193 | // 194 | // misc control functions 195 | // 196 | 197 | // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes 198 | // for each output (destination device) it is attached to. 199 | virtual status_t setStreamVolume(AudioSystem::stream_type stream, float volume, audio_io_handle_t output, int delayMs = 0) = 0; 200 | 201 | // reroute a given stream type to the specified output 202 | virtual status_t setStreamOutput(AudioSystem::stream_type stream, audio_io_handle_t output) = 0; 203 | 204 | // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface. 205 | virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0) = 0; 206 | // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager. 207 | virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) = 0; 208 | 209 | // request the playback of a tone on the specified stream: used for instance to replace notification sounds when playing 210 | // over a telephony device during a phone call. 211 | virtual status_t startTone(ToneGenerator::tone_type tone, AudioSystem::stream_type stream) = 0; 212 | virtual status_t stopTone() = 0; 213 | 214 | // set down link audio volume. 215 | virtual status_t setVoiceVolume(float volume, int delayMs = 0) = 0; 216 | 217 | // move effect to the specified output 218 | virtual status_t moveEffects(int session, 219 | audio_io_handle_t srcOutput, 220 | audio_io_handle_t dstOutput) = 0; 221 | 222 | #ifdef HAVE_FM_RADIO 223 | // set FM volume. 224 | virtual status_t setFmVolume(float volume, int delayMs = 0) { return 0; } 225 | #endif 226 | }; 227 | 228 | extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface); 229 | extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface); 230 | 231 | 232 | }; // namespace android 233 | 234 | #endif // ANDROID_AUDIOPOLICYINTERFACE_H 235 | -------------------------------------------------------------------------------- /wifi/wifi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 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 | #include 19 | #include 20 | #include 21 | 22 | #include "hardware_legacy/wifi.h" 23 | #include "libwpa_client/wpa_ctrl.h" 24 | 25 | #define LOG_TAG "WifiHW" 26 | #include "cutils/log.h" 27 | #include "cutils/memory.h" 28 | #include "cutils/misc.h" 29 | #include "cutils/properties.h" 30 | #include "private/android_filesystem_config.h" 31 | #ifdef HAVE_LIBC_SYSTEM_PROPERTIES 32 | #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ 33 | #include 34 | #endif 35 | 36 | static struct wpa_ctrl *ctrl_conn; 37 | static struct wpa_ctrl *monitor_conn; 38 | 39 | extern int do_dhcp(); 40 | extern int ifc_init(); 41 | extern void ifc_close(); 42 | extern char *dhcp_lasterror(); 43 | extern void get_dhcp_info(); 44 | extern int init_module(void *, unsigned long, const char *); 45 | extern int delete_module(const char *, unsigned int); 46 | 47 | static char iface[PROPERTY_VALUE_MAX]; 48 | // TODO: use new ANDROID_SOCKET mechanism, once support for multiple 49 | // sockets is in 50 | 51 | #ifndef WIFI_DRIVER_MODULE_PATH 52 | #define WIFI_DRIVER_MODULE_PATH "/system/lib/modules/wlan.ko" 53 | #endif 54 | #ifndef WIFI_DRIVER_MODULE_NAME 55 | #define WIFI_DRIVER_MODULE_NAME "wlan" 56 | #endif 57 | #ifndef WIFI_DRIVER_MODULE_ARG 58 | #define WIFI_DRIVER_MODULE_ARG "" 59 | #endif 60 | #ifndef WIFI_FIRMWARE_LOADER 61 | #define WIFI_FIRMWARE_LOADER "" 62 | #endif 63 | #define WIFI_TEST_INTERFACE "sta" 64 | 65 | #define WIFI_DRIVER_LOADER_DELAY 1000000 66 | 67 | static const char IFACE_DIR[] = "/data/system/wpa_supplicant"; 68 | static const char DRIVER_MODULE_NAME[] = WIFI_DRIVER_MODULE_NAME; 69 | static const char DRIVER_MODULE_TAG[] = WIFI_DRIVER_MODULE_NAME " "; 70 | static const char DRIVER_MODULE_PATH[] = WIFI_DRIVER_MODULE_PATH; 71 | static const char DRIVER_MODULE_ARG[] = WIFI_DRIVER_MODULE_ARG; 72 | static const char FIRMWARE_LOADER[] = WIFI_FIRMWARE_LOADER; 73 | static const char DRIVER_PROP_NAME[] = "wlan.driver.status"; 74 | static const char SUPPLICANT_NAME[] = "wpa_supplicant"; 75 | static const char SUPP_PROP_NAME[] = "init.svc.wpa_supplicant"; 76 | static const char SUPP_CONFIG_TEMPLATE[]= "/system/etc/wifi/wpa_supplicant.conf"; 77 | static const char SUPP_CONFIG_FILE[] = "/data/misc/wifi/wpa_supplicant.conf"; 78 | static const char MODULE_FILE[] = "/proc/modules"; 79 | 80 | static int insmod(const char *filename, const char *args) 81 | { 82 | void *module; 83 | unsigned int size; 84 | int ret; 85 | 86 | module = load_file(filename, &size); 87 | if (!module) 88 | return -1; 89 | 90 | ret = init_module(module, size, args); 91 | 92 | free(module); 93 | 94 | return ret; 95 | } 96 | 97 | static int rmmod(const char *modname) 98 | { 99 | int ret = -1; 100 | int maxtry = 10; 101 | 102 | while (maxtry-- > 0) { 103 | ret = delete_module(modname, O_NONBLOCK | O_EXCL); 104 | if (ret < 0 && errno == EAGAIN) 105 | usleep(500000); 106 | else 107 | break; 108 | } 109 | 110 | if (ret != 0) 111 | LOGD("Unable to unload driver module \"%s\": %s\n", 112 | modname, strerror(errno)); 113 | return ret; 114 | } 115 | 116 | int do_dhcp_request(int *ipaddr, int *gateway, int *mask, 117 | int *dns1, int *dns2, int *server, int *lease) { 118 | /* For test driver, always report success */ 119 | if (strcmp(iface, WIFI_TEST_INTERFACE) == 0) 120 | return 0; 121 | 122 | if (ifc_init() < 0) 123 | return -1; 124 | 125 | if (do_dhcp(iface) < 0) { 126 | ifc_close(); 127 | return -1; 128 | } 129 | ifc_close(); 130 | get_dhcp_info(ipaddr, gateway, mask, dns1, dns2, server, lease); 131 | return 0; 132 | } 133 | 134 | const char *get_dhcp_error_string() { 135 | return dhcp_lasterror(); 136 | } 137 | 138 | static int check_driver_loaded() { 139 | char driver_status[PROPERTY_VALUE_MAX]; 140 | FILE *proc; 141 | char line[sizeof(DRIVER_MODULE_TAG)+10]; 142 | 143 | if (!property_get(DRIVER_PROP_NAME, driver_status, NULL) 144 | || strcmp(driver_status, "ok") != 0) { 145 | return 0; /* driver not loaded */ 146 | } 147 | /* 148 | * If the property says the driver is loaded, check to 149 | * make sure that the property setting isn't just left 150 | * over from a previous manual shutdown or a runtime 151 | * crash. 152 | */ 153 | if ((proc = fopen(MODULE_FILE, "r")) == NULL) { 154 | LOGW("Could not open %s: %s", MODULE_FILE, strerror(errno)); 155 | property_set(DRIVER_PROP_NAME, "unloaded"); 156 | return 0; 157 | } 158 | while ((fgets(line, sizeof(line), proc)) != NULL) { 159 | if (strncmp(line, DRIVER_MODULE_TAG, strlen(DRIVER_MODULE_TAG)) == 0) { 160 | fclose(proc); 161 | return 1; 162 | } 163 | } 164 | fclose(proc); 165 | property_set(DRIVER_PROP_NAME, "unloaded"); 166 | return 0; 167 | } 168 | 169 | int wifi_load_driver() 170 | { 171 | char driver_status[PROPERTY_VALUE_MAX]; 172 | int count = 100; /* wait at most 20 seconds for completion */ 173 | 174 | if (check_driver_loaded()) { 175 | return 0; 176 | } 177 | 178 | if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0) 179 | return -1; 180 | 181 | if (strcmp(FIRMWARE_LOADER,"") == 0) { 182 | usleep(WIFI_DRIVER_LOADER_DELAY); 183 | property_set(DRIVER_PROP_NAME, "ok"); 184 | } 185 | else { 186 | property_set("ctl.start", FIRMWARE_LOADER); 187 | } 188 | sched_yield(); 189 | while (count-- > 0) { 190 | if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) { 191 | if (strcmp(driver_status, "ok") == 0) 192 | return 0; 193 | else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) { 194 | wifi_unload_driver(); 195 | return -1; 196 | } 197 | } 198 | usleep(200000); 199 | } 200 | property_set(DRIVER_PROP_NAME, "timeout"); 201 | wifi_unload_driver(); 202 | return -1; 203 | } 204 | 205 | int wifi_unload_driver() 206 | { 207 | int count = 20; /* wait at most 10 seconds for completion */ 208 | 209 | if (rmmod(DRIVER_MODULE_NAME) == 0) { 210 | while (count-- > 0) { 211 | if (!check_driver_loaded()) 212 | break; 213 | usleep(500000); 214 | } 215 | if (count) { 216 | return 0; 217 | } 218 | return -1; 219 | } else 220 | return -1; 221 | } 222 | 223 | int ensure_config_file_exists() 224 | { 225 | char buf[2048]; 226 | int srcfd, destfd; 227 | int nread; 228 | 229 | if (access(SUPP_CONFIG_FILE, R_OK|W_OK) == 0) { 230 | return 0; 231 | } else if (errno != ENOENT) { 232 | LOGE("Cannot access \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno)); 233 | return -1; 234 | } 235 | 236 | srcfd = open(SUPP_CONFIG_TEMPLATE, O_RDONLY); 237 | if (srcfd < 0) { 238 | LOGE("Cannot open \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno)); 239 | return -1; 240 | } 241 | 242 | destfd = open(SUPP_CONFIG_FILE, O_CREAT|O_WRONLY, 0660); 243 | if (destfd < 0) { 244 | close(srcfd); 245 | LOGE("Cannot create \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno)); 246 | return -1; 247 | } 248 | 249 | while ((nread = read(srcfd, buf, sizeof(buf))) != 0) { 250 | if (nread < 0) { 251 | LOGE("Error reading \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno)); 252 | close(srcfd); 253 | close(destfd); 254 | unlink(SUPP_CONFIG_FILE); 255 | return -1; 256 | } 257 | write(destfd, buf, nread); 258 | } 259 | 260 | close(destfd); 261 | close(srcfd); 262 | 263 | if (chown(SUPP_CONFIG_FILE, AID_SYSTEM, AID_WIFI) < 0) { 264 | LOGE("Error changing group ownership of %s to %d: %s", 265 | SUPP_CONFIG_FILE, AID_WIFI, strerror(errno)); 266 | unlink(SUPP_CONFIG_FILE); 267 | return -1; 268 | } 269 | return 0; 270 | } 271 | 272 | int wifi_start_supplicant() 273 | { 274 | char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; 275 | int count = 200; /* wait at most 20 seconds for completion */ 276 | #ifdef HAVE_LIBC_SYSTEM_PROPERTIES 277 | const prop_info *pi; 278 | unsigned serial = 0; 279 | #endif 280 | 281 | /* Check whether already running */ 282 | if (property_get(SUPP_PROP_NAME, supp_status, NULL) 283 | && strcmp(supp_status, "running") == 0) { 284 | return 0; 285 | } 286 | 287 | /* Before starting the daemon, make sure its config file exists */ 288 | if (ensure_config_file_exists() < 0) { 289 | LOGE("Wi-Fi will not be enabled"); 290 | return -1; 291 | } 292 | 293 | /* Clear out any stale socket files that might be left over. */ 294 | wpa_ctrl_cleanup(); 295 | 296 | #ifdef HAVE_LIBC_SYSTEM_PROPERTIES 297 | /* 298 | * Get a reference to the status property, so we can distinguish 299 | * the case where it goes stopped => running => stopped (i.e., 300 | * it start up, but fails right away) from the case in which 301 | * it starts in the stopped state and never manages to start 302 | * running at all. 303 | */ 304 | pi = __system_property_find(SUPP_PROP_NAME); 305 | if (pi != NULL) { 306 | serial = pi->serial; 307 | } 308 | #endif 309 | property_set("ctl.start", SUPPLICANT_NAME); 310 | sched_yield(); 311 | 312 | while (count-- > 0) { 313 | #ifdef HAVE_LIBC_SYSTEM_PROPERTIES 314 | if (pi == NULL) { 315 | pi = __system_property_find(SUPP_PROP_NAME); 316 | } 317 | if (pi != NULL) { 318 | __system_property_read(pi, NULL, supp_status); 319 | if (strcmp(supp_status, "running") == 0) { 320 | return 0; 321 | } else if (pi->serial != serial && 322 | strcmp(supp_status, "stopped") == 0) { 323 | return -1; 324 | } 325 | } 326 | #else 327 | if (property_get(SUPP_PROP_NAME, supp_status, NULL)) { 328 | if (strcmp(supp_status, "running") == 0) 329 | return 0; 330 | } 331 | #endif 332 | usleep(100000); 333 | } 334 | return -1; 335 | } 336 | 337 | int wifi_stop_supplicant() 338 | { 339 | char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; 340 | int count = 50; /* wait at most 5 seconds for completion */ 341 | 342 | /* Check whether supplicant already stopped */ 343 | if (property_get(SUPP_PROP_NAME, supp_status, NULL) 344 | && strcmp(supp_status, "stopped") == 0) { 345 | return 0; 346 | } 347 | 348 | property_set("ctl.stop", SUPPLICANT_NAME); 349 | sched_yield(); 350 | 351 | while (count-- > 0) { 352 | if (property_get(SUPP_PROP_NAME, supp_status, NULL)) { 353 | if (strcmp(supp_status, "stopped") == 0) 354 | return 0; 355 | } 356 | usleep(100000); 357 | } 358 | return -1; 359 | } 360 | 361 | int wifi_connect_to_supplicant() 362 | { 363 | char ifname[256]; 364 | char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; 365 | 366 | /* Make sure supplicant is running */ 367 | if (!property_get(SUPP_PROP_NAME, supp_status, NULL) 368 | || strcmp(supp_status, "running") != 0) { 369 | LOGE("Supplicant not running, cannot connect"); 370 | return -1; 371 | } 372 | 373 | property_get("wifi.interface", iface, WIFI_TEST_INTERFACE); 374 | 375 | if (access(IFACE_DIR, F_OK) == 0) { 376 | snprintf(ifname, sizeof(ifname), "%s/%s", IFACE_DIR, iface); 377 | } else { 378 | strlcpy(ifname, iface, sizeof(ifname)); 379 | } 380 | 381 | ctrl_conn = wpa_ctrl_open(ifname); 382 | if (ctrl_conn == NULL) { 383 | LOGE("Unable to open connection to supplicant on \"%s\": %s", 384 | ifname, strerror(errno)); 385 | return -1; 386 | } 387 | monitor_conn = wpa_ctrl_open(ifname); 388 | if (monitor_conn == NULL) { 389 | wpa_ctrl_close(ctrl_conn); 390 | ctrl_conn = NULL; 391 | return -1; 392 | } 393 | if (wpa_ctrl_attach(monitor_conn) != 0) { 394 | wpa_ctrl_close(monitor_conn); 395 | wpa_ctrl_close(ctrl_conn); 396 | ctrl_conn = monitor_conn = NULL; 397 | return -1; 398 | } 399 | return 0; 400 | } 401 | 402 | int wifi_send_command(struct wpa_ctrl *ctrl, const char *cmd, char *reply, size_t *reply_len) 403 | { 404 | int ret; 405 | 406 | if (ctrl_conn == NULL) { 407 | LOGV("Not connected to wpa_supplicant - \"%s\" command dropped.\n", cmd); 408 | return -1; 409 | } 410 | ret = wpa_ctrl_request(ctrl, cmd, strlen(cmd), reply, reply_len, NULL); 411 | if (ret == -2) { 412 | LOGD("'%s' command timed out.\n", cmd); 413 | return -2; 414 | } else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) { 415 | return -1; 416 | } 417 | if (strncmp(cmd, "PING", 4) == 0) { 418 | reply[*reply_len] = '\0'; 419 | } 420 | return 0; 421 | } 422 | 423 | int wifi_wait_for_event(char *buf, size_t buflen) 424 | { 425 | size_t nread = buflen - 1; 426 | int fd; 427 | fd_set rfds; 428 | int result; 429 | struct timeval tval; 430 | struct timeval *tptr; 431 | 432 | if (monitor_conn == NULL) { 433 | LOGD("Connection closed\n"); 434 | strncpy(buf, WPA_EVENT_TERMINATING " - connection closed", buflen-1); 435 | buf[buflen-1] = '\0'; 436 | return strlen(buf); 437 | } 438 | 439 | result = wpa_ctrl_recv(monitor_conn, buf, &nread); 440 | if (result < 0) { 441 | LOGD("wpa_ctrl_recv failed: %s\n", strerror(errno)); 442 | strncpy(buf, WPA_EVENT_TERMINATING " - recv error", buflen-1); 443 | buf[buflen-1] = '\0'; 444 | return strlen(buf); 445 | } 446 | buf[nread] = '\0'; 447 | /* LOGD("wait_for_event: result=%d nread=%d string=\"%s\"\n", result, nread, buf); */ 448 | /* Check for EOF on the socket */ 449 | if (result == 0 && nread == 0) { 450 | /* Fabricate an event to pass up */ 451 | LOGD("Received EOF on supplicant socket\n"); 452 | strncpy(buf, WPA_EVENT_TERMINATING " - signal 0 received", buflen-1); 453 | buf[buflen-1] = '\0'; 454 | return strlen(buf); 455 | } 456 | /* 457 | * Events strings are in the format 458 | * 459 | * CTRL-EVENT-XXX 460 | * 461 | * where N is the message level in numerical form (0=VERBOSE, 1=DEBUG, 462 | * etc.) and XXX is the event name. The level information is not useful 463 | * to us, so strip it off. 464 | */ 465 | if (buf[0] == '<') { 466 | char *match = strchr(buf, '>'); 467 | if (match != NULL) { 468 | nread -= (match+1-buf); 469 | memmove(buf, match+1, nread+1); 470 | } 471 | } 472 | return nread; 473 | } 474 | 475 | void wifi_close_supplicant_connection() 476 | { 477 | if (ctrl_conn != NULL) { 478 | wpa_ctrl_close(ctrl_conn); 479 | ctrl_conn = NULL; 480 | } 481 | if (monitor_conn != NULL) { 482 | wpa_ctrl_close(monitor_conn); 483 | monitor_conn = NULL; 484 | } 485 | } 486 | 487 | int wifi_command(const char *command, char *reply, size_t *reply_len) 488 | { 489 | return wifi_send_command(ctrl_conn, command, reply, reply_len); 490 | } 491 | -------------------------------------------------------------------------------- /include/hardware_legacy/AudioPolicyManagerBase.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 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | namespace android { 27 | 28 | // ---------------------------------------------------------------------------- 29 | 30 | #define MAX_DEVICE_ADDRESS_LEN 20 31 | // Attenuation applied to STRATEGY_SONIFICATION streams when a headset is connected: 6dB 32 | #define SONIFICATION_HEADSET_VOLUME_FACTOR 0.5 33 | // Min volume for STRATEGY_SONIFICATION streams when limited by music volume: -36dB 34 | #define SONIFICATION_HEADSET_VOLUME_MIN 0.016 35 | // Time in seconds during which we consider that music is still active after a music 36 | // track was stopped - see computeVolume() 37 | #define SONIFICATION_HEADSET_MUSIC_DELAY 5 38 | // Time in milliseconds during witch some streams are muted while the audio path 39 | // is switched 40 | #define MUTE_TIME_MS 2000 41 | 42 | #define NUM_TEST_OUTPUTS 5 43 | 44 | // ---------------------------------------------------------------------------- 45 | // AudioPolicyManagerBase implements audio policy manager behavior common to all platforms. 46 | // Each platform must implement an AudioPolicyManager class derived from AudioPolicyManagerBase 47 | // and override methods for which the platform specific behavior differs from the implementation 48 | // in AudioPolicyManagerBase. Even if no specific behavior is required, the AudioPolicyManager 49 | // class must be implemented as well as the class factory function createAudioPolicyManager() 50 | // and provided in a shared library libaudiopolicy.so. 51 | // ---------------------------------------------------------------------------- 52 | 53 | class AudioPolicyManagerBase: public AudioPolicyInterface 54 | #ifdef AUDIO_POLICY_TEST 55 | , public Thread 56 | #endif //AUDIO_POLICY_TEST 57 | { 58 | 59 | public: 60 | AudioPolicyManagerBase(AudioPolicyClientInterface *clientInterface); 61 | virtual ~AudioPolicyManagerBase(); 62 | 63 | // AudioPolicyInterface 64 | virtual status_t setDeviceConnectionState(AudioSystem::audio_devices device, 65 | AudioSystem::device_connection_state state, 66 | const char *device_address); 67 | virtual AudioSystem::device_connection_state getDeviceConnectionState(AudioSystem::audio_devices device, 68 | const char *device_address); 69 | virtual void setPhoneState(int state); 70 | virtual void setRingerMode(uint32_t mode, uint32_t mask); 71 | virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config); 72 | virtual AudioSystem::forced_config getForceUse(AudioSystem::force_use usage); 73 | virtual void setSystemProperty(const char* property, const char* value); 74 | virtual audio_io_handle_t getOutput(AudioSystem::stream_type stream, 75 | uint32_t samplingRate = 0, 76 | uint32_t format = AudioSystem::FORMAT_DEFAULT, 77 | uint32_t channels = 0, 78 | AudioSystem::output_flags flags = 79 | AudioSystem::OUTPUT_FLAG_INDIRECT); 80 | virtual status_t startOutput(audio_io_handle_t output, 81 | AudioSystem::stream_type stream, 82 | int session = 0); 83 | virtual status_t stopOutput(audio_io_handle_t output, 84 | AudioSystem::stream_type stream, 85 | int session = 0); 86 | virtual void releaseOutput(audio_io_handle_t output); 87 | virtual audio_io_handle_t getInput(int inputSource, 88 | uint32_t samplingRate, 89 | uint32_t format, 90 | uint32_t channels, 91 | AudioSystem::audio_in_acoustics acoustics); 92 | // indicates to the audio policy manager that the input starts being used. 93 | virtual status_t startInput(audio_io_handle_t input); 94 | // indicates to the audio policy manager that the input stops being used. 95 | virtual status_t stopInput(audio_io_handle_t input); 96 | virtual void releaseInput(audio_io_handle_t input); 97 | virtual void initStreamVolume(AudioSystem::stream_type stream, 98 | int indexMin, 99 | int indexMax); 100 | virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream, int index); 101 | virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream, int *index); 102 | 103 | // return the strategy corresponding to a given stream type 104 | virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream); 105 | 106 | virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc); 107 | virtual status_t registerEffect(effect_descriptor_t *desc, 108 | audio_io_handle_t output, 109 | uint32_t strategy, 110 | int session, 111 | int id); 112 | virtual status_t unregisterEffect(int id); 113 | 114 | virtual status_t dump(int fd); 115 | 116 | protected: 117 | 118 | enum routing_strategy { 119 | STRATEGY_MEDIA, 120 | STRATEGY_PHONE, 121 | STRATEGY_SONIFICATION, 122 | STRATEGY_DTMF, 123 | STRATEGY_MEDIA_SONIFICATION, 124 | NUM_STRATEGIES 125 | }; 126 | 127 | // descriptor for audio outputs. Used to maintain current configuration of each opened audio output 128 | // and keep track of the usage of this output by each audio stream type. 129 | class AudioOutputDescriptor 130 | { 131 | public: 132 | AudioOutputDescriptor(); 133 | 134 | status_t dump(int fd); 135 | 136 | uint32_t device(); 137 | void changeRefCount(AudioSystem::stream_type, int delta); 138 | uint32_t refCount(); 139 | uint32_t strategyRefCount(routing_strategy strategy); 140 | bool isUsedByStrategy(routing_strategy strategy) { return (strategyRefCount(strategy) != 0);} 141 | bool isDuplicated() { return (mOutput1 != NULL && mOutput2 != NULL); } 142 | 143 | audio_io_handle_t mId; // output handle 144 | uint32_t mSamplingRate; // 145 | uint32_t mFormat; // 146 | uint32_t mChannels; // output configuration 147 | uint32_t mLatency; // 148 | AudioSystem::output_flags mFlags; // 149 | uint32_t mDevice; // current device this output is routed to 150 | uint32_t mRefCount[AudioSystem::NUM_STREAM_TYPES]; // number of streams of each type using this output 151 | AudioOutputDescriptor *mOutput1; // used by duplicated outputs: first output 152 | AudioOutputDescriptor *mOutput2; // used by duplicated outputs: second output 153 | float mCurVolume[AudioSystem::NUM_STREAM_TYPES]; // current stream volume 154 | int mMuteCount[AudioSystem::NUM_STREAM_TYPES]; // mute request counter 155 | }; 156 | 157 | // descriptor for audio inputs. Used to maintain current configuration of each opened audio input 158 | // and keep track of the usage of this input. 159 | class AudioInputDescriptor 160 | { 161 | public: 162 | AudioInputDescriptor(); 163 | 164 | status_t dump(int fd); 165 | 166 | uint32_t mSamplingRate; // 167 | uint32_t mFormat; // input configuration 168 | uint32_t mChannels; // 169 | AudioSystem::audio_in_acoustics mAcoustics; // 170 | uint32_t mDevice; // current device this input is routed to 171 | uint32_t mRefCount; // number of AudioRecord clients using this output 172 | int mInputSource; // input source selected by application (mediarecorder.h) 173 | }; 174 | 175 | // stream descriptor used for volume control 176 | class StreamDescriptor 177 | { 178 | public: 179 | StreamDescriptor() 180 | : mIndexMin(0), mIndexMax(1), mIndexCur(1), mCanBeMuted(true) {} 181 | 182 | void dump(char* buffer, size_t size); 183 | 184 | int mIndexMin; // min volume index 185 | int mIndexMax; // max volume index 186 | int mIndexCur; // current volume index 187 | bool mCanBeMuted; // true is the stream can be muted 188 | }; 189 | 190 | // stream descriptor used for volume control 191 | class EffectDescriptor 192 | { 193 | public: 194 | 195 | status_t dump(int fd); 196 | 197 | int mOutput; // output the effect is attached to 198 | routing_strategy mStrategy; // routing strategy the effect is associated to 199 | int mSession; // audio session the effect is on 200 | effect_descriptor_t mDesc; // effect descriptor 201 | }; 202 | 203 | void addOutput(audio_io_handle_t id, AudioOutputDescriptor *outputDesc); 204 | 205 | // return the strategy corresponding to a given stream type 206 | static routing_strategy getStrategy(AudioSystem::stream_type stream); 207 | // return appropriate device for streams handled by the specified strategy according to current 208 | // phone state, connected devices... 209 | // if fromCache is true, the device is returned from mDeviceForStrategy[], otherwise it is determined 210 | // by current state (device connected, phone state, force use, a2dp output...) 211 | // This allows to: 212 | // 1 speed up process when the state is stable (when starting or stopping an output) 213 | // 2 access to either current device selection (fromCache == true) or 214 | // "future" device selection (fromCache == false) when called from a context 215 | // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND 216 | // before updateDeviceForStrategy() is called. 217 | virtual uint32_t getDeviceForStrategy(routing_strategy strategy, bool fromCache = true); 218 | // change the route of the specified output 219 | void setOutputDevice(audio_io_handle_t output, uint32_t device, bool force = false, int delayMs = 0); 220 | // select input device corresponding to requested audio source 221 | virtual uint32_t getDeviceForInputSource(int inputSource); 222 | // return io handle of active input or 0 if no input is active 223 | audio_io_handle_t getActiveInput(); 224 | // compute the actual volume for a given stream according to the requested index and a particular 225 | // device 226 | virtual float computeVolume(int stream, int index, audio_io_handle_t output, uint32_t device); 227 | // check that volume change is permitted, compute and send new volume to audio hardware 228 | status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, uint32_t device, int delayMs = 0, bool force = false); 229 | // apply all stream volumes to the specified output and device 230 | void applyStreamVolumes(audio_io_handle_t output, uint32_t device, int delayMs = 0); 231 | // Mute or unmute all streams handled by the specified strategy on the specified output 232 | void setStrategyMute(routing_strategy strategy, bool on, audio_io_handle_t output, int delayMs = 0); 233 | // Mute or unmute the stream on the specified output 234 | void setStreamMute(int stream, bool on, audio_io_handle_t output, int delayMs = 0); 235 | // handle special cases for sonification strategy while in call: mute streams or replace by 236 | // a special tone in the device used for communication 237 | void handleIncallSonification(int stream, bool starting, bool stateChange); 238 | // true is current platform implements a back microphone 239 | virtual bool hasBackMicrophone() const { return false; } 240 | 241 | #ifdef WITH_A2DP 242 | // true is current platform supports suplication of notifications and ringtones over A2DP output 243 | virtual bool a2dpUsedForSonification() const { return true; } 244 | status_t handleA2dpConnection(AudioSystem::audio_devices device, 245 | const char *device_address); 246 | status_t handleA2dpDisconnection(AudioSystem::audio_devices device, 247 | const char *device_address); 248 | void closeA2dpOutputs(); 249 | // checks and if necessary changes output (a2dp, duplicated or hardware) used for all strategies. 250 | // must be called every time a condition that affects the output choice for a given strategy is 251 | // changed: connected device, phone state, force use... 252 | // Must be called before updateDeviceForStrategy() 253 | void checkOutputForStrategy(routing_strategy strategy); 254 | // Same as checkOutputForStrategy() but for a all strategies in order of priority 255 | void checkOutputForAllStrategies(); 256 | 257 | #endif 258 | // selects the most appropriate device on output for current state 259 | // must be called every time a condition that affects the device choice for a given output is 260 | // changed: connected device, phone state, force use, output start, output stop.. 261 | // see getDeviceForStrategy() for the use of fromCache parameter 262 | uint32_t getNewDevice(audio_io_handle_t output, bool fromCache = true); 263 | // updates cache of device used by all strategies (mDeviceForStrategy[]) 264 | // must be called every time a condition that affects the device choice for a given strategy is 265 | // changed: connected device, phone state, force use... 266 | // cached values are used by getDeviceForStrategy() if parameter fromCache is true. 267 | // Must be called after checkOutputForAllStrategies() 268 | void updateDeviceForStrategy(); 269 | // true if current platform requires a specific output to be opened for this particular 270 | // set of parameters. This function is called by getOutput() and is implemented by platform 271 | // specific audio policy manager. 272 | virtual bool needsDirectOuput(AudioSystem::stream_type stream, 273 | uint32_t samplingRate, 274 | uint32_t format, 275 | uint32_t channels, 276 | AudioSystem::output_flags flags, 277 | uint32_t device); 278 | virtual uint32_t getMaxEffectsCpuLoad(); 279 | virtual uint32_t getMaxEffectsMemory(); 280 | #ifdef AUDIO_POLICY_TEST 281 | virtual bool threadLoop(); 282 | void exit(); 283 | int testOutputIndex(audio_io_handle_t output); 284 | #endif //AUDIO_POLICY_TEST 285 | 286 | AudioPolicyClientInterface *mpClientInterface; // audio policy client interface 287 | audio_io_handle_t mHardwareOutput; // hardware output handler 288 | audio_io_handle_t mA2dpOutput; // A2DP output handler 289 | audio_io_handle_t mDuplicatedOutput; // duplicated output handler: outputs to hardware and A2DP. 290 | 291 | KeyedVector mOutputs; // list of output descriptors 292 | KeyedVector mInputs; // list of input descriptors 293 | uint32_t mAvailableOutputDevices; // bit field of all available output devices 294 | uint32_t mAvailableInputDevices; // bit field of all available input devices 295 | int mPhoneState; // current phone state 296 | uint32_t mRingerMode; // current ringer mode 297 | AudioSystem::forced_config mForceUse[AudioSystem::NUM_FORCE_USE]; // current forced use configuration 298 | 299 | StreamDescriptor mStreams[AudioSystem::NUM_STREAM_TYPES]; // stream descriptors for volume control 300 | String8 mA2dpDeviceAddress; // A2DP device MAC address 301 | String8 mScoDeviceAddress; // SCO device MAC address 302 | nsecs_t mMusicStopTime; // time when last music stream was stopped 303 | bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected 304 | uint32_t mDeviceForStrategy[NUM_STRATEGIES]; 305 | 306 | // Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units 307 | static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000; 308 | // Maximum memory allocated to audio effects in KB 309 | static const uint32_t MAX_EFFECTS_MEMORY = 512; 310 | uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects 311 | uint32_t mTotalEffectsMemory; // current memory used by effects 312 | KeyedVector mEffects; // list of registered audio effects 313 | 314 | #ifdef AUDIO_POLICY_TEST 315 | Mutex mLock; 316 | Condition mWaitWorkCV; 317 | 318 | int mCurOutput; 319 | bool mDirectOutput; 320 | audio_io_handle_t mTestOutputs[NUM_TEST_OUTPUTS]; 321 | int mTestInput; 322 | uint32_t mTestDevice; 323 | uint32_t mTestSamplingRate; 324 | uint32_t mTestFormat; 325 | uint32_t mTestChannels; 326 | uint32_t mTestLatencyMs; 327 | #endif //AUDIO_POLICY_TEST 328 | }; 329 | 330 | }; 331 | --------------------------------------------------------------------------------