Merge 48e4ab6b7

Change-Id: Ie034418055ed9b10608e06fd6e35d64bddb73598
diff --git a/Android.mk b/Android.mk
index 967a096..30b3337 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,6 +1,7 @@
 # Copyright 2006 The Android Open Source Project
 
 # Setting LOCAL_PATH will mess up all-subdir-makefiles, so do it beforehand.
+SUBDIR_MAKEFILES := $(call all-named-subdir-makefiles,modules tests)
 
 LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
@@ -31,8 +32,4 @@
 
 include $(BUILD_SHARED_LIBRARY)
 
-include $(addsuffix /Android.mk, $(addprefix $(LOCAL_PATH)/, \
-			modules/gralloc \
-			tests \
-		))
-		
\ No newline at end of file
+include $(SUBDIR_MAKEFILES)
diff --git a/hardware.c b/hardware.c
index d2e3b4c..2559237 100644
--- a/hardware.c
+++ b/hardware.c
@@ -117,13 +117,20 @@
     return status;
 }
 
-int hw_get_module(const char *id, const struct hw_module_t **module) 
+int hw_get_module_by_class(const char *class_id, const char *inst,
+                           const struct hw_module_t **module)
 {
     int status;
     int i;
     const struct hw_module_t *hmi = NULL;
     char prop[PATH_MAX];
     char path[PATH_MAX];
+    char name[PATH_MAX];
+
+    if (inst)
+        snprintf(name, PATH_MAX, "%s.%s", class_id, inst);
+    else
+        strlcpy(name, class_id, PATH_MAX);
 
     /*
      * Here we rely on the fact that calling dlopen multiple times on
@@ -139,15 +146,15 @@
                 continue;
             }
             snprintf(path, sizeof(path), "%s/%s.%s.so",
-                    HAL_LIBRARY_PATH1, id, prop);
+                    HAL_LIBRARY_PATH1, name, prop);
             if (access(path, R_OK) == 0) break;
 
             snprintf(path, sizeof(path), "%s/%s.%s.so",
-                     HAL_LIBRARY_PATH2, id, prop);
+                     HAL_LIBRARY_PATH2, name, prop);
             if (access(path, R_OK) == 0) break;
         } else {
             snprintf(path, sizeof(path), "%s/%s.default.so",
-                     HAL_LIBRARY_PATH1, id);
+                     HAL_LIBRARY_PATH1, name);
             if (access(path, R_OK) == 0) break;
         }
     }
@@ -156,8 +163,13 @@
     if (i < HAL_VARIANT_KEYS_COUNT+1) {
         /* load the module, if this fails, we're doomed, and we should not try
          * to load a different variant. */
-        status = load(id, path, module);
+        status = load(class_id, path, module);
     }
 
     return status;
 }
