├── 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 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include "media/AudioSystem.h" 30 | 31 | 32 | namespace android { 33 | 34 | // ---------------------------------------------------------------------------- 35 | 36 | /** 37 | * AudioStreamOut is the abstraction interface for the audio output hardware. 38 | * 39 | * It provides information about various properties of the audio output hardware driver. 40 | */ 41 | class AudioStreamOut { 42 | public: 43 | virtual ~AudioStreamOut() = 0; 44 | 45 | /** return audio sampling rate in hz - eg. 44100 */ 46 | virtual uint32_t sampleRate() const = 0; 47 | 48 | /** returns size of output buffer - eg. 4800 */ 49 | virtual size_t bufferSize() const = 0; 50 | 51 | /** 52 | * returns the output channel nask 53 | */ 54 | virtual uint32_t channels() const = 0; 55 | 56 | /** 57 | * return audio format in 8bit or 16bit PCM format - 58 | * eg. AudioSystem:PCM_16_BIT 59 | */ 60 | virtual int format() const = 0; 61 | 62 | /** 63 | * return the frame size (number of bytes per sample). 64 | */ 65 | uint32_t frameSize() const { return AudioSystem::popCount(channels())*((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } 66 | 67 | /** 68 | * return the audio hardware driver latency in milli seconds. 69 | */ 70 | virtual uint32_t latency() const = 0; 71 | 72 | /** 73 | * Use this method in situations where audio mixing is done in the 74 | * hardware. This method serves as a direct interface with hardware, 75 | * allowing you to directly set the volume as apposed to via the framework. 76 | * This method might produce multiple PCM outputs or hardware accelerated 77 | * codecs, such as MP3 or AAC. 78 | */ 79 | virtual status_t setVolume(float left, float right) = 0; 80 | 81 | /** write audio buffer to driver. Returns number of bytes written */ 82 | virtual ssize_t write(const void* buffer, size_t bytes) = 0; 83 | 84 | /** 85 | * Put the audio hardware output into standby mode. Returns 86 | * status based on include/utils/Errors.h 87 | */ 88 | virtual status_t standby() = 0; 89 | 90 | /** dump the state of the audio output device */ 91 | virtual status_t dump(int fd, const Vector& args) = 0; 92 | 93 | // set/get audio output parameters. The function accepts a list of parameters 94 | // key value pairs in the form: key1=value1;key2=value2;... 95 | // Some keys are reserved for standard parameters (See AudioParameter class). 96 | // If the implementation does not accept a parameter change while the output is 97 | // active but the parameter is acceptable otherwise, it must return INVALID_OPERATION. 98 | // The audio flinger will put the output in standby and then change the parameter value. 99 | virtual status_t setParameters(const String8& keyValuePairs) = 0; 100 | virtual String8 getParameters(const String8& keys) = 0; 101 | 102 | // return the number of audio frames written by the audio dsp to DAC since 103 | // the output has exited standby 104 | virtual status_t getRenderPosition(uint32_t *dspFrames) = 0; 105 | }; 106 | 107 | /** 108 | * AudioStreamIn is the abstraction interface for the audio input hardware. 109 | * 110 | * It defines the various properties of the audio hardware input driver. 111 | */ 112 | class AudioStreamIn { 113 | public: 114 | virtual ~AudioStreamIn() = 0; 115 | 116 | /** return audio sampling rate in hz - eg. 44100 */ 117 | virtual uint32_t sampleRate() const = 0; 118 | 119 | /** return the input buffer size allowed by audio driver */ 120 | virtual size_t bufferSize() const = 0; 121 | 122 | /** return input channel mask */ 123 | virtual uint32_t channels() const = 0; 124 | 125 | /** 126 | * return audio format in 8bit or 16bit PCM format - 127 | * eg. AudioSystem:PCM_16_BIT 128 | */ 129 | virtual int format() const = 0; 130 | 131 | /** 132 | * return the frame size (number of bytes per sample). 133 | */ 134 | uint32_t frameSize() const { return AudioSystem::popCount(channels())*((format()==AudioSystem::PCM_16_BIT)?sizeof(int16_t):sizeof(int8_t)); } 135 | 136 | /** set the input gain for the audio driver. This method is for 137 | * for future use */ 138 | virtual status_t setGain(float gain) = 0; 139 | 140 | /** read audio buffer in from audio driver */ 141 | virtual ssize_t read(void* buffer, ssize_t bytes) = 0; 142 | 143 | /** dump the state of the audio input device */ 144 | virtual status_t dump(int fd, const Vector& args) = 0; 145 | 146 | /** 147 | * Put the audio hardware input into standby mode. Returns 148 | * status based on include/utils/Errors.h 149 | */ 150 | virtual status_t standby() = 0; 151 | 152 | // set/get audio input parameters. The function accepts a list of parameters 153 | // key value pairs in the form: key1=value1;key2=value2;... 154 | // Some keys are reserved for standard parameters (See AudioParameter class). 155 | // If the implementation does not accept a parameter change while the output is 156 | // active but the parameter is acceptable otherwise, it must return INVALID_OPERATION. 157 | // The audio flinger will put the input in standby and then change the parameter value. 158 | virtual status_t setParameters(const String8& keyValuePairs) = 0; 159 | virtual String8 getParameters(const String8& keys) = 0; 160 | 161 | 162 | // Return the amount of input frames lost in the audio driver since the last call of this function. 163 | // Audio driver is expected to reset the value to 0 and restart counting upon returning the current value by this function call. 164 | // Such loss typically occurs when the user space process is blocked longer than the capacity of audio driver buffers. 165 | // Unit: the number of input audio frames 166 | virtual unsigned int getInputFramesLost() const = 0; 167 | 168 | }; 169 | 170 | /** 171 | * AudioHardwareInterface.h defines the interface to the audio hardware abstraction layer. 172 | * 173 | * The interface supports setting and getting parameters, selecting audio routing 174 | * paths, and defining input and output streams. 175 | * 176 | * AudioFlinger initializes the audio hardware and immediately opens an output stream. 177 | * You can set Audio routing to output to handset, speaker, Bluetooth, or a headset. 178 | * 179 | * The audio input stream is initialized when AudioFlinger is called to carry out 180 | * a record operation. 181 | */ 182 | class AudioHardwareInterface 183 | { 184 | public: 185 | virtual ~AudioHardwareInterface() {} 186 | 187 | /** 188 | * check to see if the audio hardware interface has been initialized. 189 | * return status based on values defined in include/utils/Errors.h 190 | */ 191 | virtual status_t initCheck() = 0; 192 | 193 | /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */ 194 | virtual status_t setVoiceVolume(float volume) = 0; 195 | 196 | /** 197 | * set the audio volume for all audio activities other than voice call. 198 | * Range between 0.0 and 1.0. If any value other than NO_ERROR is returned, 199 | * the software mixer will emulate this capability. 200 | */ 201 | virtual status_t setMasterVolume(float volume) = 0; 202 | 203 | /** 204 | * setMode is called when the audio mode changes. NORMAL mode is for 205 | * standard audio playback, RINGTONE when a ringtone is playing, and IN_CALL 206 | * when a call is in progress. 207 | */ 208 | virtual status_t setMode(int mode) = 0; 209 | 210 | // mic mute 211 | virtual status_t setMicMute(bool state) = 0; 212 | virtual status_t getMicMute(bool* state) = 0; 213 | 214 | // set/get global audio parameters 215 | virtual status_t setParameters(const String8& keyValuePairs) = 0; 216 | virtual String8 getParameters(const String8& keys) = 0; 217 | 218 | // Returns audio input buffer size according to parameters passed or 0 if one of the 219 | // parameters is not supported 220 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount) = 0; 221 | 222 | /** This method creates and opens the audio hardware output stream */ 223 | virtual AudioStreamOut* openOutputStream( 224 | uint32_t devices, 225 | int *format=0, 226 | uint32_t *channels=0, 227 | uint32_t *sampleRate=0, 228 | status_t *status=0) = 0; 229 | virtual void closeOutputStream(AudioStreamOut* out) = 0; 230 | /** This method creates and opens the audio hardware input stream */ 231 | virtual AudioStreamIn* openInputStream( 232 | uint32_t devices, 233 | int *format, 234 | uint32_t *channels, 235 | uint32_t *sampleRate, 236 | status_t *status, 237 | AudioSystem::audio_in_acoustics acoustics) = 0; 238 | virtual void closeInputStream(AudioStreamIn* in) = 0; 239 | 240 | /**This method dumps the state of the audio hardware */ 241 | virtual status_t dumpState(int fd, const Vector& args) = 0; 242 | 243 | static AudioHardwareInterface* create(); 244 | 245 | protected: 246 | 247 | virtual status_t dump(int fd, const Vector& args) = 0; 248 | }; 249 | 250 | // ---------------------------------------------------------------------------- 251 | 252 | extern "C" AudioHardwareInterface* createAudioHardware(void); 253 | 254 | }; // namespace android 255 | 256 | #endif // ANDROID_AUDIO_HARDWARE_INTERFACE_H 257 | -------------------------------------------------------------------------------- /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 | #include 21 | #include 22 | #include 23 | 24 | namespace android { 25 | 26 | 27 | // ---------------------------------------------------------------------------- 28 | 29 | // The AudioPolicyInterface and AudioPolicyClientInterface classes define the communication interfaces 30 | // between the platform specific audio policy manager and Android generic audio policy manager. 31 | // The platform specific audio policy manager must implement methods of the AudioPolicyInterface class. 32 | // This implementation makes use of the AudioPolicyClientInterface to control the activity and 33 | // configuration of audio input and output streams. 34 | // 35 | // The platform specific audio policy manager is in charge of the audio routing and volume control 36 | // policies for a given platform. 37 | // The main roles of this module are: 38 | // - keep track of current system state (removable device connections, phone state, user requests...). 39 | // System state changes and user actions are notified to audio policy manager with methods of the AudioPolicyInterface. 40 | // - process getOutput() queries received when AudioTrack objects are created: Those queries 41 | // return a handler on an output that has been selected, configured and opened by the audio policy manager and that 42 | // must be used by the AudioTrack when registering to the AudioFlinger with the createTrack() method. 43 | // When the AudioTrack object is released, a putOutput() query is received and the audio policy manager can decide 44 | // to close or reconfigure the output depending on other streams using this output and current system state. 45 | // - similarly process getInput() and putInput() queries received from AudioRecord objects and configure audio inputs. 46 | // - process volume control requests: the stream volume is converted from an index value (received from UI) to a float value 47 | // applicable to each output as a function of platform specific settings and current output route (destination device). It 48 | // also make sure that streams are not muted if not allowed (e.g. camera shutter sound in some countries). 49 | // 50 | // The platform specific audio policy manager is provided as a shared library by platform vendors (as for libaudio.so) 51 | // and is linked with libaudioflinger.so 52 | 53 | 54 | // Audio Policy Manager Interface 55 | class AudioPolicyInterface 56 | { 57 | 58 | public: 59 | virtual ~AudioPolicyInterface() {} 60 | // 61 | // configuration functions 62 | // 63 | 64 | // indicate a change in device connection status 65 | virtual status_t setDeviceConnectionState(AudioSystem::audio_devices device, 66 | AudioSystem::device_connection_state state, 67 | const char *device_address) = 0; 68 | // retreive a device connection status 69 | virtual AudioSystem::device_connection_state getDeviceConnectionState(AudioSystem::audio_devices device, 70 | const char *device_address) = 0; 71 | // indicate a change in phone state. Valid phones states are defined by AudioSystem::audio_mode 72 | virtual void setPhoneState(int state) = 0; 73 | // indicate a change in ringer mode 74 | virtual void setRingerMode(uint32_t mode, uint32_t mask) = 0; 75 | // force using a specific device category for the specified usage 76 | virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config) = 0; 77 | // retreive current device category forced for a given usage 78 | virtual AudioSystem::forced_config getForceUse(AudioSystem::force_use usage) = 0; 79 | // set a system property (e.g. camera sound always audible) 80 | virtual void setSystemProperty(const char* property, const char* value) = 0; 81 | 82 | 83 | // 84 | // Audio routing query functions 85 | // 86 | 87 | // request an output appriate for playback of the supplied stream type and parameters 88 | virtual audio_io_handle_t getOutput(AudioSystem::stream_type stream, 89 | uint32_t samplingRate = 0, 90 | uint32_t format = AudioSystem::FORMAT_DEFAULT, 91 | uint32_t channels = 0, 92 | AudioSystem::output_flags flags = AudioSystem::OUTPUT_FLAG_INDIRECT) = 0; 93 | // indicates to the audio policy manager that the output starts being used by corresponding stream. 94 | virtual status_t startOutput(audio_io_handle_t output, 95 | AudioSystem::stream_type stream, 96 | int session = 0) = 0; 97 | // indicates to the audio policy manager that the output stops being used by corresponding stream. 98 | virtual status_t stopOutput(audio_io_handle_t output, 99 | AudioSystem::stream_type stream, 100 | int session = 0) = 0; 101 | // releases the output. 102 | virtual void releaseOutput(audio_io_handle_t output) = 0; 103 | 104 | // request an input appriate for record from the supplied device with supplied parameters. 105 | virtual audio_io_handle_t getInput(int inputSource, 106 | uint32_t samplingRate = 0, 107 | uint32_t Format = AudioSystem::FORMAT_DEFAULT, 108 | uint32_t channels = 0, 109 | AudioSystem::audio_in_acoustics acoustics = (AudioSystem::audio_in_acoustics)0) = 0; 110 | // indicates to the audio policy manager that the input starts being used. 111 | virtual status_t startInput(audio_io_handle_t input) = 0; 112 | // indicates to the audio policy manager that the input stops being used. 113 | virtual status_t stopInput(audio_io_handle_t input) = 0; 114 | // releases the input. 115 | virtual void releaseInput(audio_io_handle_t input) = 0; 116 | 117 | // 118 | // volume control functions 119 | // 120 | 121 | // initialises stream volume conversion parameters by specifying volume index range. 122 | virtual void initStreamVolume(AudioSystem::stream_type stream, 123 | int indexMin, 124 | int indexMax) = 0; 125 | 126 | // sets the new stream volume at a level corresponding to the supplied index 127 | virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream, int index) = 0; 128 | // retreive current volume index for the specified stream 129 | virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream, int *index) = 0; 130 | 131 | // return the strategy corresponding to a given stream type 132 | virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream) = 0; 133 | 134 | // Audio effect management 135 | virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc) = 0; 136 | virtual status_t registerEffect(effect_descriptor_t *desc, 137 | audio_io_handle_t output, 138 | uint32_t strategy, 139 | int session, 140 | int id) = 0; 141 | virtual status_t unregisterEffect(int id) = 0; 142 | 143 | //dump state 144 | virtual status_t dump(int fd) = 0; 145 | }; 146 | 147 | 148 | // Audio Policy client Interface 149 | class AudioPolicyClientInterface 150 | { 151 | public: 152 | virtual ~AudioPolicyClientInterface() {} 153 | 154 | // 155 | // Audio output Control functions 156 | // 157 | 158 | // opens an audio output with the requested parameters. The parameter values can indicate to use the default values 159 | // in case the audio policy manager has no specific requirements for the output being opened. 160 | // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream. 161 | // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly. 162 | virtual audio_io_handle_t openOutput(uint32_t *pDevices, 163 | uint32_t *pSamplingRate, 164 | uint32_t *pFormat, 165 | uint32_t *pChannels, 166 | uint32_t *pLatencyMs, 167 | AudioSystem::output_flags flags) = 0; 168 | // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by 169 | // a special mixer thread in the AudioFlinger. 170 | virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2) = 0; 171 | // closes the output stream 172 | virtual status_t closeOutput(audio_io_handle_t output) = 0; 173 | // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in 174 | // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded. 175 | virtual status_t suspendOutput(audio_io_handle_t output) = 0; 176 | // restores a suspended output. 177 | virtual status_t restoreOutput(audio_io_handle_t output) = 0; 178 | 179 | // 180 | // Audio input Control functions 181 | // 182 | 183 | // opens an audio input 184 | virtual audio_io_handle_t openInput(uint32_t *pDevices, 185 | uint32_t *pSamplingRate, 186 | uint32_t *pFormat, 187 | uint32_t *pChannels, 188 | uint32_t acoustics) = 0; 189 | // closes an audio input 190 | virtual status_t closeInput(audio_io_handle_t input) = 0; 191 | // 192 | // misc control functions 193 | // 194 | 195 | // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes 196 | // for each output (destination device) it is attached to. 197 | virtual status_t setStreamVolume(AudioSystem::stream_type stream, float volume, audio_io_handle_t output, int delayMs = 0) = 0; 198 | 199 | // reroute a given stream type to the specified output 200 | virtual status_t setStreamOutput(AudioSystem::stream_type stream, audio_io_handle_t output) = 0; 201 | 202 | // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface. 203 | virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0) = 0; 204 | // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager. 205 | virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) = 0; 206 | 207 | // request the playback of a tone on the specified stream: used for instance to replace notification sounds when playing 208 | // over a telephony device during a phone call. 209 | virtual status_t startTone(ToneGenerator::tone_type tone, AudioSystem::stream_type stream) = 0; 210 | virtual status_t stopTone() = 0; 211 | 212 | // set down link audio volume. 213 | virtual status_t setVoiceVolume(float volume, int delayMs = 0) = 0; 214 | 215 | // move effect to the specified output 216 | virtual status_t moveEffects(int session, 217 | audio_io_handle_t srcOutput, 218 | audio_io_handle_t dstOutput) = 0; 219 | 220 | }; 221 | 222 | extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface); 223 | extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface); 224 | 225 | 226 | }; // namespace android 227 | 228 | #endif // ANDROID_AUDIOPOLICYINTERFACE_H 229 | -------------------------------------------------------------------------------- /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 daemon_cmd[PROPERTY_VALUE_MAX]; 275 | char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; 276 | int count = 200; /* wait at most 20 seconds for completion */ 277 | #ifdef HAVE_LIBC_SYSTEM_PROPERTIES 278 | const prop_info *pi; 279 | unsigned serial = 0; 280 | #endif 281 | 282 | /* Check whether already running */ 283 | if (property_get(SUPP_PROP_NAME, supp_status, NULL) 284 | && strcmp(supp_status, "running") == 0) { 285 | return 0; 286 | } 287 | 288 | /* Before starting the daemon, make sure its config file exists */ 289 | if (ensure_config_file_exists() < 0) { 290 | LOGE("Wi-Fi will not be enabled"); 291 | return -1; 292 | } 293 | 294 | /* Clear out any stale socket files that might be left over. */ 295 | wpa_ctrl_cleanup(); 296 | 297 | #ifdef HAVE_LIBC_SYSTEM_PROPERTIES 298 | /* 299 | * Get a reference to the status property, so we can distinguish 300 | * the case where it goes stopped => running => stopped (i.e., 301 | * it start up, but fails right away) from the case in which 302 | * it starts in the stopped state and never manages to start 303 | * running at all. 304 | */ 305 | pi = __system_property_find(SUPP_PROP_NAME); 306 | if (pi != NULL) { 307 | serial = pi->serial; 308 | } 309 | #endif 310 | property_get("wifi.interface", iface, WIFI_TEST_INTERFACE); 311 | snprintf(daemon_cmd, PROPERTY_VALUE_MAX, "%s:-i%s", SUPPLICANT_NAME, iface); 312 | property_set("ctl.start", daemon_cmd); 313 | sched_yield(); 314 | 315 | while (count-- > 0) { 316 | #ifdef HAVE_LIBC_SYSTEM_PROPERTIES 317 | if (pi == NULL) { 318 | pi = __system_property_find(SUPP_PROP_NAME); 319 | } 320 | if (pi != NULL) { 321 | __system_property_read(pi, NULL, supp_status); 322 | if (strcmp(supp_status, "running") == 0) { 323 | return 0; 324 | } else if (pi->serial != serial && 325 | strcmp(supp_status, "stopped") == 0) { 326 | return -1; 327 | } 328 | } 329 | #else 330 | if (property_get(SUPP_PROP_NAME, supp_status, NULL)) { 331 | if (strcmp(supp_status, "running") == 0) 332 | return 0; 333 | } 334 | #endif 335 | usleep(100000); 336 | } 337 | return -1; 338 | } 339 | 340 | int wifi_stop_supplicant() 341 | { 342 | char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; 343 | int count = 50; /* wait at most 5 seconds for completion */ 344 | 345 | /* Check whether supplicant already stopped */ 346 | if (property_get(SUPP_PROP_NAME, supp_status, NULL) 347 | && strcmp(supp_status, "stopped") == 0) { 348 | return 0; 349 | } 350 | 351 | property_set("ctl.stop", SUPPLICANT_NAME); 352 | sched_yield(); 353 | 354 | while (count-- > 0) { 355 | if (property_get(SUPP_PROP_NAME, supp_status, NULL)) { 356 | if (strcmp(supp_status, "stopped") == 0) 357 | return 0; 358 | } 359 | usleep(100000); 360 | } 361 | return -1; 362 | } 363 | 364 | int wifi_connect_to_supplicant() 365 | { 366 | char ifname[256]; 367 | char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; 368 | 369 | /* Make sure supplicant is running */ 370 | if (!property_get(SUPP_PROP_NAME, supp_status, NULL) 371 | || strcmp(supp_status, "running") != 0) { 372 | LOGE("Supplicant not running, cannot connect"); 373 | return -1; 374 | } 375 | 376 | if (access(IFACE_DIR, F_OK) == 0) { 377 | snprintf(ifname, sizeof(ifname), "%s/%s", IFACE_DIR, iface); 378 | } else { 379 | strlcpy(ifname, iface, sizeof(ifname)); 380 | } 381 | 382 | ctrl_conn = wpa_ctrl_open(ifname); 383 | if (ctrl_conn == NULL) { 384 | LOGE("Unable to open connection to supplicant on \"%s\": %s", 385 | ifname, strerror(errno)); 386 | return -1; 387 | } 388 | monitor_conn = wpa_ctrl_open(ifname); 389 | if (monitor_conn == NULL) { 390 | wpa_ctrl_close(ctrl_conn); 391 | ctrl_conn = NULL; 392 | return -1; 393 | } 394 | if (wpa_ctrl_attach(monitor_conn) != 0) { 395 | wpa_ctrl_close(monitor_conn); 396 | wpa_ctrl_close(ctrl_conn); 397 | ctrl_conn = monitor_conn = NULL; 398 | return -1; 399 | } 400 | return 0; 401 | } 402 | 403 | int wifi_send_command(struct wpa_ctrl *ctrl, const char *cmd, char *reply, size_t *reply_len) 404 | { 405 | int ret; 406 | 407 | if (ctrl_conn == NULL) { 408 | LOGV("Not connected to wpa_supplicant - \"%s\" command dropped.\n", cmd); 409 | return -1; 410 | } 411 | ret = wpa_ctrl_request(ctrl, cmd, strlen(cmd), reply, reply_len, NULL); 412 | if (ret == -2) { 413 | LOGD("'%s' command timed out.\n", cmd); 414 | return -2; 415 | } else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) { 416 | return -1; 417 | } 418 | if (strncmp(cmd, "PING", 4) == 0) { 419 | reply[*reply_len] = '\0'; 420 | } 421 | return 0; 422 | } 423 | 424 | int wifi_wait_for_event(char *buf, size_t buflen) 425 | { 426 | size_t nread = buflen - 1; 427 | int fd; 428 | fd_set rfds; 429 | int result; 430 | struct timeval tval; 431 | struct timeval *tptr; 432 | 433 | if (monitor_conn == NULL) { 434 | LOGD("Connection closed\n"); 435 | strncpy(buf, WPA_EVENT_TERMINATING " - connection closed", buflen-1); 436 | buf[buflen-1] = '\0'; 437 | return strlen(buf); 438 | } 439 | 440 | result = wpa_ctrl_recv(monitor_conn, buf, &nread); 441 | if (result < 0) { 442 | LOGD("wpa_ctrl_recv failed: %s\n", strerror(errno)); 443 | strncpy(buf, WPA_EVENT_TERMINATING " - recv error", buflen-1); 444 | buf[buflen-1] = '\0'; 445 | return strlen(buf); 446 | } 447 | buf[nread] = '\0'; 448 | /* LOGD("wait_for_event: result=%d nread=%d string=\"%s\"\n", result, nread, buf); */ 449 | /* Check for EOF on the socket */ 450 | if (result == 0 && nread == 0) { 451 | /* Fabricate an event to pass up */ 452 | LOGD("Received EOF on supplicant socket\n"); 453 | strncpy(buf, WPA_EVENT_TERMINATING " - signal 0 received", buflen-1); 454 | buf[buflen-1] = '\0'; 455 | return strlen(buf); 456 | } 457 | /* 458 | * Events strings are in the format 459 | * 460 | * CTRL-EVENT-XXX 461 | * 462 | * where N is the message level in numerical form (0=VERBOSE, 1=DEBUG, 463 | * etc.) and XXX is the event name. The level information is not useful 464 | * to us, so strip it off. 465 | */ 466 | if (buf[0] == '<') { 467 | char *match = strchr(buf, '>'); 468 | if (match != NULL) { 469 | nread -= (match+1-buf); 470 | memmove(buf, match+1, nread+1); 471 | } 472 | } 473 | return nread; 474 | } 475 | 476 | void wifi_close_supplicant_connection() 477 | { 478 | if (ctrl_conn != NULL) { 479 | wpa_ctrl_close(ctrl_conn); 480 | ctrl_conn = NULL; 481 | } 482 | if (monitor_conn != NULL) { 483 | wpa_ctrl_close(monitor_conn); 484 | monitor_conn = NULL; 485 | } 486 | } 487 | 488 | int wifi_command(const char *command, char *reply, size_t *reply_len) 489 | { 490 | return wifi_send_command(ctrl_conn, command, reply, reply_len); 491 | } 492 | -------------------------------------------------------------------------------- /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 | NUM_STRATEGIES 124 | }; 125 | 126 | // descriptor for audio outputs. Used to maintain current configuration of each opened audio output 127 | // and keep track of the usage of this output by each audio stream type. 128 | class AudioOutputDescriptor 129 | { 130 | public: 131 | AudioOutputDescriptor(); 132 | 133 | status_t dump(int fd); 134 | 135 | uint32_t device(); 136 | void changeRefCount(AudioSystem::stream_type, int delta); 137 | uint32_t refCount(); 138 | uint32_t strategyRefCount(routing_strategy strategy); 139 | bool isUsedByStrategy(routing_strategy strategy) { return (strategyRefCount(strategy) != 0);} 140 | bool isDuplicated() { return (mOutput1 != NULL && mOutput2 != NULL); } 141 | 142 | audio_io_handle_t mId; // output handle 143 | uint32_t mSamplingRate; // 144 | uint32_t mFormat; // 145 | uint32_t mChannels; // output configuration 146 | uint32_t mLatency; // 147 | AudioSystem::output_flags mFlags; // 148 | uint32_t mDevice; // current device this output is routed to 149 | uint32_t mRefCount[AudioSystem::NUM_STREAM_TYPES]; // number of streams of each type using this output 150 | AudioOutputDescriptor *mOutput1; // used by duplicated outputs: first output 151 | AudioOutputDescriptor *mOutput2; // used by duplicated outputs: second output 152 | float mCurVolume[AudioSystem::NUM_STREAM_TYPES]; // current stream volume 153 | int mMuteCount[AudioSystem::NUM_STREAM_TYPES]; // mute request counter 154 | }; 155 | 156 | // descriptor for audio inputs. Used to maintain current configuration of each opened audio input 157 | // and keep track of the usage of this input. 158 | class AudioInputDescriptor 159 | { 160 | public: 161 | AudioInputDescriptor(); 162 | 163 | status_t dump(int fd); 164 | 165 | uint32_t mSamplingRate; // 166 | uint32_t mFormat; // input configuration 167 | uint32_t mChannels; // 168 | AudioSystem::audio_in_acoustics mAcoustics; // 169 | uint32_t mDevice; // current device this input is routed to 170 | uint32_t mRefCount; // number of AudioRecord clients using this output 171 | int mInputSource; // input source selected by application (mediarecorder.h) 172 | }; 173 | 174 | // stream descriptor used for volume control 175 | class StreamDescriptor 176 | { 177 | public: 178 | StreamDescriptor() 179 | : mIndexMin(0), mIndexMax(1), mIndexCur(1), mCanBeMuted(true) {} 180 | 181 | void dump(char* buffer, size_t size); 182 | 183 | int mIndexMin; // min volume index 184 | int mIndexMax; // max volume index 185 | int mIndexCur; // current volume index 186 | bool mCanBeMuted; // true is the stream can be muted 187 | }; 188 | 189 | // stream descriptor used for volume control 190 | class EffectDescriptor 191 | { 192 | public: 193 | 194 | status_t dump(int fd); 195 | 196 | int mOutput; // output the effect is attached to 197 | routing_strategy mStrategy; // routing strategy the effect is associated to 198 | int mSession; // audio session the effect is on 199 | effect_descriptor_t mDesc; // effect descriptor 200 | }; 201 | 202 | void addOutput(audio_io_handle_t id, AudioOutputDescriptor *outputDesc); 203 | 204 | // return the strategy corresponding to a given stream type 205 | static routing_strategy getStrategy(AudioSystem::stream_type stream); 206 | // return appropriate device for streams handled by the specified strategy according to current 207 | // phone state, connected devices... 208 | // if fromCache is true, the device is returned from mDeviceForStrategy[], otherwise it is determined 209 | // by current state (device connected, phone state, force use, a2dp output...) 210 | // This allows to: 211 | // 1 speed up process when the state is stable (when starting or stopping an output) 212 | // 2 access to either current device selection (fromCache == true) or 213 | // "future" device selection (fromCache == false) when called from a context 214 | // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND 215 | // before updateDeviceForStrategy() is called. 216 | virtual uint32_t getDeviceForStrategy(routing_strategy strategy, bool fromCache = true); 217 | // change the route of the specified output 218 | void setOutputDevice(audio_io_handle_t output, uint32_t device, bool force = false, int delayMs = 0); 219 | // select input device corresponding to requested audio source 220 | virtual uint32_t getDeviceForInputSource(int inputSource); 221 | // return io handle of active input or 0 if no input is active 222 | audio_io_handle_t getActiveInput(); 223 | // compute the actual volume for a given stream according to the requested index and a particular 224 | // device 225 | virtual float computeVolume(int stream, int index, audio_io_handle_t output, uint32_t device); 226 | // check that volume change is permitted, compute and send new volume to audio hardware 227 | status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, uint32_t device, int delayMs = 0, bool force = false); 228 | // apply all stream volumes to the specified output and device 229 | void applyStreamVolumes(audio_io_handle_t output, uint32_t device, int delayMs = 0); 230 | // Mute or unmute all streams handled by the specified strategy on the specified output 231 | void setStrategyMute(routing_strategy strategy, bool on, audio_io_handle_t output, int delayMs = 0); 232 | // Mute or unmute the stream on the specified output 233 | void setStreamMute(int stream, bool on, audio_io_handle_t output, int delayMs = 0); 234 | // handle special cases for sonification strategy while in call: mute streams or replace by 235 | // a special tone in the device used for communication 236 | void handleIncallSonification(int stream, bool starting, bool stateChange); 237 | // true is current platform implements a back microphone 238 | virtual bool hasBackMicrophone() const { return false; } 239 | 240 | #ifdef WITH_A2DP 241 | // true is current platform supports suplication of notifications and ringtones over A2DP output 242 | virtual bool a2dpUsedForSonification() const { return true; } 243 | status_t handleA2dpConnection(AudioSystem::audio_devices device, 244 | const char *device_address); 245 | status_t handleA2dpDisconnection(AudioSystem::audio_devices device, 246 | const char *device_address); 247 | void closeA2dpOutputs(); 248 | // checks and if necessary changes output (a2dp, duplicated or hardware) used for all strategies. 249 | // must be called every time a condition that affects the output choice for a given strategy is 250 | // changed: connected device, phone state, force use... 251 | // Must be called before updateDeviceForStrategy() 252 | void checkOutputForStrategy(routing_strategy strategy); 253 | // Same as checkOutputForStrategy() but for a all strategies in order of priority 254 | void checkOutputForAllStrategies(); 255 | 256 | #endif 257 | // selects the most appropriate device on output for current state 258 | // must be called every time a condition that affects the device choice for a given output is 259 | // changed: connected device, phone state, force use, output start, output stop.. 260 | // see getDeviceForStrategy() for the use of fromCache parameter 261 | uint32_t getNewDevice(audio_io_handle_t output, bool fromCache = true); 262 | // updates cache of device used by all strategies (mDeviceForStrategy[]) 263 | // must be called every time a condition that affects the device choice for a given strategy is 264 | // changed: connected device, phone state, force use... 265 | // cached values are used by getDeviceForStrategy() if parameter fromCache is true. 266 | // Must be called after checkOutputForAllStrategies() 267 | void updateDeviceForStrategy(); 268 | // true if current platform requires a specific output to be opened for this particular 269 | // set of parameters. This function is called by getOutput() and is implemented by platform 270 | // specific audio policy manager. 271 | virtual bool needsDirectOuput(AudioSystem::stream_type stream, 272 | uint32_t samplingRate, 273 | uint32_t format, 274 | uint32_t channels, 275 | AudioSystem::output_flags flags, 276 | uint32_t device); 277 | virtual uint32_t getMaxEffectsCpuLoad(); 278 | virtual uint32_t getMaxEffectsMemory(); 279 | #ifdef AUDIO_POLICY_TEST 280 | virtual bool threadLoop(); 281 | void exit(); 282 | int testOutputIndex(audio_io_handle_t output); 283 | #endif //AUDIO_POLICY_TEST 284 | 285 | AudioPolicyClientInterface *mpClientInterface; // audio policy client interface 286 | audio_io_handle_t mHardwareOutput; // hardware output handler 287 | audio_io_handle_t mA2dpOutput; // A2DP output handler 288 | audio_io_handle_t mDuplicatedOutput; // duplicated output handler: outputs to hardware and A2DP. 289 | 290 | KeyedVector mOutputs; // list of output descriptors 291 | KeyedVector mInputs; // list of input descriptors 292 | uint32_t mAvailableOutputDevices; // bit field of all available output devices 293 | uint32_t mAvailableInputDevices; // bit field of all available input devices 294 | int mPhoneState; // current phone state 295 | uint32_t mRingerMode; // current ringer mode 296 | AudioSystem::forced_config mForceUse[AudioSystem::NUM_FORCE_USE]; // current forced use configuration 297 | 298 | StreamDescriptor mStreams[AudioSystem::NUM_STREAM_TYPES]; // stream descriptors for volume control 299 | String8 mA2dpDeviceAddress; // A2DP device MAC address 300 | String8 mScoDeviceAddress; // SCO device MAC address 301 | nsecs_t mMusicStopTime; // time when last music stream was stopped 302 | bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected 303 | uint32_t mDeviceForStrategy[NUM_STRATEGIES]; 304 | 305 | // Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units 306 | static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000; 307 | // Maximum memory allocated to audio effects in KB 308 | static const uint32_t MAX_EFFECTS_MEMORY = 512; 309 | uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects 310 | uint32_t mTotalEffectsMemory; // current memory used by effects 311 | KeyedVector mEffects; // list of registered audio effects 312 | 313 | #ifdef AUDIO_POLICY_TEST 314 | Mutex mLock; 315 | Condition mWaitWorkCV; 316 | 317 | int mCurOutput; 318 | bool mDirectOutput; 319 | audio_io_handle_t mTestOutputs[NUM_TEST_OUTPUTS]; 320 | int mTestInput; 321 | uint32_t mTestDevice; 322 | uint32_t mTestSamplingRate; 323 | uint32_t mTestFormat; 324 | uint32_t mTestChannels; 325 | uint32_t mTestLatencyMs; 326 | #endif //AUDIO_POLICY_TEST 327 | }; 328 | 329 | }; 330 | --------------------------------------------------------------------------------