+
+int hw_get_module(const char *id, const struct hw_module_t **module)
+{
+    return hw_get_module_by_class(id, NULL, module);
+}
diff --git a/include/hardware/audio_hal.h b/include/hardware/audio_hal.h
new file mode 100644
index 0000000..c105370
--- /dev/null
+++ b/include/hardware/audio_hal.h
@@ -0,0 +1,298 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_AUDIO_HAL_INTERFACE_H
+#define ANDROID_AUDIO_HAL_INTERFACE_H
+
+#include <stdint.h>
+#include <strings.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <cutils/bitops.h>
+
+#include <hardware/hardware.h>
+#include <system/audio.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define AUDIO_HARDWARE_MODULE_ID "audio"
+
+/**
+ * Name of the audio devices to open
+ */
+#define AUDIO_HARDWARE_INTERFACE "audio_hw_if"
+
+/**************************************/
+
+/* common audio stream parameters and operations */
+struct audio_stream {
+
+    /**
+     * sampling rate is in Hz - eg. 44100
+     */
+    uint32_t (*get_sample_rate)(const struct audio_stream *stream);
+    int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
+
+    /**
+     * size of output buffer in bytes - eg. 4800
+     */
+    size_t (*get_buffer_size)(const struct audio_stream *stream);
+
+    /**
+     * the channel mask -
+     *  e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
+     */
+    uint32_t (*get_channels)(const struct audio_stream *stream);
+
+    /**
+     * audio format - eg. AUDIO_FORMAT_PCM_16_BIT
+     */
+    int (*get_format)(const struct audio_stream *stream);
+    int (*set_format)(struct audio_stream *stream, int format);
+
+    /**
+     * Put the audio hardware input/output into standby mode.
+     * Returns 0 on success and <0 on failure.
+     */
+    int (*standby)(struct audio_stream *stream);
+
+    /** dump the state of the audio input/output device */
+    int (*dump)(const struct audio_stream *stream, int fd);
+
+    audio_devices_t (*get_device)(const struct audio_stream *stream);
+    int (*set_device)(struct audio_stream *stream, audio_devices_t device);
+
+    /**
+     * set/get audio stream parameters. The function accepts a list of
+     * parameter key value pairs in the form: key1=value1;key2=value2;...
+     *
+     * Some keys are reserved for standard parameters (See AudioParameter class)
+     *
+     * If the implementation does not accept a parameter change while
+     * the output is active but the parameter is acceptable otherwise, it must
+     * return -ENOSYS.
+     *
+     * The audio flinger will put the stream in standby and then change the
+     * parameter value.
+     */
+    int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs);
+
+    /*
+     * Returns a pointer to a heap allocated string. The caller is responsible
+     * for freeing the memory for it.
+     */
+    char * (*get_parameters)(const struct audio_stream *stream,
+                             const char *keys);
+};
+typedef struct audio_stream audio_stream_t;
+
+/**
+ * audio_stream_out is the abstraction interface for the audio output hardware.
+ *
+ * It provides information about various properties of the audio output
+ * hardware driver.
+ */
+
+struct audio_stream_out {
+    struct audio_stream common;
+
+    /**
+     * return the audio hardware driver latency in milli seconds.
+     */
+    uint32_t (*get_latency)(const struct audio_stream_out *stream);
+
+    /**
+     * Use this method in situations where audio mixing is done in the
+     * hardware. This method serves as a direct interface with hardware,
+     * allowing you to directly set the volume as apposed to via the framework.
+     * This method might produce multiple PCM outputs or hardware accelerated
+     * codecs, such as MP3 or AAC.
+     */
+    int (*set_volume)(struct audio_stream_out *stream, float left, float right);
+
+    /**
+     * write audio buffer to driver. Returns number of bytes written
+     */
+    ssize_t (*write)(struct audio_stream_out *stream, const void* buffer,
+                     size_t bytes);
+
+    /* return the number of audio frames written by the audio dsp to DAC since
+     * the output has exited standby
+     */
+    int (*get_render_position)(const struct audio_stream_out *stream,
+                               uint32_t *dsp_frames);
+};
+typedef struct audio_stream_out audio_stream_out_t;
+
+struct audio_stream_in {
+    struct audio_stream common;
+
+    /** set the input gain for the audio driver. This method is for
+     *  for future use */
+    int (*set_gain)(struct audio_stream_in *stream, float gain);
+
+    /** read audio buffer in from audio driver */
+    ssize_t (*read)(struct audio_stream_in *stream, void* buffer,
+                    size_t bytes);
+
+    /**
+     * Return the amount of input frames lost in the audio driver since the
+     * last call of this function.
+     * Audio driver is expected to reset the value to 0 and restart counting
+     * upon returning the current value by this function call.
+     * Such loss typically occurs when the user space process is blocked
+     * longer than the capacity of audio driver buffers.
+     *
+     * Unit: the number of input audio frames
+     */
+    uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream);
+};
+typedef struct audio_stream_in audio_stream_in_t;
+
+/**
+ * return the frame size (number of bytes per sample).
+ */
+static inline uint32_t audio_stream_frame_size(struct audio_stream *s)
+{
+    int chan_samp_sz;
+
+    switch (s->get_format(s)) {
+    case AUDIO_FORMAT_PCM_16_BIT:
+        chan_samp_sz = sizeof(int16_t);
+        break;
+    case AUDIO_FORMAT_PCM_8_BIT:
+    default:
+        chan_samp_sz = sizeof(int8_t);
+        break;
+    }
+
+    return popcount(s->get_channels(s)) * chan_samp_sz;
+}
+
+
+/**********************************************************************/
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+struct audio_module {
+    struct hw_module_t common;
+};
+
+struct audio_hw_device {
+    struct hw_device_t common;
+
+    /**
+     * used by audio flinger to enumerate what devices are supported by
+     * each audio_hw_device implementation.
+     *
+     * Return value is a bitmask of 1 or more values of audio_devices_t
+     */
+    uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);
+
+    /**
+     * check to see if the audio hardware interface has been initialized.
+     * returns 0 on success, -ENODEV on failure.
+     */
+    int (*init_check)(const struct audio_hw_device *dev);
+
+    /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */
+    int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
+
+    /**
+     * set the audio volume for all audio activities other than voice call.
+     * Range between 0.0 and 1.0. If any value other than 0 is returned,
+     * the software mixer will emulate this capability.
+     */
+    int (*set_master_volume)(struct audio_hw_device *dev, float volume);
+
+    /**
+     * setMode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
+     * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
+     * playing, and AUDIO_MODE_IN_CALL when a call is in progress.
+     */
+    int (*set_mode)(struct audio_hw_device *dev, int mode);
+
+    /* mic mute */
+    int (*set_mic_mute)(struct audio_hw_device *dev, bool state);
+    int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state);
+
+    /* set/get global audio parameters */
+    int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs);
+
+    /*
+     * Returns a pointer to a heap allocated string. The caller is responsible
+     * for freeing the memory for it.
+     */
+    char * (*get_parameters)(const struct audio_hw_device *dev,
+                             const char *keys);
+
+    /* Returns audio input buffer size according to parameters passed or
+     * 0 if one of the parameters is not supported
+     */
+    size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,
+                                    uint32_t sample_rate, int format,
+                                    int channel_count);
+
+    /** This method creates and opens the audio hardware output stream */
+    int (*open_output_stream)(struct audio_hw_device *dev, uint32_t devices,
+                              int *format, uint32_t *channels,
+                              uint32_t *sample_rate,
+                              struct audio_stream_out **out);
+
+    void (*close_output_stream)(struct audio_hw_device *dev,
+                                struct audio_stream_out* out);
+
+    /** This method creates and opens the audio hardware input stream */
+    int (*open_input_stream)(struct audio_hw_device *dev, uint32_t devices,
+                             int *format, uint32_t *channels,
+                             uint32_t *sample_rate,
+                             audio_in_acoustics_t acoustics,
+                             struct audio_stream_in **stream_in);
+
+    void (*close_input_stream)(struct audio_hw_device *dev,
+                               struct audio_stream_in *in);
+
+    /** This method dumps the state of the audio hardware */
+    int (*dump)(const struct audio_hw_device *dev, int fd);
+};
+typedef struct audio_hw_device audio_hw_device_t;
+
+/** convenience API for opening and closing a supported device */
+
+static inline int audio_hw_device_open(const struct hw_module_t* module,
+                                       struct audio_hw_device** device)
+{
+    return module->methods->open(module, AUDIO_HARDWARE_INTERFACE,
+                                 (struct hw_device_t**)device);
+}
+
+static inline int audio_hw_device_close(struct audio_hw_device* device)
+{
+    return device->common.close(&device->common);
+}
+
+
+__END_DECLS
+
+#endif  // ANDROID_AUDIO_INTERFACE_H
diff --git a/include/hardware/audio_policy.h b/include/hardware/audio_policy.h
new file mode 100644
index 0000000..1e0af7d
--- /dev/null
+++ b/include/hardware/audio_policy.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_AUDIO_POLICY_CORE_H
+#define ANDROID_AUDIO_POLICY_CORE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <cutils/bitops.h>
+
+__BEGIN_DECLS
+
+/* The enums were moved here mostly from
+ * frameworks/base/include/media/AudioSystem.h
+ */
+
+/* request to open a direct output with get_output() (by opposition to
+ * sharing an output with other AudioTracks)
+ */
+typedef enum {
+    AUDIO_POLICY_OUTPUT_FLAG_INDIRECT = 0x0,
+    AUDIO_POLICY_OUTPUT_FLAG_DIRECT = 0x1
+} audio_policy_output_flags_t;
+
+/* device categories used for audio_policy->set_force_use() */
+typedef enum {
+    AUDIO_POLICY_FORCE_NONE,
+    AUDIO_POLICY_FORCE_SPEAKER,
+    AUDIO_POLICY_FORCE_HEADPHONES,
+    AUDIO_POLICY_FORCE_BT_SCO,
+    AUDIO_POLICY_FORCE_BT_A2DP,
+    AUDIO_POLICY_FORCE_WIRED_ACCESSORY,
+    AUDIO_POLICY_FORCE_BT_CAR_DOCK,
+    AUDIO_POLICY_FORCE_BT_DESK_DOCK,
+    AUDIO_POLICY_FORCE_ANALOG_DOCK,
+    AUDIO_POLICY_FORCE_DIGITAL_DOCK,
+
+    AUDIO_POLICY_FORCE_CFG_CNT,
+    AUDIO_POLICY_FORCE_CFG_MAX = AUDIO_POLICY_FORCE_CFG_CNT - 1,
+
+    AUDIO_POLICY_FORCE_DEFAULT = AUDIO_POLICY_FORCE_NONE,
+} audio_policy_forced_cfg_t;
+
+/* usages used for audio_policy->set_force_use() */
+typedef enum {
+    AUDIO_POLICY_FORCE_FOR_COMMUNICATION,
+    AUDIO_POLICY_FORCE_FOR_MEDIA,
+    AUDIO_POLICY_FORCE_FOR_RECORD,
+    AUDIO_POLICY_FORCE_FOR_DOCK,
+
+    AUDIO_POLICY_FORCE_USE_CNT,
+    AUDIO_POLICY_FORCE_USE_MAX = AUDIO_POLICY_FORCE_USE_CNT - 1,
+} audio_policy_force_use_t;
+
+/* device connection states used for audio_policy->set_device_connection_state()
+ */
+typedef enum {
+    AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
+    AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
+
+    AUDIO_POLICY_DEVICE_STATE_CNT,
+    AUDIO_POLICY_DEVICE_STATE_MAX = AUDIO_POLICY_DEVICE_STATE_CNT - 1,
+} audio_policy_dev_state_t;
+
+typedef enum {
+    /* Used to generate a tone to notify the user of a
+     * notification/alarm/ringtone while they are in a call. */
+    AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION = 0,
+
+    AUDIO_POLICY_TONE_CNT,
+    AUDIO_POLICY_TONE_MAX                  = AUDIO_POLICY_TONE_CNT - 1,
+} audio_policy_tone_t;
+
+
+static inline bool audio_is_low_visibility(audio_stream_type_t stream)
+{
+    switch (stream) {
+    case AUDIO_STREAM_SYSTEM:
+    case AUDIO_STREAM_NOTIFICATION:
+    case AUDIO_STREAM_RING:
+        return true;
+    default:
+        return false;
+    }
+}
+
+
+__END_DECLS
+
+#endif  // ANDROID_AUDIO_POLICY_CORE_H
diff --git a/include/hardware/audio_policy_hal.h b/include/hardware/audio_policy_hal.h
new file mode 100644
index 0000000..bf226d9
--- /dev/null
+++ b/include/hardware/audio_policy_hal.h
@@ -0,0 +1,384 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_AUDIO_POLICY_INTERFACE_H
+#define ANDROID_AUDIO_POLICY_INTERFACE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <hardware/hardware.h>
+
+#include <system/audio.h>
+#include <hardware/audio_policy.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define AUDIO_POLICY_HARDWARE_MODULE_ID "audio_policy"
+
+/**
+ * Name of the audio devices to open
+ */
+#define AUDIO_POLICY_INTERFACE "policy"
+
+/* ---------------------------------------------------------------------------- */
+
+/*
+ * The audio_policy and audio_policy_service_ops structs define the
+ * communication interfaces between the platform specific audio policy manager
+ * and Android generic audio policy manager.
+ * The platform specific audio policy manager must implement methods of the
+ * audio_policy struct.
+ * This implementation makes use of the audio_policy_service_ops to control
+ * the activity and configuration of audio input and output streams.
+ *
+ * The platform specific audio policy manager is in charge of the audio
+ * routing and volume control policies for a given platform.
+ * The main roles of this module are:
+ *   - keep track of current system state (removable device connections, phone
+ *     state, user requests...).
+ *   System state changes and user actions are notified to audio policy
+ *   manager with methods of the audio_policy.
+ *
+ *   - process get_output() queries received when AudioTrack objects are
+ *     created: Those queries return a handler on an output that has been
+ *     selected, configured and opened by the audio policy manager and that
+ *     must be used by the AudioTrack when registering to the AudioFlinger
+ *     with the createTrack() method.
+ *   When the AudioTrack object is released, a release_output() query
+ *   is received and the audio policy manager can decide to close or
+ *   reconfigure the output depending on other streams using this output and
+ *   current system state.
+ *
+ *   - similarly process get_input() and release_input() queries received from
+ *     AudioRecord objects and configure audio inputs.
+ *   - process volume control requests: the stream volume is converted from
+ *     an index value (received from UI) to a float value applicable to each
+ *     output as a function of platform specific settings and current output
+ *     route (destination device). It also make sure that streams are not
+ *     muted if not allowed (e.g. camera shutter sound in some countries).
+ */
+
+/* XXX: this should be defined OUTSIDE of frameworks/base */
+struct effect_descriptor_s;
+
+struct audio_policy {
+    /*
+     * configuration functions
+     */
+
+    /* indicate a change in device connection status */
+    int (*set_device_connection_state)(struct audio_policy *pol,
+                                       audio_devices_t device,
+                                       audio_policy_dev_state_t state,
+                                       const char *device_address);
+
+    /* retreive a device connection status */
+    audio_policy_dev_state_t (*get_device_connection_state)(
+                                            const struct audio_policy *pol,
+                                            audio_devices_t device,
+                                            const char *device_address);
+
+    /* indicate a change in phone state. Valid phones states are defined
+     * by audio_mode_t */
+    void (*set_phone_state)(struct audio_policy *pol, int state);
+
+    /* indicate a change in ringer mode */
+    void (*set_ringer_mode)(struct audio_policy *pol, uint32_t mode,
+                            uint32_t mask);
+
+    /* force using a specific device category for the specified usage */
+    void (*set_force_use)(struct audio_policy *pol,
+                          audio_policy_force_use_t usage,
+                          audio_policy_forced_cfg_t config);
+
+    /* retreive current device category forced for a given usage */
+    audio_policy_forced_cfg_t (*get_force_use)(const struct audio_policy *pol,
+                                               audio_policy_force_use_t usage);
+
+    /* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE
+     * can still be muted. */
+    void (*set_can_mute_enforced_audible)(struct audio_policy *pol,
+                                          bool can_mute);
+
+    /* check proper initialization */
+    int (*init_check)(const struct audio_policy *pol);
+
+    /*
+     * Audio routing query functions
+     */
+
+    /* request an output appriate for playback of the supplied stream type and
+     * parameters */
+    audio_io_handle_t (*get_output)(struct audio_policy *pol,
+                                    audio_stream_type_t stream,
+                                    uint32_t samplingRate,
+                                    uint32_t format,
+                                    uint32_t channels,
+                                    audio_policy_output_flags_t flags);
+
+    /* indicates to the audio policy manager that the output starts being used
+     * by corresponding stream. */
+    int (*start_output)(struct audio_policy *pol,
+                        audio_io_handle_t output,
+                        audio_stream_type_t stream,
+                        int session);
+
+    /* indicates to the audio policy manager that the output stops being used
+     * by corresponding stream. */
+    int (*stop_output)(struct audio_policy *pol,
+                       audio_io_handle_t output,
+                       audio_stream_type_t stream,
+                       int session);
+
+    /* releases the output. */
+    void (*release_output)(struct audio_policy *pol, audio_io_handle_t output);
+
+    /* request an input appriate for record from the supplied device with
+     * supplied parameters. */
+    audio_io_handle_t (*get_input)(struct audio_policy *pol, int inputSource,
+                                   uint32_t samplingRate,
+                                   uint32_t format,
+                                   uint32_t channels,
+                                   audio_in_acoustics_t acoustics);
+
+    /* indicates to the audio policy manager that the input starts being used */
+    int (*start_input)(struct audio_policy *pol, audio_io_handle_t input);
+
+    /* indicates to the audio policy manager that the input stops being used. */
+    int (*stop_input)(struct audio_policy *pol, audio_io_handle_t input);
+
+    /* releases the input. */
+    void (*release_input)(struct audio_policy *pol, audio_io_handle_t input);
+
+    /*
+     * volume control functions
+     */
+
+    /* initialises stream volume conversion parameters by specifying volume
+     * index range. */
+    void (*init_stream_volume)(struct audio_policy *pol,
+                               audio_stream_type_t stream,
+                               int index_min,
+                               int index_max);
+
+    /* sets the new stream volume at a level corresponding to the supplied
+     * index */
+    int (*set_stream_volume_index)(struct audio_policy *pol,
+                                   audio_stream_type_t stream,
+                                   int index);
+
+    /* retreive current volume index for the specified stream */
+    int (*get_stream_volume_index)(const struct audio_policy *pol,
+                                   audio_stream_type_t stream,
+                                   int *index);
+
+    /* return the strategy corresponding to a given stream type */
+    uint32_t (*get_strategy_for_stream)(const struct audio_policy *pol,
+                                        audio_stream_type_t stream);
+
+    /* return the enabled output devices for the given stream type */
+    uint32_t (*get_devices_for_stream)(const struct audio_policy *pol,
+                                       audio_stream_type_t stream);
+
+    /* Audio effect management */
+    audio_io_handle_t (*get_output_for_effect)(struct audio_policy *pol,
+                                            struct effect_descriptor_s *desc);
+
+    int (*register_effect)(struct audio_policy *pol,
+                           struct effect_descriptor_s *desc,
+                           audio_io_handle_t output,
+                           uint32_t strategy,
+                           int session,
+                           int id);
+
+    int (*unregister_effect)(struct audio_policy *pol, int id);
+
+    bool (*is_stream_active)(const struct audio_policy *pol,
+                             int stream,
+                             uint32_t in_past_ms);
+
+    /* dump state */
+    int (*dump)(const struct audio_policy *pol, int fd);
+};
+
+struct audio_policy_service_ops {
+    /*
+     * Audio output Control functions
+     */
+
+    /* Opens an audio output with the requested parameters.
+     *
+     * The parameter values can indicate to use the default values in case the
+     * audio policy manager has no specific requirements for the output being
+     * opened.
+     *
+     * When the function returns, the parameter values reflect the actual
+     * values used by the audio hardware output stream.
+     *
+     * The audio policy manager can check if the proposed parameters are
+     * suitable or not and act accordingly.
+     */
+    audio_io_handle_t (*open_output)(void *service,
+                                     uint32_t *pDevices,
+                                     uint32_t *pSamplingRate,
+                                     uint32_t *pFormat,
+                                     uint32_t *pChannels,
+                                     uint32_t *pLatencyMs,
+                                     audio_policy_output_flags_t flags);
+
+    /* creates a special output that is duplicated to the two outputs passed as
+     * arguments. The duplication is performed by
+     * a special mixer thread in the AudioFlinger.
+     */
+    audio_io_handle_t (*open_duplicate_output)(void *service,
+                                               audio_io_handle_t output1,
+                                               audio_io_handle_t output2);
+
+    /* closes the output stream */
+    int (*close_output)(void *service, audio_io_handle_t output);
+
+    /* suspends the output.
+     *
+     * When an output is suspended, the corresponding audio hardware output
+     * stream is placed in standby and the AudioTracks attached to the mixer
+     * thread are still processed but the output mix is discarded.
+     */
+    int (*suspend_output)(void *service, audio_io_handle_t output);
+
+    /* restores a suspended output. */
+    int (*restore_output)(void *service, audio_io_handle_t output);
+
+    /* */
+    /* Audio input Control functions */
+    /* */
+
+    /* opens an audio input */
+    audio_io_handle_t (*open_input)(void *service,
+                                    uint32_t *pDevices,
+                                    uint32_t *pSamplingRate,
+                                    uint32_t *pFormat,
+                                    uint32_t *pChannels,
+                                    uint32_t acoustics);
+
+    /* closes an audio input */
+    int (*close_input)(void *service, audio_io_handle_t input);
+
+    /* */
+    /* misc control functions */
+    /* */
+
+    /* set a stream volume for a particular output.
+     *
+     * For the same user setting, a given stream type can have different
+     * volumes for each output (destination device) it is attached to.
+     */
+    int (*set_stream_volume)(void *service,
+                             audio_stream_type_t stream,
+                             float volume,
+                             audio_io_handle_t output,
+                             int delay_ms);
+
+    /* reroute a given stream type to the specified output */
+    int (*set_stream_output)(void *service,
+                             audio_stream_type_t stream,
+                             audio_io_handle_t output);
+
+    /* function enabling to send proprietary informations directly from audio
+     * policy manager to audio hardware interface. */
+    void (*set_parameters)(void *service,
+                           audio_io_handle_t io_handle,
+                           const char *kv_pairs,
+                           int delay_ms);
+
+    /* function enabling to receive proprietary informations directly from
+     * audio hardware interface to audio policy manager.
+     *
+     * Returns a pointer to a heap allocated string. The caller is responsible
+     * for freeing the memory for it.
+     */
+
+    char * (*get_parameters)(void *service, audio_io_handle_t io_handle,
+                             const char *keys);
+
+    /* request the playback of a tone on the specified stream.
+     * used for instance to replace notification sounds when playing over a
+     * telephony device during a phone call.
+     */
+    int (*start_tone)(void *service,
+                      audio_policy_tone_t tone,
+                      audio_stream_type_t stream);
+
+    int (*stop_tone)(void *service);
+
+    /* set down link audio volume. */
+    int (*set_voice_volume)(void *service,
+                            float volume,
+                            int delay_ms);
+
+    /* move effect to the specified output */
+    int (*move_effects)(void *service,
+                        int session,
+                        audio_io_handle_t src_output,
+                        audio_io_handle_t dst_output);
+};
+
+/**********************************************************************/
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+typedef struct audio_policy_module {
+    struct hw_module_t common;
+} audio_policy_module_t;
+
+struct audio_policy_device {
+    struct hw_device_t common;
+
+    int (*create_audio_policy)(const struct audio_policy_device *device,
+                               struct audio_policy_service_ops *aps_ops,
+                               void *service,
+                               struct audio_policy **ap);
+
+    int (*destroy_audio_policy)(const struct audio_policy_device *device,
+                                struct audio_policy *ap);
+};
+
+/** convenience API for opening and closing a supported device */
+
+static inline int audio_policy_dev_open(const hw_module_t* module,
+                                    struct audio_policy_device** device)
+{
+    return module->methods->open(module, AUDIO_POLICY_INTERFACE,
+                                 (hw_device_t**)device);
+}
+
+static inline int audio_policy_dev_close(struct audio_policy_device* device)
+{
+    return device->common.close(&device->common);
+}
+
+
+__END_DECLS
+
+#endif  // ANDROID_AUDIO_POLICY_INTERFACE_H
diff --git a/include/hardware/camera.h b/include/hardware/camera.h
new file mode 100644
index 0000000..04fb6ec
--- /dev/null
+++ b/include/hardware/camera.h
@@ -0,0 +1,293 @@
+/*
+ * Copyright (C) 2010-2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// FIXME: add well-defined names for cameras
+
+#ifndef ANDROID_INCLUDE_CAMERA_H
+#define ANDROID_INCLUDE_CAMERA_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <cutils/native_handle.h>
+#include <system/camera.h>
+#include <hardware/hardware.h>
+#include <hardware/gralloc.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define CAMERA_HARDWARE_MODULE_ID "camera"
+
+struct camera_info {
+    /**
+     * The direction that the camera faces to. It should be CAMERA_FACING_BACK
+     * or CAMERA_FACING_FRONT.
+     */
+    int facing;
+
+    /**
+     * The orientation of the camera image. The value is the angle that the
+     * camera image needs to be rotated clockwise so it shows correctly on the
+     * display in its natural orientation. It should be 0, 90, 180, or 270.
+     *
+     * For example, suppose a device has a naturally tall screen. The
+     * back-facing camera sensor is mounted in landscape. You are looking at
+     * the screen. If the top side of the camera sensor is aligned with the
+     * right edge of the screen in natural orientation, the value should be
+     * 90. If the top side of a front-facing camera sensor is aligned with the
+     * right of the screen, the value should be 270.
+     */
+    int orientation;
+};
+
+typedef struct camera_module {
+    hw_module_t common;
+    int (*get_number_of_cameras)(void);
+    int (*get_camera_info)(int camera_id, struct camera_info *info);
+} camera_module_t;
+
+typedef struct camera_memory {
+    void *data;
+    size_t size;
+    void *handle;
+} camera_memory_t;
+
+typedef camera_memory_t* (*camera_request_memory)(size_t size, void *user);
+
+typedef void (*camera_notify_callback)(int32_t msg_type,
+        int32_t ext1,
+        int32_t ext2,
+        void *user);
+
+typedef void (*camera_data_callback)(int32_t msg_type,
+        const camera_memory_t *data,
+        void *user);
+
+typedef void (*camera_data_timestamp_callback)(int64_t timestamp,
+        int32_t msg_type,
+        const camera_memory_t *data,
+        void *user);
+
+#define HAL_CAMERA_PREVIEW_WINDOW_TAG 0xcafed00d
+
+typedef struct preview_stream_ops {
+    int (*dequeue_buffer)(struct preview_stream_ops* w,
+                buffer_handle_t** buffer);
+    int (*enqueue_buffer)(struct preview_stream_ops* w,
+                buffer_handle_t* buffer);
+    int (*cancel_buffer)(struct preview_stream_ops* w,
+                buffer_handle_t* buffer);
+    int (*set_buffer_count)(struct preview_stream_ops* w, int count);
+    int (*set_buffers_geometry)(struct preview_stream_ops* pw,
+                int w, int h, int format);
+    int (*set_crop)(struct preview_stream_ops *w,
+                int left, int top, int right, int bottom);
+    int (*set_usage)(struct preview_stream_ops* w, int usage);
+    int (*set_swap_interval)(struct preview_stream_ops *w, int interval);
+
+    int (*get_min_undequeued_buffer_count)(const struct preview_stream_ops *w,
+                int *count);
+} preview_stream_ops_t;
+
+struct camera_device;
+typedef struct camera_device_ops {
+    /** Set the ANativeWindow to which preview frames are sent */
+    int (*set_preview_window)(struct camera_device *,
+            struct preview_stream_ops *window);
+
+    /** Set the notification and data callbacks */
+    void (*set_callbacks)(struct camera_device *,
+            camera_notify_callback notify_cb,
+            camera_data_callback data_cb,
+            camera_data_timestamp_callback data_cb_timestamp,
+            camera_request_memory get_memory,
+            void *user);
+
+    /**
+     * The following three functions all take a msg_type, which is a bitmask of
+     * the messages defined in include/ui/Camera.h
+     */
+
+    /**
+     * Enable a message, or set of messages.
+     */
+    void (*enable_msg_type)(struct camera_device *, int32_t msg_type);
+
+    /**
+     * Disable a message, or a set of messages.
+     *
+     * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera
+     * HAL should not rely on its client to call releaseRecordingFrame() to
+     * release video recording frames sent out by the cameral HAL before and
+     * after the disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera HAL
+     * clients must not modify/access any video recording frame after calling
+     * disableMsgType(CAMERA_MSG_VIDEO_FRAME).
+     */
+    void (*disable_msg_type)(struct camera_device *, int32_t msg_type);
+
+    /**
+     * Query whether a message, or a set of messages, is enabled.  Note that
+     * this is operates as an AND, if any of the messages queried are off, this
+     * will return false.
+     */
+    int (*msg_type_enabled)(struct camera_device *, int32_t msg_type);
+
+    /**
+     * Start preview mode.
+     */
+    int (*start_preview)(struct camera_device *);
+
+    /**
+     * Stop a previously started preview.
+     */
+    void (*stop_preview)(struct camera_device *);
+
+    /**
+     * Returns true if preview is enabled.
+     */
+    int (*preview_enabled)(struct camera_device *);
+
+    /**
+     * Request the camera HAL to store meta data or real YUV data in the video
+     * buffers sent out via CAMERA_MSG_VIDEO_FRAME for a recording session. If
+     * it is not called, the default camera HAL behavior is to store real YUV
+     * data in the video buffers.
+     *
+     * This method should be called before startRecording() in order to be
+     * effective.
+     *
+     * If meta data is stored in the video buffers, it is up to the receiver of
+     * the video buffers to interpret the contents and to find the actual frame
+     * data with the help of the meta data in the buffer. How this is done is
+     * outside of the scope of this method.
+     *
+     * Some camera HALs may not support storing meta data in the video buffers,
+     * but all camera HALs should support storing real YUV data in the video
+     * buffers. If the camera HAL does not support storing the meta data in the
+     * video buffers when it is requested to do do, INVALID_OPERATION must be
+     * returned. It is very useful for the camera HAL to pass meta data rather
+     * than the actual frame data directly to the video encoder, since the
+     * amount of the uncompressed frame data can be very large if video size is
+     * large.
+     *
+     * @param enable if true to instruct the camera HAL to store
+     *        meta data in the video buffers; false to instruct
+     *        the camera HAL to store real YUV data in the video
+     *        buffers.
+     *
+     * @return OK on success.
+     */
+    int (*store_meta_data_in_buffers)(struct camera_device *, int enable);
+
+    /**
+     * Start record mode. When a record image is available, a
+     * CAMERA_MSG_VIDEO_FRAME message is sent with the corresponding
+     * frame. Every record frame must be released by a camera HAL client via
+     * releaseRecordingFrame() before the client calls
+     * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls
+     * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
+     * responsibility to manage the life-cycle of the video recording frames,
+     * and the client must not modify/access any video recording frames.
+     */
+    int (*start_recording)(struct camera_device *);
+
+    /**
+     * Stop a previously started recording.
+     */
+    void (*stop_recording)(struct camera_device *);
+
+    /**
+     * Returns true if recording is enabled.
+     */
+    int (*recording_enabled)(struct camera_device *);
+
+    /**
+     * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
+     *
+     * It is camera HAL client's responsibility to release video recording
+     * frames sent out by the camera HAL before the camera HAL receives a call
+     * to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives the call to
+     * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
+     * responsibility to manage the life-cycle of the video recording frames.
+     */
+    void (*release_recording_frame)(struct camera_device *,
+                    const void *opaque);
+
+    /**
+     * Start auto focus, the notification callback routine is called with
+     * CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() will be
+     * called again if another auto focus is needed.
+     */
+    int (*auto_focus)(struct camera_device *);
+
+    /**
+     * Cancels auto-focus function. If the auto-focus is still in progress,
+     * this function will cancel it. Whether the auto-focus is in progress or
+     * not, this function will return the focus position to the default.  If
+     * the camera does not support auto-focus, this is a no-op.
+     */
+    int (*cancel_auto_focus)(struct camera_device *);
+
+    /**
+     * Take a picture.
+     */
+    int (*take_picture)(struct camera_device *);
+
+    /**
+     * Cancel a picture that was started with takePicture. Calling this method
+     * when no picture is being taken is a no-op.
+     */
+    int (*cancel_picture)(struct camera_device *);
+
+    /**
+     * Set the camera parameters. This returns BAD_VALUE if any parameter is
+     * invalid or not supported.
+     */
+    int (*set_parameters)(struct camera_device *, const char *parms);
+
+    /** Return the camera parameters. */
+    char *(*get_parameters)(struct camera_device *);
+
+    /**
+     * Send command to camera driver.
+     */
+    int (*send_command)(struct camera_device *,
+                int32_t cmd, int32_t arg1, int32_t arg2);
+
+    /**
+     * Release the hardware resources owned by this object.  Note that this is
+     * *not* done in the destructor.
+     */
+    void (*release)(struct camera_device *);
+
+    /**
+     * Dump state of the camera hardware
+     */
+    int (*dump)(struct camera_device *, int fd);
+} camera_device_ops_t;
+
+typedef struct camera_device {
+    hw_device_t common;
+    camera_device_ops_t *ops;
+    void *priv;
+} camera_device_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_CAMERA_H */
diff --git a/include/hardware/copybit.h b/include/hardware/copybit.h
deleted file mode 100644
index b6302c3..0000000
--- a/include/hardware/copybit.h
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_COPYBIT_INTERFACE_H
-#define ANDROID_COPYBIT_INTERFACE_H
-
-#include <hardware/hardware.h>
-
-#include <stdint.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-__BEGIN_DECLS
-
-/**
- * The id of this module
- */
-#define COPYBIT_HARDWARE_MODULE_ID "copybit"
-
-/**
- * Name of the graphics device to open
- */
-#define COPYBIT_HARDWARE_COPYBIT0 "copybit0"
-
-/* supported pixel-formats. these must be compatible with
- * graphics/PixelFormat.java, ui/PixelFormat.h, pixelflinger/format.h
- */
-enum {
-    COPYBIT_FORMAT_RGBA_8888    = HAL_PIXEL_FORMAT_RGBA_8888,
-    COPYBIT_FORMAT_RGBX_8888    = HAL_PIXEL_FORMAT_RGBX_8888,
-    COPYBIT_FORMAT_RGB_888      = HAL_PIXEL_FORMAT_RGB_888,
-    COPYBIT_FORMAT_RGB_565      = HAL_PIXEL_FORMAT_RGB_565,
-    COPYBIT_FORMAT_BGRA_8888    = HAL_PIXEL_FORMAT_BGRA_8888,
-    COPYBIT_FORMAT_RGBA_5551    = HAL_PIXEL_FORMAT_RGBA_5551,
-    COPYBIT_FORMAT_RGBA_4444    = HAL_PIXEL_FORMAT_RGBA_4444,
-    COPYBIT_FORMAT_YCbCr_422_SP = 0x10,
-    COPYBIT_FORMAT_YCrCb_420_SP = 0x11,
-};
-
-/* name for copybit_set_parameter */
-enum {
-    /* rotation of the source image in degrees (0 to 359) */
-    COPYBIT_ROTATION_DEG    = 1,
-    /* plane alpha value */
-    COPYBIT_PLANE_ALPHA     = 2,
-    /* enable or disable dithering */
-    COPYBIT_DITHER          = 3,
-    /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */
-    COPYBIT_TRANSFORM       = 4,
-    /* blurs the copied bitmap. The amount of blurring cannot be changed 
-     * at this time. */
-    COPYBIT_BLUR            = 5
-};
-
-/* values for copybit_set_parameter(COPYBIT_TRANSFORM) */
-enum {
-    /* flip source image horizontally */
-    COPYBIT_TRANSFORM_FLIP_H    = HAL_TRANSFORM_FLIP_H,
-    /* flip source image vertically */
-    COPYBIT_TRANSFORM_FLIP_V    = HAL_TRANSFORM_FLIP_V,
-    /* rotate source image 90 degres */
-    COPYBIT_TRANSFORM_ROT_90    = HAL_TRANSFORM_ROT_90,
-    /* rotate source image 180 degres */
-    COPYBIT_TRANSFORM_ROT_180   = HAL_TRANSFORM_ROT_180,
-    /* rotate source image 270 degres */
-    COPYBIT_TRANSFORM_ROT_270   = HAL_TRANSFORM_ROT_270,
-};
-
-/* enable/disable value copybit_set_parameter */
-enum {
-    COPYBIT_DISABLE = 0,
-    COPYBIT_ENABLE  = 1
-};
-
-/* use get_static_info() to query static informations about the hardware */
-enum {
-    /* Maximum amount of minification supported by the hardware*/
-    COPYBIT_MINIFICATION_LIMIT  = 1,
-    /* Maximum amount of magnification supported by the hardware */
-    COPYBIT_MAGNIFICATION_LIMIT = 2,
-    /* Number of fractional bits support by the scaling engine */
-    COPYBIT_SCALING_FRAC_BITS   = 3,
-    /* Supported rotation step in degres. */
-    COPYBIT_ROTATION_STEP_DEG   = 4,
-};
-
-/* Image structure */
-struct copybit_image_t {
-    /* width */
-    uint32_t    w;
-    /* height */
-    uint32_t    h;
-    /* format COPYBIT_FORMAT_xxx */
-    int32_t     format;
-    /* base of buffer with image */
-    void        *base;
-    /* handle to the image */
-    native_handle_t* handle;
-};
-
-/* Rectangle */
-struct copybit_rect_t {
-    /* left */
-    int l;
-    /* top */
-    int t;
-    /* right */
-    int r;
-    /* bottom */
-    int b;
-};
-
-/* Region */
-struct copybit_region_t {
-    int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect);
-};
-
-/**
- * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
- * and the fields of this data structure must begin with hw_module_t
- * followed by module specific information.
- */
-struct copybit_module_t {
-    struct hw_module_t common;
-};
-
-/**
- * Every device data structure must begin with hw_device_t
- * followed by module specific public methods and attributes.
- */
-struct copybit_device_t {
-    struct hw_device_t common;
-
-    /**
-     * Set a copybit parameter.
-     *
-     * @param dev from open
-     * @param name one for the COPYBIT_NAME_xxx
-     * @param value one of the COPYBIT_VALUE_xxx
-     *
-     * @return 0 if successful
-     */
-    int (*set_parameter)(struct copybit_device_t *dev, int name, int value);
-
-    /**
-     * Get a static copybit information.
-     *
-     * @param dev from open
-     * @param name one of the COPYBIT_STATIC_xxx
-     *
-     * @return value or -EINVAL if error
-     */
-    int (*get)(struct copybit_device_t *dev, int name);
-
-    /**
-     * Execute the bit blit copy operation
-     *
-     * @param dev from open
-     * @param dst is the destination image
-     * @param src is the source image
-     * @param region the clip region
-     *
-     * @return 0 if successful
-     */
-    int (*blit)(struct copybit_device_t *dev,
-                struct copybit_image_t const *dst,
-                struct copybit_image_t const *src,
-                struct copybit_region_t const *region);
-
-    /**
-     * Execute the stretch bit blit copy operation
-     *
-     * @param dev from open
-     * @param dst is the destination image
-     * @param src is the source image
-     * @param dst_rect is the destination rectangle
-     * @param src_rect is the source rectangle
-     * @param region the clip region
-     *
-     * @return 0 if successful
-     */
-    int (*stretch)(struct copybit_device_t *dev,
-                   struct copybit_image_t const *dst,
-                   struct copybit_image_t const *src,
-                   struct copybit_rect_t const *dst_rect,
-                   struct copybit_rect_t const *src_rect,
-                   struct copybit_region_t const *region);
-};
-
-
-/** convenience API for opening and closing a device */
-
-static inline int copybit_open(const struct hw_module_t* module, 
-        struct copybit_device_t** device) {
-    return module->methods->open(module, 
-            COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device);
-}
-
-static inline int copybit_close(struct copybit_device_t* device) {
-    return device->common.close(&device->common);
-}
-
-
-__END_DECLS
-
-#endif  // ANDROID_COPYBIT_INTERFACE_H
diff --git a/include/hardware/fb.h b/include/hardware/fb.h
new file mode 100644
index 0000000..ba2f286
--- /dev/null
+++ b/include/hardware/fb.h
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_FB_INTERFACE_H
+#define ANDROID_FB_INTERFACE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <cutils/native_handle.h>
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+#define GRALLOC_HARDWARE_FB0 "fb0"
+
+/*****************************************************************************/
+
+
+/*****************************************************************************/
+
+typedef struct framebuffer_device_t {
+    struct hw_device_t common;
+
+    /* flags describing some attributes of the framebuffer */
+    const uint32_t  flags;
+
+    /* dimensions of the framebuffer in pixels */
+    const uint32_t  width;
+    const uint32_t  height;
+
+    /* frambuffer stride in pixels */
+    const int       stride;
+
+    /* framebuffer pixel format */
+    const int       format;
+
+    /* resolution of the framebuffer's display panel in pixel per inch*/
+    const float     xdpi;
+    const float     ydpi;
+
+    /* framebuffer's display panel refresh rate in frames per second */
+    const float     fps;
+
+    /* min swap interval supported by this framebuffer */
+    const int       minSwapInterval;
+
+    /* max swap interval supported by this framebuffer */
+    const int       maxSwapInterval;
+
+    int reserved[8];
+
+    /*
+     * requests a specific swap-interval (same definition than EGL)
+     *
+     * Returns 0 on success or -errno on error.
+     */
+    int (*setSwapInterval)(struct framebuffer_device_t* window,
+            int interval);
+
+    /*
+     * This hook is OPTIONAL.
+     *
+     * It is non NULL If the framebuffer driver supports "update-on-demand"
+     * and the given rectangle is the area of the screen that gets
+     * updated during (*post)().
+     *
+     * This is useful on devices that are able to DMA only a portion of
+     * the screen to the display panel, upon demand -- as opposed to
+     * constantly refreshing the panel 60 times per second, for instance.
+     *
+     * Only the area defined by this rectangle is guaranteed to be valid, that
+     * is, the driver is not allowed to post anything outside of this
+     * rectangle.
+     *
+     * The rectangle evaluated during (*post)() and specifies which area
+     * of the buffer passed in (*post)() shall to be posted.
+     *
+     * return -EINVAL if width or height <=0, or if left or top < 0
+     */
+    int (*setUpdateRect)(struct framebuffer_device_t* window,
+            int left, int top, int width, int height);
+
+    /*
+     * Post <buffer> to the display (display it on the screen)
+     * The buffer must have been allocated with the
+     *   GRALLOC_USAGE_HW_FB usage flag.
+     * buffer must be the same width and height as the display and must NOT
+     * be locked.
+     *
+     * The buffer is shown during the next VSYNC.
+     *
+     * If the same buffer is posted again (possibly after some other buffer),
+     * post() will block until the the first post is completed.
+     *
+     * Internally, post() is expected to lock the buffer so that a
+     * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or
+     * USAGE_*_WRITE will block until it is safe; that is typically once this
+     * buffer is shown and another buffer has been posted.
+     *
+     * Returns 0 on success or -errno on error.
+     */
+    int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);
+
+
+    /*
+     * The (*compositionComplete)() method must be called after the
+     * compositor has finished issuing GL commands for client buffers.
+     */
+
+    int (*compositionComplete)(struct framebuffer_device_t* dev);
+
+    /*
+     * This hook is OPTIONAL.
+     *
+     * If non NULL it will be caused by SurfaceFlinger on dumpsys
+     */
+    void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len);
+
+    /*
+     * (*enableScreen)() is used to either blank (enable=0) or
+     * unblank (enable=1) the screen this framebuffer is attached to.
+     *
+     * Returns 0 on success or -errno on error.
+     */
+    int (*enableScreen)(struct framebuffer_device_t* dev, int enable);
+
+    void* reserved_proc[6];
+
+} framebuffer_device_t;
+
+
+/** convenience API for opening and closing a supported device */
+
+static inline int framebuffer_open(const struct hw_module_t* module,
+        struct framebuffer_device_t** device) {
+    return module->methods->open(module,
+            GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device);
+}
+
+static inline int framebuffer_close(struct framebuffer_device_t* device) {
+    return device->common.close(&device->common);
+}
+
+
+__END_DECLS
+
+#endif  // ANDROID_FB_INTERFACE_H
diff --git a/include/hardware/gralloc.h b/include/hardware/gralloc.h
index 5eefe79..8ee0240 100644
--- a/include/hardware/gralloc.h
+++ b/include/hardware/gralloc.h
@@ -18,14 +18,18 @@
 #ifndef ANDROID_GRALLOC_INTERFACE_H
 #define ANDROID_GRALLOC_INTERFACE_H
 
-#include <cutils/native_handle.h>
-
+#include <system/window.h>
 #include <hardware/hardware.h>
 
 #include <stdint.h>
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+#include <cutils/native_handle.h>
+
+#include <hardware/hardware.h>
+#include <hardware/fb.h>
+
 __BEGIN_DECLS
 
 #define GRALLOC_API_VERSION 1
@@ -39,7 +43,6 @@
  * Name of the graphics device to open
  */
 
-#define GRALLOC_HARDWARE_FB0 "fb0"
 #define GRALLOC_HARDWARE_GPU0 "gpu0"
 
 enum {
@@ -95,16 +98,6 @@
 
 /*****************************************************************************/
 
-typedef const native_handle* buffer_handle_t;
-
-enum {
-    /* FIXME: this only exists to work-around some issues with
-     * the video and camera frameworks. don't implement unless
-     * you know what you're doing.
-     */
-    GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 0x080000001,
-};
-
 /**
  * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
  * and the fields of this data structure must begin with hw_module_t
@@ -247,109 +240,6 @@
 } alloc_device_t;
 
 
-typedef struct framebuffer_device_t {
-    struct hw_device_t common;
-
-    /* flags describing some attributes of the framebuffer */
-    const uint32_t  flags;
-    
-    /* dimensions of the framebuffer in pixels */
-    const uint32_t  width;
-    const uint32_t  height;
-
-    /* frambuffer stride in pixels */
-    const int       stride;
-    
-    /* framebuffer pixel format */
-    const int       format;
-    
-    /* resolution of the framebuffer's display panel in pixel per inch*/
-    const float     xdpi;
-    const float     ydpi;
-
-    /* framebuffer's display panel refresh rate in frames per second */
-    const float     fps;
-
-    /* min swap interval supported by this framebuffer */
-    const int       minSwapInterval;
-
-    /* max swap interval supported by this framebuffer */
-    const int       maxSwapInterval;
-
-    int reserved[8];
-    
-    /* 
-     * requests a specific swap-interval (same definition than EGL) 
-     * 
-     * Returns 0 on success or -errno on error.
-     */
-    int (*setSwapInterval)(struct framebuffer_device_t* window,
-            int interval);
-
-    /*
-     * This hook is OPTIONAL.
-     * 
-     * It is non NULL If the framebuffer driver supports "update-on-demand" 
-     * and the given rectangle is the area of the screen that gets 
-     * updated during (*post)().
-     * 
-     * This is useful on devices that are able to DMA only a portion of
-     * the screen to the display panel, upon demand -- as opposed to
-     * constantly refreshing the panel 60 times per second, for instance.
-     * 
-     * Only the area defined by this rectangle is guaranteed to be valid, that
-     * is, the driver is not allowed to post anything outside of this
-     * rectangle. 
-     * 
-     * The rectangle evaluated during (*post)() and specifies which area
-     * of the buffer passed in (*post)() shall to be posted.
-     * 
-     * return -EINVAL if width or height <=0, or if left or top < 0 
-     */
-    int (*setUpdateRect)(struct framebuffer_device_t* window,
-            int left, int top, int width, int height);
-    
-    /*
-     * Post <buffer> to the display (display it on the screen)
-     * The buffer must have been allocated with the 
-     *   GRALLOC_USAGE_HW_FB usage flag.
-     * buffer must be the same width and height as the display and must NOT
-     * be locked.
-     * 
-     * The buffer is shown during the next VSYNC. 
-     * 
-     * If the same buffer is posted again (possibly after some other buffer),
-     * post() will block until the the first post is completed.
-     *
-     * Internally, post() is expected to lock the buffer so that a 
-     * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or
-     * USAGE_*_WRITE will block until it is safe; that is typically once this
-     * buffer is shown and another buffer has been posted.
-     *
-     * Returns 0 on success or -errno on error.
-     */
-    int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);
-
-
-    /*
-     * The (*compositionComplete)() method must be called after the
-     * compositor has finished issuing GL commands for client buffers.
-     */
-
-    int (*compositionComplete)(struct framebuffer_device_t* dev);
-
-    /*
-     * This hook is OPTIONAL.
-     *
-     * If non NULL it will be caused by SurfaceFlinger on dumpsys
-     */
-    void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len);
-
-    void* reserved_proc[7];
-
-} framebuffer_device_t;
-
-
 /** convenience API for opening and closing a supported device */
 
 static inline int gralloc_open(const struct hw_module_t* module, 
@@ -362,18 +252,6 @@
     return device->common.close(&device->common);
 }
 
-
-static inline int framebuffer_open(const struct hw_module_t* module, 
-        struct framebuffer_device_t** device) {
-    return module->methods->open(module, 
-            GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device);
-}
-
-static inline int framebuffer_close(struct framebuffer_device_t* device) {
-    return device->common.close(&device->common);
-}
-
-
 __END_DECLS
 
 #endif  // ANDROID_ALLOC_INTERFACE_H
diff --git a/include/hardware/hardware.h b/include/hardware/hardware.h
index d9cc0dc..7774b2b 100644
--- a/include/hardware/hardware.h
+++ b/include/hardware/hardware.h
@@ -21,6 +21,7 @@
 #include <sys/cdefs.h>
 
 #include <cutils/native_handle.h>
+#include <system/graphics.h>
 
 __BEGIN_DECLS
 
@@ -113,92 +114,25 @@
 
 /**
  * Get the module info associated with a module by id.
- * @return: 0 == success, <0 == error and *pHmi == NULL
+ *
+ * @return: 0 == success, <0 == error and *module == NULL
  */
 int hw_get_module(const char *id, const struct hw_module_t **module);
 
-
 /**
- * pixel format definitions
- */
-
-enum {
-    HAL_PIXEL_FORMAT_RGBA_8888          = 1,
-    HAL_PIXEL_FORMAT_RGBX_8888          = 2,
-    HAL_PIXEL_FORMAT_RGB_888            = 3,
-    HAL_PIXEL_FORMAT_RGB_565            = 4,
-    HAL_PIXEL_FORMAT_BGRA_8888          = 5,
-    HAL_PIXEL_FORMAT_RGBA_5551          = 6,
-    HAL_PIXEL_FORMAT_RGBA_4444          = 7,
-
-    /* 0x8 - 0xFF range unavailable */
-
-    /*
-     * 0x100 - 0x1FF
-     *
-     * This range is reserved for pixel formats that are specific to the HAL
-     * implementation.  Implementations can use any value in this range to
-     * communicate video pixel formats between their HAL modules.  These formats
-     * must not have an alpha channel.  Additionally, an EGLimage created from a
-     * gralloc buffer of one of these formats must be supported for use with the
-     * GL_OES_EGL_image_external OpenGL ES extension.
-     */
-
-    /*
-     * Android YUV format:
-     *
-     * This format is exposed outside of the HAL to software
-     * decoders and applications.
-     * EGLImageKHR must support it in conjunction with the
-     * OES_EGL_image_external extension.
-     *
-     * YV12 is 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
-     * by (W/2) x (H/2) Cr and Cb planes.
-     *
-     * This format assumes
-     * - an even width
-     * - an even height
-     * - a horizontal stride multiple of 16 pixels
-     * - a vertical stride equal to the height
-     *
-     *   y_size = stride * height
-     *   c_size = ALIGN(stride/2, 16) * height/2
-     *   size = y_size + c_size * 2
-     *   cr_offset = y_size
-     *   cb_offset = y_size + c_size
-     *
-     */
-    HAL_PIXEL_FORMAT_YV12   = 0x32315659, // YCrCb 4:2:0 Planar
-
-
-
-    /* Legacy formats (deprecated), used by ImageFormat.java */
-    HAL_PIXEL_FORMAT_YCbCr_422_SP       = 0x10, // NV16
-    HAL_PIXEL_FORMAT_YCrCb_420_SP       = 0x11, // NV21
-    HAL_PIXEL_FORMAT_YCbCr_422_I        = 0x14, // YUY2
-};
-
-
-/**
- * Transformation definitions
+ * Get the module info associated with a module instance by class 'class_id'
+ * and instance 'inst'.
  *
- * IMPORTANT NOTE:
- * HAL_TRANSFORM_ROT_90 is applied CLOCKWISE and AFTER HAL_TRANSFORM_FLIP_{H|V}.
+ * Some modules types necessitate multiple instances. For example audio supports
+ * multiple concurrent interfaces and thus 'audio' is the module class
+ * and 'primary' or 'a2dp' are module interfaces. This implies that the files
+ * providing these modules would be named audio.primary.<variant>.so and
+ * audio.a2dp.<variant>.so
  *
+ * @return: 0 == success, <0 == error and *module == NULL
  */
-
-enum {
-    /* flip source image horizontally (around the vertical axis) */
-    HAL_TRANSFORM_FLIP_H    = 0x01,
-    /* flip source image vertically (around the horizontal axis)*/
-    HAL_TRANSFORM_FLIP_V    = 0x02,
-    /* rotate source image 90 degrees clockwise */
-    HAL_TRANSFORM_ROT_90    = 0x04,
-    /* rotate source image 180 degrees */
-    HAL_TRANSFORM_ROT_180   = 0x03,
-    /* rotate source image 270 degrees clockwise */
-    HAL_TRANSFORM_ROT_270   = 0x07,
-};
+int hw_get_module_by_class(const char *class_id, const char *inst,
+                           const struct hw_module_t **module);
 
 __END_DECLS
 
diff --git a/include/hardware/overlay.h b/include/hardware/overlay.h
deleted file mode 100644
index c56a974..0000000
--- a/include/hardware/overlay.h
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_OVERLAY_INTERFACE_H
-#define ANDROID_OVERLAY_INTERFACE_H
-
-#include <cutils/native_handle.h>
-
-#include <hardware/hardware.h>
-
-#include <stdint.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-__BEGIN_DECLS
-
-/**
- * The id of this module
- */
-#define OVERLAY_HARDWARE_MODULE_ID "overlay"
-
-/**
- * Name of the overlay device to open
- */
-#define OVERLAY_HARDWARE_CONTROL    "control"
-#define OVERLAY_HARDWARE_DATA       "data"
-
-/*****************************************************************************/
-
-/* possible overlay formats */
-enum {
-    OVERLAY_FORMAT_RGBA_8888    = HAL_PIXEL_FORMAT_RGBA_8888,
-    OVERLAY_FORMAT_RGB_565      = HAL_PIXEL_FORMAT_RGB_565,
-    OVERLAY_FORMAT_BGRA_8888    = HAL_PIXEL_FORMAT_BGRA_8888,
-    OVERLAY_FORMAT_YCbYCr_422_I = 0x14,
-    OVERLAY_FORMAT_CbYCrY_422_I = 0x16,
-    OVERLAY_FORMAT_DEFAULT      = 99    // The actual color format is determined
-                                        // by the overlay
-};
-
-/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
-enum {
-    /* flip source image horizontally */
-    OVERLAY_TRANSFORM_FLIP_H    = HAL_TRANSFORM_FLIP_H,
-    /* flip source image vertically */
-    OVERLAY_TRANSFORM_FLIP_V    = HAL_TRANSFORM_FLIP_V,
-    /* rotate source image 90 degrees */
-    OVERLAY_TRANSFORM_ROT_90    = HAL_TRANSFORM_ROT_90,
-    /* rotate source image 180 degrees */
-    OVERLAY_TRANSFORM_ROT_180   = HAL_TRANSFORM_ROT_180,
-    /* rotate source image 270 degrees */
-    OVERLAY_TRANSFORM_ROT_270   = HAL_TRANSFORM_ROT_270
-};
-
-/* names for setParameter() */
-enum {
-    /* rotation of the source image in degrees (0 to 359) */
-    OVERLAY_ROTATION_DEG  = 1,
-    /* enable or disable dithering */
-    OVERLAY_DITHER        = 3,
-    /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */
-    OVERLAY_TRANSFORM    = 4,
-};
-
-/* enable/disable value setParameter() */
-enum {
-    OVERLAY_DISABLE = 0,
-    OVERLAY_ENABLE  = 1
-};
-
-/* names for get() */
-enum {
-    /* Maximum amount of minification supported by the hardware*/
-    OVERLAY_MINIFICATION_LIMIT      = 1,
-    /* Maximum amount of magnification supported by the hardware */
-    OVERLAY_MAGNIFICATION_LIMIT     = 2,
-    /* Number of fractional bits support by the overlay scaling engine */
-    OVERLAY_SCALING_FRAC_BITS       = 3,
-    /* Supported rotation step in degrees. */
-    OVERLAY_ROTATION_STEP_DEG       = 4,
-    /* horizontal alignment in pixels */
-    OVERLAY_HORIZONTAL_ALIGNMENT    = 5,
-    /* vertical alignment in pixels */
-    OVERLAY_VERTICAL_ALIGNMENT      = 6,
-    /* width alignment restrictions. negative number for max. power-of-two */
-    OVERLAY_WIDTH_ALIGNMENT         = 7,
-    /* height alignment restrictions. negative number for max. power-of-two */
-    OVERLAY_HEIGHT_ALIGNMENT        = 8,
-};
-
-/*****************************************************************************/
-
-/* opaque reference to an Overlay kernel object */
-typedef const native_handle* overlay_handle_t;
-
-typedef struct overlay_t {
-    uint32_t            w;
-    uint32_t            h;
-    int32_t             format;
-    uint32_t            w_stride;
-    uint32_t            h_stride;
-    uint32_t            reserved[3];
-    /* returns a reference to this overlay's handle (the caller doesn't
-     * take ownership) */
-    overlay_handle_t    (*getHandleRef)(struct overlay_t* overlay);
-    uint32_t            reserved_procs[7];
-} overlay_t;
-
-typedef void* overlay_buffer_t;
-
-/*****************************************************************************/
-
-/**
- * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
- * and the fields of this data structure must begin with hw_module_t
- * followed by module specific information.
- */
-struct overlay_module_t {
-    struct hw_module_t common;
-};
-
-/*****************************************************************************/
-
-/**
- * Every device data structure must begin with hw_device_t
- * followed by module specific public methods and attributes.
- */
-
-struct overlay_control_device_t {
-    struct hw_device_t common;
-    
-    /* get static informations about the capabilities of the overlay engine */
-    int (*get)(struct overlay_control_device_t *dev, int name);
-
-    /* creates an overlay matching the given parameters as closely as possible.
-     * returns an error if no more overlays are available. The actual
-     * size and format is returned in overlay_t. */
-    overlay_t* (*createOverlay)(struct overlay_control_device_t *dev,
-            uint32_t w, uint32_t h, int32_t format);
-    
-    /* destroys an overlay. This call releases all
-     * resources associated with overlay_t and make it invalid */
-    void (*destroyOverlay)(struct overlay_control_device_t *dev,
-            overlay_t* overlay);
-
-    /* set position and scaling of the given overlay as closely as possible.
-     * if scaling cannot be performed, overlay must be centered. */
-    int (*setPosition)(struct overlay_control_device_t *dev,
-            overlay_t* overlay, 
-            int x, int y, uint32_t w, uint32_t h);
-
-    /* returns the actual position and size of the overlay */
-    int (*getPosition)(struct overlay_control_device_t *dev,
-            overlay_t* overlay, 
-            int* x, int* y, uint32_t* w, uint32_t* h);
-
-    /* sets configurable parameters for this overlay. returns an error if not
-     * supported. */
-    int (*setParameter)(struct overlay_control_device_t *dev,
-            overlay_t* overlay, int param, int value);
-
-    int (*stage)(struct overlay_control_device_t *dev, overlay_t* overlay);
-    int (*commit)(struct overlay_control_device_t *dev, overlay_t* overlay);
-};
-
-
-struct overlay_data_device_t {
-    struct hw_device_t common;
-
-    /* initialize the overlay from the given handle. this associates this
-     * overlay data module to its control module */
-    int (*initialize)(struct overlay_data_device_t *dev,
-            overlay_handle_t handle);
-
-    /* can be called to change the width and height of the overlay. */
-    int (*resizeInput)(struct overlay_data_device_t *dev,
-            uint32_t w, uint32_t h);
-
-    int (*setCrop)(struct overlay_data_device_t *dev,
-            uint32_t x, uint32_t y, uint32_t w, uint32_t h) ;
-
-    int (*getCrop)(struct overlay_data_device_t *dev,
-       uint32_t* x, uint32_t* y, uint32_t* w, uint32_t* h) ;
-
-    int (*setParameter)(struct overlay_data_device_t *dev,
-            int param, int value);
-
-    /* blocks until an overlay buffer is available and return that buffer. */
-    int (*dequeueBuffer)(struct overlay_data_device_t *dev,
-		         overlay_buffer_t *buf);
-
-    /* release the overlay buffer and post it */
-    int (*queueBuffer)(struct overlay_data_device_t *dev,
-            overlay_buffer_t buffer);
-
-    /* returns the address of a given buffer if supported, NULL otherwise. */
-    void* (*getBufferAddress)(struct overlay_data_device_t *dev,
-            overlay_buffer_t buffer);
-
-    int (*getBufferCount)(struct overlay_data_device_t *dev);
-};
-
-
-/*****************************************************************************/
-
-/** convenience API for opening and closing a device */
-
-static inline int overlay_control_open(const struct hw_module_t* module, 
-        struct overlay_control_device_t** device) {
-    return module->methods->open(module, 
-            OVERLAY_HARDWARE_CONTROL, (struct hw_device_t**)device);
-}
-
-static inline int overlay_control_close(struct overlay_control_device_t* device) {
-    return device->common.close(&device->common);
-}
-
-static inline int overlay_data_open(const struct hw_module_t* module, 
-        struct overlay_data_device_t** device) {
-    return module->methods->open(module, 
-            OVERLAY_HARDWARE_DATA, (struct hw_device_t**)device);
-}
-
-static inline int overlay_data_close(struct overlay_data_device_t* device) {
-    return device->common.close(&device->common);
-}
-
-__END_DECLS
-
-#endif  // ANDROID_OVERLAY_INTERFACE_H
diff --git a/include/hardware/sensors.h b/include/hardware/sensors.h
index 1dcd5fa..7819a71 100644
--- a/include/hardware/sensors.h
+++ b/include/hardware/sensors.h
@@ -56,12 +56,13 @@
 #define SENSOR_TYPE_GYROSCOPE           4
 #define SENSOR_TYPE_LIGHT               5
 #define SENSOR_TYPE_PRESSURE            6
-#define SENSOR_TYPE_TEMPERATURE         7
+#define SENSOR_TYPE_TEMPERATURE         7   // deprecated
 #define SENSOR_TYPE_PROXIMITY           8
 #define SENSOR_TYPE_GRAVITY             9
 #define SENSOR_TYPE_LINEAR_ACCELERATION 10
 #define SENSOR_TYPE_ROTATION_VECTOR     11
 #define SENSOR_TYPE_RELATIVE_HUMIDITY   12
+#define SENSOR_TYPE_AMBIENT_TEMPERATURE 13
 
 /**
  * Values returned by the accelerometer in various locations in the universe.
@@ -268,6 +269,18 @@
  * Elements of the rotation vector are unitless.  The x, y, and z axis are defined
  * in the same was as for the acceleration sensor.
  *
+ * The reference coordinate system is defined as a direct orthonormal basis,
+ * where:
+ *
+ * - X is defined as the vector product Y.Z (It is tangential to
+ * the ground at the device's current location and roughly points East).
+ *
+ * - Y is tangential to the ground at the device's current location and
+ * points towards the magnetic North Pole.
+ *
+ * - Z points towards the sky and is perpendicular to the ground.
+ *
+ *
  * The rotation-vector is stored as:
  *
  *   sensors_event_t.data[0] = x*sin(theta/2)
@@ -275,6 +288,7 @@
  *   sensors_event_t.data[2] = z*sin(theta/2)
  *   sensors_event_t.data[3] =   cos(theta/2)
  *
+ *
  * Relative Humidity
  * -----------------
  *
@@ -283,6 +297,16 @@
  *
  * Relative humidity sensors report a value only when it changes and each
  * time the sensor is enabled. setDelay() is ignored.
+ *
+ *
+ * Ambient Temperature
+ * -------------------
+ *
+ * The ambient (room) temperature in degree Celsius.
+ *
+ * Temperature sensors report a value only when it changes and each time the
+ * sensor is enabled. setDelay() is ignored.
+ *
  */
 
 typedef struct {
@@ -462,6 +486,4 @@
 
 __END_DECLS
 
-#include <hardware/sensors_deprecated.h>
-
 #endif  // ANDROID_SENSORS_INTERFACE_H
diff --git a/include/hardware/sensors_deprecated.h b/include/hardware/sensors_deprecated.h
deleted file mode 100644
index ee667d6..0000000
--- a/include/hardware/sensors_deprecated.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define SENSORS_HARDWARE_CONTROL    "control"
-#define SENSORS_HARDWARE_DATA       "data"
-
-__BEGIN_DECLS
-
-typedef struct {
-    int             sensor;
-    union {
-        sensors_vec_t   vector;
-        sensors_vec_t   orientation;
-        sensors_vec_t   acceleration;
-        sensors_vec_t   magnetic;
-        float           temperature;
-        float           distance;
-        float           light;
-        float           pressure;
-    };
-    int64_t         time;
-    uint32_t        reserved;
-} sensors_data_t;
-
-struct sensors_control_device_t {
-    struct hw_device_t common;
-    native_handle_t* (*open_data_source)(struct sensors_control_device_t *dev);
-    int (*close_data_source)(struct sensors_control_device_t *dev);
-    int (*activate)(struct sensors_control_device_t *dev, 
-            int handle, int enabled);
-    int (*set_delay)(struct sensors_control_device_t *dev, int32_t ms);
-    int (*wake)(struct sensors_control_device_t *dev);
-};
-
-struct sensors_data_device_t {
-    struct hw_device_t common;
-    int (*data_open)(struct sensors_data_device_t *dev, native_handle_t* nh);
-    int (*data_close)(struct sensors_data_device_t *dev);
-    int (*poll)(struct sensors_data_device_t *dev, 
-            sensors_data_t* data);
-};
-
-static inline int sensors_control_open(const struct hw_module_t* module, 
-        struct sensors_control_device_t** device) {
-    return module->methods->open(module, 
-            SENSORS_HARDWARE_CONTROL, (struct hw_device_t**)device);
-}
-
-static inline int sensors_control_close(struct sensors_control_device_t* device) {
-    return device->common.close(&device->common);
-}
-
-static inline int sensors_data_open(const struct hw_module_t* module, 
-        struct sensors_data_device_t** device) {
-    return module->methods->open(module, 
-            SENSORS_HARDWARE_DATA, (struct hw_device_t**)device);
-}
-
-static inline int sensors_data_close(struct sensors_data_device_t* device) {
-    return device->common.close(&device->common);
-}
-
-__END_DECLS
diff --git a/modules/Android.mk b/modules/Android.mk
new file mode 100644
index 0000000..04b9140
--- /dev/null
+++ b/modules/Android.mk
@@ -0,0 +1,2 @@
+hardware_modules := gralloc hwcomposer audio
+include $(call all-named-subdir-makefiles,$(hardware_modules))
diff --git a/modules/audio/Android.mk b/modules/audio/Android.mk
new file mode 100644
index 0000000..f773079
--- /dev/null
+++ b/modules/audio/Android.mk
@@ -0,0 +1,43 @@
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+# The default audio HAL module, which is a stub, that is loaded if no other
+# device specific modules are present. The exact load order can be seen in
+# libhardware/hardware.c
+#
+# The format of the name is audio.<type>.<hardware/etc>.so where the only
+# required type is 'primary'. Other possibilites are 'a2dp', 'usb', etc.
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := audio.primary.default
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_SRC_FILES := audio_hw.c
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
+
+# The stub audio policy HAL module that can be used as a skeleton for
+# new implementations.
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := audio_policy.stub
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_SRC_FILES := audio_policy.c
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/audio/audio_hw.c b/modules/audio/audio_hw.c
new file mode 100644
index 0000000..b3ab1e2
--- /dev/null
+++ b/modules/audio/audio_hw.c
@@ -0,0 +1,412 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "audio_hw_default"
+//#define LOG_NDEBUG 0
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <sys/time.h>
+
+#include <cutils/log.h>
+
+#include <hardware/hardware.h>
+#include <system/audio.h>
+#include <hardware/audio_hal.h>
+
+struct stub_audio_device {
+    struct audio_hw_device device;
+};
+
+struct stub_stream_out {
+    struct audio_stream_out stream;
+};
+
+struct stub_stream_in {
+    struct audio_stream_in stream;
+};
+
+static uint32_t out_get_sample_rate(const struct audio_stream *stream)
+{
+    return 44100;
+}
+
+static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
+{
+    return 0;
+}
+
+static size_t out_get_buffer_size(const struct audio_stream *stream)
+{
+    return 4096;
+}
+
+static uint32_t out_get_channels(const struct audio_stream *stream)
+{
+    return AUDIO_CHANNEL_OUT_STEREO;
+}
+
+static int out_get_format(const struct audio_stream *stream)
+{
+    return AUDIO_FORMAT_PCM_16_BIT;
+}
+
+static int out_set_format(struct audio_stream *stream, int format)
+{
+    return 0;
+}
+
+static int out_standby(struct audio_stream *stream)
+{
+    return 0;
+}
+
+static int out_dump(const struct audio_stream *stream, int fd)
+{
+    return 0;
+}
+
+static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
+{
+    return 0;
+}
+
+static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
+{
+    return strdup("");
+}
+
+static uint32_t out_get_latency(const struct audio_stream_out *stream)
+{
+    return 0;
+}
+
+static int out_set_volume(struct audio_stream_out *stream, float left,
+                          float right)
+{
+    return 0;
+}
+
+static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
+                         size_t bytes)
+{
+    /* XXX: fake timing for audio output */
+    usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
+           out_get_sample_rate(&stream->common));
+    return bytes;
+}
+
+static int out_get_render_position(const struct audio_stream_out *stream,
+                                   uint32_t *dsp_frames)
+{
+    return -EINVAL;
+}
+
+/** audio_stream_in implementation **/
+static uint32_t in_get_sample_rate(const struct audio_stream *stream)
+{
+    return 8000;
+}
+
+static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
+{
+    return 0;
+}
+
+static size_t in_get_buffer_size(const struct audio_stream *stream)
+{
+    return 320;
+}
+
+static uint32_t in_get_channels(const struct audio_stream *stream)
+{
+    return AUDIO_CHANNEL_IN_MONO;
+}
+
+static int in_get_format(const struct audio_stream *stream)
+{
+    return AUDIO_FORMAT_PCM_16_BIT;
+}
+
+static int in_set_format(struct audio_stream *stream, int format)
+{
+    return 0;
+}
+
+static int in_standby(struct audio_stream *stream)
+{
+    return 0;
+}
+
+static int in_dump(const struct audio_stream *stream, int fd)
+{
+    return 0;
+}
+
+static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
+{
+    return 0;
+}
+
+static char * in_get_parameters(const struct audio_stream *stream,
+                                const char *keys)
+{
+    return strdup("");
+}
+
+static int in_set_gain(struct audio_stream_in *stream, float gain)
+{
+    return 0;
+}
+
+static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
+                       size_t bytes)
+{
+    /* XXX: fake timing for audio input */
+    usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
+           in_get_sample_rate(&stream->common));
+    return bytes;
+}
+
+static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
+{
+    return 0;
+}
+
+
+static int adev_open_output_stream(struct audio_hw_device *dev,
+                                   uint32_t devices, int *format,
+                                   uint32_t *channels, uint32_t *sample_rate,
+                                   struct audio_stream_out **stream_out)
+{
+    struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
+    struct stub_stream_out *out;
+    int ret;
+
+    out = (struct stub_stream_out *)calloc(1, sizeof(struct stub_stream_out));
+    if (!out)
+        return -ENOMEM;
+
+    out->stream.common.get_sample_rate = out_get_sample_rate;
+    out->stream.common.set_sample_rate = out_set_sample_rate;
+    out->stream.common.get_buffer_size = out_get_buffer_size;
+    out->stream.common.get_channels = out_get_channels;
+    out->stream.common.get_format = out_get_format;
+    out->stream.common.set_format = out_set_format;
+    out->stream.common.standby = out_standby;
+    out->stream.common.dump = out_dump;
+    out->stream.common.set_parameters = out_set_parameters;
+    out->stream.common.get_parameters = out_get_parameters;
+    out->stream.get_latency = out_get_latency;
+    out->stream.set_volume = out_set_volume;
+    out->stream.write = out_write;
+    out->stream.get_render_position = out_get_render_position;
+
+    *stream_out = &out->stream;
+    return 0;
+
+err_open:
+    free(out);
+    *stream_out = NULL;
+    return ret;
+}
+
+static void adev_close_output_stream(struct audio_hw_device *dev,
+                                     struct audio_stream_out *stream)
+{
+    free(stream);
+}
+
+static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
+{
+    return -ENOSYS;
+}
+
+static char * adev_get_parameters(const struct audio_hw_device *dev,
+                                  const char *keys)
+{
+    return NULL;
+}
+
+static int adev_init_check(const struct audio_hw_device *dev)
+{
+    return 0;
+}
+
+static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
+{
+    return -ENOSYS;
+}
+
+static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
+{
+    return -ENOSYS;
+}
+
+static int adev_set_mode(struct audio_hw_device *dev, int mode)
+{
+    return 0;
+}
+
+static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
+{
+    return -ENOSYS;
+}
+
+static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
+{
+    return -ENOSYS;
+}
+
+static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
+                                         uint32_t sample_rate, int format,
+                                         int channel_count)
+{
+    return 320;
+}
+
+static int adev_open_input_stream(struct audio_hw_device *dev, uint32_t devices,
+                                  int *format, uint32_t *channels,
+                                  uint32_t *sample_rate,
+                                  audio_in_acoustics_t acoustics,
+                                  struct audio_stream_in **stream_in)
+{
+    struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
+    struct stub_stream_in *in;
+    int ret;
+
+    in = (struct stub_stream_in *)calloc(1, sizeof(struct stub_stream_in));
+    if (!in)
+        return -ENOMEM;
+
+    in->stream.common.get_sample_rate = in_get_sample_rate;
+    in->stream.common.set_sample_rate = in_set_sample_rate;
+    in->stream.common.get_buffer_size = in_get_buffer_size;
+    in->stream.common.get_channels = in_get_channels;
+    in->stream.common.get_format = in_get_format;
+    in->stream.common.set_format = in_set_format;
+    in->stream.common.standby = in_standby;
+    in->stream.common.dump = in_dump;
+    in->stream.common.set_parameters = in_set_parameters;
+    in->stream.common.get_parameters = in_get_parameters;
+    in->stream.set_gain = in_set_gain;
+    in->stream.read = in_read;
+    in->stream.get_input_frames_lost = in_get_input_frames_lost;
+
+    *stream_in = &in->stream;
+    return 0;
+
+err_open:
+    free(in);
+    *stream_in = NULL;
+    return ret;
+}
+
+static void adev_close_input_stream(struct audio_hw_device *dev,
+                                   struct audio_stream_in *in)
+{
+    return;
+}
+
+static int adev_dump(const audio_hw_device_t *device, int fd)
+{
+    return 0;
+}
+
+static int adev_close(hw_device_t *device)
+{
+    free(device);
+    return 0;
+}
+
+static uint32_t adev_get_supported_devices(const struct audio_hw_device *dev)
+{
+    return (/* OUT */
+            AUDIO_DEVICE_OUT_EARPIECE |
+            AUDIO_DEVICE_OUT_SPEAKER |
+            AUDIO_DEVICE_OUT_WIRED_HEADSET |
+            AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
+            AUDIO_DEVICE_OUT_AUX_DIGITAL |
+            AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
+            AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
+            AUDIO_DEVICE_OUT_ALL_SCO |
+            AUDIO_DEVICE_OUT_DEFAULT |
+            /* IN */
+            AUDIO_DEVICE_IN_COMMUNICATION |
+            AUDIO_DEVICE_IN_AMBIENT |
+            AUDIO_DEVICE_IN_BUILTIN_MIC |
+            AUDIO_DEVICE_IN_WIRED_HEADSET |
+            AUDIO_DEVICE_IN_AUX_DIGITAL |
+            AUDIO_DEVICE_IN_BACK_MIC |
+            AUDIO_DEVICE_IN_ALL_SCO |
+            AUDIO_DEVICE_IN_DEFAULT);
+}
+
+static int adev_open(const hw_module_t* module, const char* name,
+                     hw_device_t** device)
+{
+    struct stub_audio_device *adev;
+    int ret;
+
+    if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
+        return -EINVAL;
+
+    adev = calloc(1, sizeof(struct stub_audio_device));
+    if (!adev)
+        return -ENOMEM;
+
+    adev->device.common.tag = HARDWARE_DEVICE_TAG;
+    adev->device.common.version = 0;
+    adev->device.common.module = (struct hw_module_t *) module;
+    adev->device.common.close = adev_close;
+
+    adev->device.get_supported_devices = adev_get_supported_devices;
+    adev->device.init_check = adev_init_check;
+    adev->device.set_voice_volume = adev_set_voice_volume;
+    adev->device.set_master_volume = adev_set_master_volume;
+    adev->device.set_mode = adev_set_mode;
+    adev->device.set_mic_mute = adev_set_mic_mute;
+    adev->device.get_mic_mute = adev_get_mic_mute;
+    adev->device.set_parameters = adev_set_parameters;
+    adev->device.get_parameters = adev_get_parameters;
+    adev->device.get_input_buffer_size = adev_get_input_buffer_size;
+    adev->device.open_output_stream = adev_open_output_stream;
+    adev->device.close_output_stream = adev_close_output_stream;
+    adev->device.open_input_stream = adev_open_input_stream;
+    adev->device.close_input_stream = adev_close_input_stream;
+    adev->device.dump = adev_dump;
+
+    *device = &adev->device.common;
+
+    return 0;
+}
+
+static struct hw_module_methods_t hal_module_methods = {
+    .open = adev_open,
+};
+
+struct audio_module HAL_MODULE_INFO_SYM = {
+    .common = {
+        .tag = HARDWARE_MODULE_TAG,
+        .version_major = 1,
+        .version_minor = 0,
+        .id = AUDIO_HARDWARE_MODULE_ID,
+        .name = "Default audio HW HAL",
+        .author = "The Android Open Source Project",
+        .methods = &hal_module_methods,
+    },
+};
diff --git a/modules/audio/audio_policy.c b/modules/audio/audio_policy.c
new file mode 100644
index 0000000..8afef5f
--- /dev/null
+++ b/modules/audio/audio_policy.c
@@ -0,0 +1,318 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "audio_policy_default"
+//#define LOG_NDEBUG 0
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <hardware/hardware.h>
+#include <system/audio.h>
+#include <hardware/audio_policy.h>
+#include <hardware/audio_policy_hal.h>
+
+struct default_ap_module {
+    struct audio_policy_module module;
+};
+
+struct default_ap_device {
+    struct audio_policy_device device;
+};
+
+struct default_audio_policy {
+    struct audio_policy policy;
+
+    struct audio_policy_service_ops *aps_ops;
+    void *service;
+};
+
+static int ap_set_device_connection_state(struct audio_policy *pol,
+                                          audio_devices_t device,
+                                          audio_policy_dev_state_t state,
+                                          const char *device_address)
+{
+    return -ENOSYS;
+}
+
+static audio_policy_dev_state_t ap_get_device_connection_state(
+                                            const struct audio_policy *pol,
+                                            audio_devices_t device,
+                                            const char *device_address)
+{
+    return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
+}
+
+static void ap_set_phone_state(struct audio_policy *pol, int state)
+{
+}
+
+static void ap_set_ringer_mode(struct audio_policy *pol, uint32_t mode,
+                               uint32_t mask)
+{
+}
+
+static void ap_set_force_use(struct audio_policy *pol,
+                          audio_policy_force_use_t usage,
+                          audio_policy_forced_cfg_t config)
+{
+}
+
+    /* retreive current device category forced for a given usage */
+static audio_policy_forced_cfg_t ap_get_force_use(
+                                               const struct audio_policy *pol,
+                                               audio_policy_force_use_t usage)
+{
+    return AUDIO_POLICY_FORCE_NONE;
+}
+
+/* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE
+ * can still be muted. */
+static void ap_set_can_mute_enforced_audible(struct audio_policy *pol,
+                                             bool can_mute)
+{
+}
+
+static int ap_init_check(const struct audio_policy *pol)
+{
+    return 0;
+}
+
+static audio_io_handle_t ap_get_output(struct audio_policy *pol,
+                                       audio_stream_type_t stream,
+                                       uint32_t sampling_rate,
+                                       uint32_t format,
+                                       uint32_t channels,
+                                       audio_policy_output_flags_t flags)
+{
+    return 0;
+}
+
+static int ap_start_output(struct audio_policy *pol, audio_io_handle_t output,
+                           audio_stream_type_t stream, int session)
+{
+    return -ENOSYS;
+}
+
+static int ap_stop_output(struct audio_policy *pol, audio_io_handle_t output,
+                          audio_stream_type_t stream, int session)
+{
+    return -ENOSYS;
+}
+
+static void ap_release_output(struct audio_policy *pol,
+                              audio_io_handle_t output)
+{
+}
+
+static audio_io_handle_t ap_get_input(struct audio_policy *pol, int inputSource,
+                                      uint32_t sampling_rate,
+                                      uint32_t format,
+                                      uint32_t channels,
+                                      audio_in_acoustics_t acoustics)
+{
+    return 0;
+}
+
+static int ap_start_input(struct audio_policy *pol, audio_io_handle_t input)
+{
+    return -ENOSYS;
+}
+
+static int ap_stop_input(struct audio_policy *pol, audio_io_handle_t input)
+{
+    return -ENOSYS;
+}
+
+static void ap_release_input(struct audio_policy *pol, audio_io_handle_t input)
+{
+}
+
+static void ap_init_stream_volume(struct audio_policy *pol,
+                                  audio_stream_type_t stream, int index_min,
+                                  int index_max)
+{
+}
+
+static int ap_set_stream_volume_index(struct audio_policy *pol,
+                                      audio_stream_type_t stream,
+                                      int index)
+{
+    return -ENOSYS;
+}
+
+static int ap_get_stream_volume_index(const struct audio_policy *pol,
+                                      audio_stream_type_t stream,
+                                      int *index)
+{
+    return -ENOSYS;
+}
+
+static uint32_t ap_get_strategy_for_stream(const struct audio_policy *pol,
+                                           audio_stream_type_t stream)
+{
+    return 0;
+}
+
+static uint32_t ap_get_devices_for_stream(const struct audio_policy *pol,
+                                          audio_stream_type_t stream)
+{
+    return 0;
+}
+
+static audio_io_handle_t ap_get_output_for_effect(struct audio_policy *pol,
+                                            struct effect_descriptor_s *desc)
+{
+    return 0;
+}
+
+static int ap_register_effect(struct audio_policy *pol,
+                              struct effect_descriptor_s *desc,
+                              audio_io_handle_t output,
+                              uint32_t strategy,
+                              int session,
+                              int id)
+{
+    return -ENOSYS;
+}
+
+static int ap_unregister_effect(struct audio_policy *pol, int id)
+{
+    return -ENOSYS;
+}
+
+static bool ap_is_stream_active(const struct audio_policy *pol, int stream,
+                                uint32_t in_past_ms)
+{
+    return false;
+}
+
+static int ap_dump(const struct audio_policy *pol, int fd)
+{
+    return -ENOSYS;
+}
+
+static int create_default_ap(const struct audio_policy_device *device,
+                             struct audio_policy_service_ops *aps_ops,
+                             void *service,
+                             struct audio_policy **ap)
+{
+    struct default_ap_device *dev;
+    struct default_audio_policy *dap;
+    int ret;
+
+    *ap = NULL;
+
+    if (!service || !aps_ops)
+        return -EINVAL;
+
+    dap = (struct default_audio_policy *)calloc(1, sizeof(*dap));
+    if (!dap)
+        return -ENOMEM;
+
+    dap->policy.set_device_connection_state = ap_set_device_connection_state;
+    dap->policy.get_device_connection_state = ap_get_device_connection_state;
+    dap->policy.set_phone_state = ap_set_phone_state;
+    dap->policy.set_ringer_mode = ap_set_ringer_mode;
+    dap->policy.set_force_use = ap_set_force_use;
+    dap->policy.get_force_use = ap_get_force_use;
+    dap->policy.set_can_mute_enforced_audible =
+        ap_set_can_mute_enforced_audible;
+    dap->policy.init_check = ap_init_check;
+    dap->policy.get_output = ap_get_output;
+    dap->policy.start_output = ap_start_output;
+    dap->policy.stop_output = ap_stop_output;
+    dap->policy.release_output = ap_release_output;
+    dap->policy.get_input = ap_get_input;
+    dap->policy.start_input = ap_start_input;
+    dap->policy.stop_input = ap_stop_input;
+    dap->policy.release_input = ap_release_input;
+    dap->policy.init_stream_volume = ap_init_stream_volume;
+    dap->policy.set_stream_volume_index = ap_set_stream_volume_index;
+    dap->policy.get_stream_volume_index = ap_get_stream_volume_index;
+    dap->policy.get_strategy_for_stream = ap_get_strategy_for_stream;
+    dap->policy.get_devices_for_stream = ap_get_devices_for_stream;
+    dap->policy.get_output_for_effect = ap_get_output_for_effect;
+    dap->policy.register_effect = ap_register_effect;
+    dap->policy.unregister_effect = ap_unregister_effect;
+    dap->policy.is_stream_active = ap_is_stream_active;
+    dap->policy.dump = ap_dump;
+
+    dap->service = service;
+    dap->aps_ops = aps_ops;
+
+    *ap = &dap->policy;
+    return 0;
+}
+
+static int destroy_default_ap(const struct audio_policy_device *ap_dev,
+                              struct audio_policy *ap)
+{
+    free(ap);
+    return 0;
+}
+
+static int default_ap_dev_close(hw_device_t* device)
+{
+    free(device);
+    return 0;
+}
+
+static int default_ap_dev_open(const hw_module_t* module, const char* name,
+                               hw_device_t** device)
+{
+    struct default_ap_device *dev;
+
+    *device = NULL;
+
+    if (strcmp(name, AUDIO_POLICY_INTERFACE) != 0)
+        return -EINVAL;
+
+    dev = (struct default_ap_device *)calloc(1, sizeof(*dev));
+    if (!dev)
+        return -ENOMEM;
+
+    dev->device.common.tag = HARDWARE_DEVICE_TAG;
+    dev->device.common.version = 0;
+    dev->device.common.module = (hw_module_t *)module;
+    dev->device.common.close = default_ap_dev_close;
+    dev->device.create_audio_policy = create_default_ap;
+    dev->device.destroy_audio_policy = destroy_default_ap;
+
+    *device = &dev->device.common;
+
+    return 0;
+}
+
+static struct hw_module_methods_t default_ap_module_methods = {
+    .open = default_ap_dev_open,
+};
+
+struct default_ap_module HAL_MODULE_INFO_SYM = {
+    .module = {
+        .common = {
+            .tag            = HARDWARE_MODULE_TAG,
+            .version_major  = 1,
+            .version_minor  = 0,
+            .id             = AUDIO_POLICY_HARDWARE_MODULE_ID,
+            .name           = "Default audio policy HAL",
+            .author         = "The Android Open Source Project",
+            .methods        = &default_ap_module_methods,
+        },
+    },
+};
diff --git a/modules/gralloc/Android.mk b/modules/gralloc/Android.mk
index cbfd82b..1e1e05f 100644
--- a/modules/gralloc/Android.mk
+++ b/modules/gralloc/Android.mk
@@ -15,10 +15,10 @@
 
 LOCAL_PATH := $(call my-dir)
 
-# HAL module implemenation, not prelinked and stored in
+# HAL module implemenation stored in
 # hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
 include $(CLEAR_VARS)
-LOCAL_PRELINK_MODULE := false
+
 LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
 LOCAL_SHARED_LIBRARIES := liblog libcutils
 
diff --git a/modules/hwcomposer/Android.mk b/modules/hwcomposer/Android.mk
index 233059b..f1e819b 100644
--- a/modules/hwcomposer/Android.mk
+++ b/modules/hwcomposer/Android.mk
@@ -15,13 +15,14 @@
 
 LOCAL_PATH := $(call my-dir)
 
-# HAL module implemenation, not prelinked and stored in
+# HAL module implemenation stored in
 # hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
 include $(CLEAR_VARS)
-LOCAL_PRELINK_MODULE := false
+
 LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
 LOCAL_SHARED_LIBRARIES := liblog libEGL
 LOCAL_SRC_FILES := hwcomposer.cpp
 LOCAL_MODULE := hwcomposer.default
 LOCAL_CFLAGS:= -DLOG_TAG=\"hwcomposer\"
+LOCAL_MODULE_TAGS := optional
 include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/hwcomposer/hwcomposer.cpp b/modules/hwcomposer/hwcomposer.cpp
index 939210b..68b7070 100644
--- a/modules/hwcomposer/hwcomposer.cpp
+++ b/modules/hwcomposer/hwcomposer.cpp
@@ -15,7 +15,6 @@
  */
 
 #include <hardware/hardware.h>
-#include <hardware/overlay.h>
 
 #include <fcntl.h>
 #include <errno.h>
diff --git a/modules/overlay/Android.mk b/modules/overlay/Android.mk
index 8b7db26..a2fa0bb 100644
--- a/modules/overlay/Android.mk
+++ b/modules/overlay/Android.mk
@@ -15,10 +15,10 @@
 
 LOCAL_PATH := $(call my-dir)
 
-# HAL module implemenation, not prelinked and stored in
+# HAL module implemenation stored in
 # hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
 include $(CLEAR_VARS)
-LOCAL_PRELINK_MODULE := false
+
 LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
 LOCAL_SHARED_LIBRARIES := liblog
 LOCAL_SRC_FILES := overlay.cpp