Merge "HWComposer: update the hwc_layer::handle docs"
diff --git a/hardware.c b/hardware.c
index 3a5b9df..1f831cb 100644
--- a/hardware.c
+++ b/hardware.c
@@ -74,7 +74,7 @@
     handle = dlopen(path, RTLD_NOW);
     if (handle == NULL) {
         char const *err_str = dlerror();
-        LOGE("load: module=%s\n%s", path, err_str?err_str:"unknown");
+        ALOGE("load: module=%s\n%s", path, err_str?err_str:"unknown");
         status = -EINVAL;
         goto done;
     }
@@ -83,14 +83,14 @@
     const char *sym = HAL_MODULE_INFO_SYM_AS_STR;
     hmi = (struct hw_module_t *)dlsym(handle, sym);
     if (hmi == NULL) {
-        LOGE("load: couldn't find symbol %s", sym);
+        ALOGE("load: couldn't find symbol %s", sym);
         status = -EINVAL;
         goto done;
     }
 
     /* Check that the id matches */
     if (strcmp(id, hmi->id) != 0) {
-        LOGE("load: id=%s != hmi->id=%s", id, hmi->id);
+        ALOGE("load: id=%s != hmi->id=%s", id, hmi->id);
         status = -EINVAL;
         goto done;
     }
diff --git a/include/hardware/audio.h b/include/hardware/audio.h
index 2d7f39d..1e68cd1 100644
--- a/include/hardware/audio.h
+++ b/include/hardware/audio.h
@@ -102,12 +102,12 @@
     /**
      * audio format - eg. AUDIO_FORMAT_PCM_16_BIT
      */
-    int (*get_format)(const struct audio_stream *stream);
+    audio_format_t (*get_format)(const struct audio_stream *stream);
 
     /* currently unused - use set_parameters with key
      *     AUDIO_PARAMETER_STREAM_FORMAT
      */
-    int (*set_format)(struct audio_stream *stream, int format);
+    int (*set_format)(struct audio_stream *stream, audio_format_t format);
 
     /**
      * Put the audio hardware input/output into standby mode.
@@ -184,6 +184,14 @@
      */
     int (*get_render_position)(const struct audio_stream_out *stream,
                                uint32_t *dsp_frames);
+
+    /**
+     * get the local time at which the next write to the audio driver will be
+     * presented
+     */
+    int (*get_next_write_timestamp)(const struct audio_stream_out *stream,
+                                    int64_t *timestamp);
+
 };
 typedef struct audio_stream_out audio_stream_out_t;
 
@@ -215,9 +223,9 @@
 /**
  * return the frame size (number of bytes per sample).
  */
-static inline uint32_t audio_stream_frame_size(struct audio_stream *s)
+static inline size_t audio_stream_frame_size(struct audio_stream *s)
 {
-    int chan_samp_sz;
+    size_t chan_samp_sz;
 
     switch (s->get_format(s)) {
     case AUDIO_FORMAT_PCM_16_BIT:
@@ -272,11 +280,20 @@
     int (*set_master_volume)(struct audio_hw_device *dev, float volume);
 
     /**
-     * setMode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
+     * Get the current master volume value for the HAL, if the HAL supports
+     * master volume control.  AudioFlinger will query this value from the
+     * primary audio HAL when the service starts and use the value for setting
+     * the initial master volume across all HALs.  HALs which do not support
+     * this method should may leave it set to NULL.
+     */
+    int (*get_master_volume)(struct audio_hw_device *dev, float *volume);
+
+    /**
+     * set_mode 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);
+    int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode);
 
     /* mic mute */
     int (*set_mic_mute)(struct audio_hw_device *dev, bool state);
@@ -296,12 +313,12 @@
      * 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,
+                                    uint32_t sample_rate, audio_format_t 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,
+                              audio_format_t *format, uint32_t *channels,
                               uint32_t *sample_rate,
                               struct audio_stream_out **out);
 
@@ -310,7 +327,7 @@
 
     /** 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,
+                             audio_format_t *format, uint32_t *channels,
                              uint32_t *sample_rate,
                              audio_in_acoustics_t acoustics,
                              struct audio_stream_in **stream_in);
diff --git a/include/hardware/audio_effect.h b/include/hardware/audio_effect.h
index 5adab12..39cbf83 100644
--- a/include/hardware/audio_effect.h
+++ b/include/hardware/audio_effect.h
@@ -111,19 +111,19 @@
 //  |                           |           | 1 requires device updates
 //  |                           |           | 2, 4 reserved
 //  +---------------------------+-----------+-----------------------------------
-//  | Sample input mode         | 12..13    | 1 direct: process() function or EFFECT_CMD_CONFIGURE
+//  | Sample input mode         | 12..13    | 1 direct: process() function or EFFECT_CMD_SET_CONFIG
 //  |                           |           |   command must specify a buffer descriptor
 //  |                           |           | 2 provider: process() function uses the
 //  |                           |           |   bufferProvider indicated by the
-//  |                           |           |   EFFECT_CMD_CONFIGURE command to request input.
+//  |                           |           |   EFFECT_CMD_SET_CONFIG command to request input.
 //  |                           |           |   buffers.
 //  |                           |           | 3 both: both input modes are supported
 //  +---------------------------+-----------+-----------------------------------
-//  | Sample output mode        | 14..15    | 1 direct: process() function or EFFECT_CMD_CONFIGURE
+//  | Sample output mode        | 14..15    | 1 direct: process() function or EFFECT_CMD_SET_CONFIG
 //  |                           |           |   command must specify a buffer descriptor
 //  |                           |           | 2 provider: process() function uses the
 //  |                           |           |   bufferProvider indicated by the
-//  |                           |           |   EFFECT_CMD_CONFIGURE command to request output
+//  |                           |           |   EFFECT_CMD_SET_CONFIG command to request output
 //  |                           |           |   buffers.
 //  |                           |           | 3 both: both output modes are supported
 //  +---------------------------+-----------+-----------------------------------
@@ -269,7 +269,7 @@
     //          (count and location) in input buffer descriptor and output processed
     //          samples as specified in output buffer descriptor. If the buffer descriptor
     //          is not specified the function must use either the buffer or the
-    //          buffer provider function installed by the EFFECT_CMD_CONFIGURE command.
+    //          buffer provider function installed by the EFFECT_CMD_SET_CONFIG command.
     //          The effect framework will call the process() function after the EFFECT_CMD_ENABLE
     //          command is received and until the EFFECT_CMD_DISABLE is received. When the engine
     //          receives the EFFECT_CMD_DISABLE command it should turn off the effect gracefully
@@ -284,10 +284,10 @@
     //          self:       handle to the effect interface this function
     //              is called on.
     //          inBuffer:   buffer descriptor indicating where to read samples to process.
-    //              If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE command.
+    //              If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG command.
     //
     //          outBuffer:   buffer descriptor indicating where to write processed samples.
-    //              If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE command.
+    //              If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG command.
     //
     //    Output:
     //        returned value:    0 successful operation
@@ -369,12 +369,12 @@
     //          self:       handle to the effect interface this function
     //              is called on.
     //          inBuffer:   buffer descriptor indicating where to read samples to process.
-    //              If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE_REVERSE command.
+    //              If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG_REVERSE command.
     //
     //          outBuffer:   buffer descriptor indicating where to write processed samples.
-    //              If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE_REVERSE command.
+    //              If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG_REVERSE command.
     //              If the buffer and buffer provider in the configuration received by
-    //              EFFECT_CMD_CONFIGURE_REVERSE are also NULL, do not return modified reverse
+    //              EFFECT_CMD_SET_CONFIG_REVERSE are also NULL, do not return modified reverse
     //              stream data
     //
     //    Output:
@@ -395,7 +395,7 @@
 //
 enum effect_command_e {
    EFFECT_CMD_INIT,                 // initialize effect engine
-   EFFECT_CMD_CONFIGURE,            // configure effect engine (see effect_config_t)
+   EFFECT_CMD_SET_CONFIG,           // configure effect engine (see effect_config_t)
    EFFECT_CMD_RESET,                // reset effect engine
    EFFECT_CMD_ENABLE,               // enable effect process
    EFFECT_CMD_DISABLE,              // disable effect process
@@ -406,8 +406,13 @@
    EFFECT_CMD_SET_DEVICE,           // set audio device (see audio.h, audio_devices_t)
    EFFECT_CMD_SET_VOLUME,           // set volume
    EFFECT_CMD_SET_AUDIO_MODE,       // set the audio mode (normal, ring, ...)
-   EFFECT_CMD_CONFIGURE_REVERSE,    // configure effect engine reverse stream(see effect_config_t)
+   EFFECT_CMD_SET_CONFIG_REVERSE,   // configure effect engine reverse stream(see effect_config_t)
    EFFECT_CMD_SET_INPUT_DEVICE,     // set capture device (see audio.h, audio_devices_t)
+   EFFECT_CMD_GET_CONFIG,           // read effect engine configuration
+   EFFECT_CMD_GET_CONFIG_REVERSE,   // read configure effect engine reverse stream configuration
+   EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS,// get all supported configurations for a feature.
+   EFFECT_CMD_GET_FEATURE_CONFIG,   // get current feature configuration
+   EFFECT_CMD_SET_FEATURE_CONFIG,   // set current feature configuration
    EFFECT_CMD_FIRST_PROPRIETARY = 0x10000 // first proprietary command code
 };
 
@@ -425,7 +430,7 @@
 //  size: sizeof(int)
 //  data: status
 //==================================================================================================
-// command: EFFECT_CMD_CONFIGURE
+// command: EFFECT_CMD_SET_CONFIG
 //--------------------------------------------------------------------------------------------------
 // description:
 //  Apply new audio parameters configurations for input and output buffers
@@ -579,16 +584,17 @@
 //--------------------------------------------------------------------------------------------------
 // command format:
 //  size: sizeof(uint32_t)
-//  data: audio_mode_e
+//  data: audio_mode_t
 //--------------------------------------------------------------------------------------------------
 // reply format:
 //  size: 0
 //  data: N/A
 //==================================================================================================
-// command: EFFECT_CMD_CONFIGURE_REVERSE
+// command: EFFECT_CMD_SET_CONFIG_REVERSE
 //--------------------------------------------------------------------------------------------------
 // description:
-//  Apply new audio parameters configurations for input and output buffers of reverse stream
+//  Apply new audio parameters configurations for input and output buffers of reverse stream.
+//  An example of reverse stream is the echo reference supplied to an Acoustic Echo Canceler.
 //--------------------------------------------------------------------------------------------------
 // command format:
 //  size: sizeof(effect_config_t)
@@ -614,6 +620,91 @@
 //  size: 0
 //  data: N/A
 //==================================================================================================
+// command: EFFECT_CMD_GET_CONFIG
+//--------------------------------------------------------------------------------------------------
+// description:
+//  Read audio parameters configurations for input and output buffers
+//--------------------------------------------------------------------------------------------------
+// command format:
+//  size: 0
+//  data: N/A
+//--------------------------------------------------------------------------------------------------
+// reply format:
+//  size: sizeof(effect_config_t)
+//  data: effect_config_t
+//==================================================================================================
+// command: EFFECT_CMD_GET_CONFIG_REVERSE
+//--------------------------------------------------------------------------------------------------
+// description:
+//  Read audio parameters configurations for input and output buffers of reverse stream
+//--------------------------------------------------------------------------------------------------
+// command format:
+//  size: 0
+//  data: N/A
+//--------------------------------------------------------------------------------------------------
+// reply format:
+//  size: sizeof(effect_config_t)
+//  data: effect_config_t
+//==================================================================================================
+// command: EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS
+//--------------------------------------------------------------------------------------------------
+// description:
+//  Queries for supported configurations for a particular feature (e.g. get the supported
+// combinations of main and auxiliary channels for a noise suppressor).
+// The command parameter is the feature identifier (See effect_feature_e for a list of defined
+// features) followed by the maximum number of configuration descriptor to return.
+// The reply is composed of:
+//  - status (uint32_t):
+//          - 0 if feature is supported
+//          - -ENOSYS if the feature is not supported,
+//          - -ENOMEM if the feature is supported but the total number of supported configurations
+//          exceeds the maximum number indicated by the caller.
+//  - total number of supported configurations (uint32_t)
+//  - an array of configuration descriptors.
+// The actual number of descriptors returned must not exceed the maximum number indicated by
+// the caller.
+//--------------------------------------------------------------------------------------------------
+// command format:
+//  size: 2 x sizeof(uint32_t)
+//  data: effect_feature_e + maximum number of configurations to return
+//--------------------------------------------------------------------------------------------------
+// reply format:
+//  size: 2 x sizeof(uint32_t) + n x sizeof (<config descriptor>)
+//  data: status + total number of configurations supported + array of n config descriptors
+//==================================================================================================
+// command: EFFECT_CMD_GET_FEATURE_CONFIG
+//--------------------------------------------------------------------------------------------------
+// description:
+//  Retrieves current configuration for a given feature.
+// The reply status is:
+//      - 0 if feature is supported
+//      - -ENOSYS if the feature is not supported,
+//--------------------------------------------------------------------------------------------------
+// command format:
+//  size: sizeof(uint32_t)
+//  data: effect_feature_e
+//--------------------------------------------------------------------------------------------------
+// reply format:
+//  size: sizeof(uint32_t) + sizeof (<config descriptor>)
+//  data: status + config descriptor
+//==================================================================================================
+// command: EFFECT_CMD_SET_FEATURE_CONFIG
+//--------------------------------------------------------------------------------------------------
+// description:
+//  Sets current configuration for a given feature.
+// The reply status is:
+//      - 0 if feature is supported
+//      - -ENOSYS if the feature is not supported,
+//      - -EINVAL if the configuration is invalid
+//--------------------------------------------------------------------------------------------------
+// command format:
+//  size: sizeof(uint32_t) + sizeof (<config descriptor>)
+//  data: effect_feature_e + config descriptor
+//--------------------------------------------------------------------------------------------------
+// reply format:
+//  size: sizeof(uint32_t)
+//  data: status
+//==================================================================================================
 // command: EFFECT_CMD_FIRST_PROPRIETARY
 //--------------------------------------------------------------------------------------------------
 // description:
@@ -649,7 +740,7 @@
 // with getBuffer() is not needed anymore.
 // The process function should use the buffer provider mechanism to retrieve
 // input or output buffer if the inBuffer or outBuffer passed as argument is NULL
-// and the buffer configuration (buffer_config_t) given by the EFFECT_CMD_CONFIGURE
+// and the buffer configuration (buffer_config_t) given by the EFFECT_CMD_SET_CONFIG
 // command did not specify an audio buffer.
 
 typedef int32_t (* buffer_function_t)(void *cookie, audio_buffer_t *buffer);
@@ -664,7 +755,7 @@
 // The buffer_config_s structure specifies the input or output audio format
 // to be used by the effect engine. It is part of the effect_config_t
 // structure that defines both input and output buffer configurations and is
-// passed by the EFFECT_CMD_CONFIGURE or EFFECT_CMD_CONFIGURE_REVERSE command.
+// passed by the EFFECT_CMD_SET_CONFIG or EFFECT_CMD_SET_CONFIG_REVERSE command.
 typedef struct buffer_config_s {
     audio_buffer_t  buffer;     // buffer for use by process() function if not passed explicitly
     uint32_t   samplingRate;    // sampling rate
@@ -684,8 +775,22 @@
 
 };
 
+// feature identifiers for EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS command
+enum effect_feature_e {
+    EFFECT_FEATURE_AUX_CHANNELS, // supports auxiliary channels (e.g. dual mic noise suppressor)
+    EFFECT_FEATURE_CNT
+};
+
+// EFFECT_FEATURE_AUX_CHANNELS feature configuration descriptor. Describe a combination
+// of main and auxiliary channels supported
+typedef struct channel_config_s {
+    uint32_t   main_channels;   // channel mask for main channels
+    uint32_t   aux_channels;    // channel mask for auxiliary channels
+} channel_config_t;
+
+
 // Values for bit field "mask" in buffer_config_t. If a bit is set, the corresponding field
-// in buffer_config_t must be taken into account when executing the EFFECT_CMD_CONFIGURE command
+// in buffer_config_t must be taken into account when executing the EFFECT_CMD_SET_CONFIG command
 #define EFFECT_CONFIG_BUFFER    0x0001  // buffer field must be taken into account
 #define EFFECT_CONFIG_SMP_RATE  0x0002  // samplingRate field must be taken into account
 #define EFFECT_CONFIG_CHANNELS  0x0004  // channels field must be taken into account
@@ -697,7 +802,7 @@
                            EFFECT_CONFIG_ACC_MODE | EFFECT_CONFIG_PROVIDER)
 
 
-// effect_config_s structure describes the format of the pCmdData argument of EFFECT_CMD_CONFIGURE
+// effect_config_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_CONFIG
 // command to configure audio parameters and buffers for effect engine input and output.
 typedef struct effect_config_s {
     buffer_config_t   inputCfg;
@@ -840,7 +945,7 @@
     //        *pHandle:         updated with the effect interface handle.
     //
     ////////////////////////////////////////////////////////////////////////////////
-    int32_t (*create_effect)(effect_uuid_t *uuid,
+    int32_t (*create_effect)(const effect_uuid_t *uuid,
                              int32_t sessionId,
                              int32_t ioId,
                              effect_handle_t *pHandle);
@@ -882,7 +987,7 @@
     //        *pDescriptor:     updated with the effect descriptor.
     //
     ////////////////////////////////////////////////////////////////////////////////
-    int32_t (*get_descriptor)(effect_uuid_t *uuid,
+    int32_t (*get_descriptor)(const effect_uuid_t *uuid,
                               effect_descriptor_t *pDescriptor);
 } audio_effect_library_t;
 
diff --git a/include/hardware/audio_policy.h b/include/hardware/audio_policy.h
index fc56e5e..f31bea8 100644
--- a/include/hardware/audio_policy.h
+++ b/include/hardware/audio_policy.h
@@ -91,7 +91,7 @@
                                        audio_policy_dev_state_t state,
                                        const char *device_address);
 
-    /* retreive a device connection status */
+    /* retrieve a device connection status */
     audio_policy_dev_state_t (*get_device_connection_state)(
                                             const struct audio_policy *pol,
                                             audio_devices_t device,
@@ -99,9 +99,9 @@
 
     /* 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);
+    void (*set_phone_state)(struct audio_policy *pol, audio_mode_t state);
 
-    /* indicate a change in ringer mode */
+    /* deprecated, never called (was "indicate a change in ringer mode") */
     void (*set_ringer_mode)(struct audio_policy *pol, uint32_t mode,
                             uint32_t mask);
 
@@ -110,7 +110,7 @@
                           audio_policy_force_use_t usage,
                           audio_policy_forced_cfg_t config);
 
-    /* retreive current device category forced for a given usage */
+    /* retrieve 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);
 
@@ -131,7 +131,7 @@
     audio_io_handle_t (*get_output)(struct audio_policy *pol,
                                     audio_stream_type_t stream,
                                     uint32_t samplingRate,
-                                    uint32_t format,
+                                    audio_format_t format,
                                     uint32_t channels,
                                     audio_policy_output_flags_t flags);
 
@@ -152,11 +152,11 @@
     /* 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
+    /* request an input appropriate for record from the supplied device with
      * supplied parameters. */
-    audio_io_handle_t (*get_input)(struct audio_policy *pol, int inputSource,
+    audio_io_handle_t (*get_input)(struct audio_policy *pol, audio_source_t inputSource,
                                    uint32_t samplingRate,
-                                   uint32_t format,
+                                   audio_format_t format,
                                    uint32_t channels,
                                    audio_in_acoustics_t acoustics);
 
@@ -174,23 +174,37 @@
      */
 
     /* initialises stream volume conversion parameters by specifying volume
-     * index range. */
+     * index range. The index range for each stream is defined by AudioService. */
     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 */
+     * index. The index is within the range specified by init_stream_volume() */
     int (*set_stream_volume_index)(struct audio_policy *pol,
                                    audio_stream_type_t stream,
                                    int index);
 
-    /* retreive current volume index for the specified stream */
+    /* retrieve current volume index for the specified stream */
     int (*get_stream_volume_index)(const struct audio_policy *pol,
                                    audio_stream_type_t stream,
                                    int *index);
 
+    /* sets the new stream volume at a level corresponding to the supplied
+     * index for the specified device.
+     * The index is within the range specified by init_stream_volume() */
+    int (*set_stream_volume_index_for_device)(struct audio_policy *pol,
+                                   audio_stream_type_t stream,
+                                   int index,
+                                   audio_devices_t device);
+
+    /* retrieve current volume index for the specified stream for the specified device */
+    int (*get_stream_volume_index_for_device)(const struct audio_policy *pol,
+                                   audio_stream_type_t stream,
+                                   int *index,
+                                   audio_devices_t device);
+
     /* 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);
@@ -215,7 +229,7 @@
     int (*set_effect_enabled)(struct audio_policy *pol, int id, bool enabled);
 
     bool (*is_stream_active)(const struct audio_policy *pol,
-                             int stream,
+                             audio_stream_type_t stream,
                              uint32_t in_past_ms);
 
     /* dump state */
@@ -242,7 +256,7 @@
     audio_io_handle_t (*open_output)(void *service,
                                      uint32_t *pDevices,
                                      uint32_t *pSamplingRate,
-                                     uint32_t *pFormat,
+                                     audio_format_t *pFormat,
                                      uint32_t *pChannels,
                                      uint32_t *pLatencyMs,
                                      audio_policy_output_flags_t flags);
@@ -277,9 +291,9 @@
     audio_io_handle_t (*open_input)(void *service,
                                     uint32_t *pDevices,
                                     uint32_t *pSamplingRate,
-                                    uint32_t *pFormat,
+                                    audio_format_t *pFormat,
                                     uint32_t *pChannels,
-                                    uint32_t acoustics);
+                                    audio_in_acoustics_t acoustics);
 
     /* closes an audio input */
     int (*close_input)(void *service, audio_io_handle_t input);
diff --git a/include/hardware/camera.h b/include/hardware/camera.h
index 4d25023..4058c30 100644
--- a/include/hardware/camera.h
+++ b/include/hardware/camera.h
@@ -109,6 +109,11 @@
                 int *count);
     int (*lock_buffer)(struct preview_stream_ops* w,
                 buffer_handle_t* buffer);
+    // Timestamps are measured in nanoseconds, and must be comparable
+    // and monotonically increasing between two frames in the same
+    // preview stream. They do not need to be comparable between
+    // consecutive or parallel preview streams, cameras, or app runs.
+    int (*set_timestamp)(struct preview_stream_ops *w, int64_t timestamp);
 } preview_stream_ops_t;
 
 struct camera_device;
diff --git a/include/hardware/gralloc.h b/include/hardware/gralloc.h
index f8beb5e..2dbd1fa 100644
--- a/include/hardware/gralloc.h
+++ b/include/hardware/gralloc.h
@@ -258,4 +258,4 @@
 
 __END_DECLS
 
-#endif  // ANDROID_ALLOC_INTERFACE_H
+#endif  // ANDROID_GRALLOC_INTERFACE_H
diff --git a/include/hardware/keymaster.h b/include/hardware/keymaster.h
new file mode 100644
index 0000000..76ab75d
--- /dev/null
+++ b/include/hardware/keymaster.h
@@ -0,0 +1,102 @@
+/*
+ * 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_HARDWARE_KEYMASTER_H
+#define ANDROID_HARDWARE_KEYMASTER_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define KEYSTORE_HARDWARE_MODULE_ID "keystore"
+
+#define KEYSTORE_KEYMASTER "keymaster"
+
+struct keystore_module {
+    struct hw_module_t common;
+};
+
+/**
+ * Key algorithm for imported keypairs.
+ */
+typedef enum {
+    ALGORITHM_RSA,
+} keymaster_keypair_algorithm_t;
+
+/**
+ * The parameters that can be set for a given keymaster implementation.
+ */
+struct keymaster_device {
+    struct hw_device_t common;
+
+    void* context;
+
+    /**
+     * Generates a public and private key. The key-blob returned is opaque
+     * and will subsequently provided for signing and verification.
+     *
+     * Returns: 0 on success or an error code less than 0.
+     */
+    int (*generate_rsa_keypair)(const struct keymaster_device* dev,
+            int modulus_size, unsigned long public_exponent,
+            uint8_t** keyBlob, size_t* keyBlobLength);
+
+    /**
+     * Imports a public and private key pair. The imported keys should be in
+     * DER format. The key-blob returned is opaque and can be subsequently
+     * provided for signing and verification.
+     *
+     * Returns: 0 on success or an error code less than 0.
+     */
+    int (*import_keypair)(const struct keymaster_device* dev,
+            keymaster_keypair_algorithm_t algorithm,
+            uint8_t* privateKey, size_t* privateKeyLength,
+            uint8_t* publicKey, size_t* publicKeyLength,
+            uint8_t** keyBlob, size_t* keyBlobLength);
+
+    /**
+     * Signs data using a key-blob generated before.
+     *
+     * Returns: 0 on success or an error code less than 0.
+     */
+    int (*sign_data)(const struct keymaster_device* dev,
+            const uint8_t* keyBlob, const size_t keyBlobLength,
+            const uint8_t* data, const size_t dataLength,
+            uint8_t** signedData, size_t* signedDataLength);
+
+    /**
+     * Verifies data signed with a key-blob.
+     *
+     * Returns: 0 on successful verification or an error code less than 0.
+     */
+    int (*verify_data)(const struct keymaster_device* dev,
+            const uint8_t* keyBlob, const size_t keyBlobLength,
+            const uint8_t* signedData, const size_t signedDataLength,
+            const uint8_t* signature, const size_t signatureLength);
+};
+typedef struct keymaster_device keymaster_device_t;
+
+__END_DECLS
+
+#endif  // ANDROID_HARDWARE_KEYMASTER_H
+
diff --git a/include/hardware/local_time_hal.h b/include/hardware/local_time_hal.h
new file mode 100644
index 0000000..6b6a317
--- /dev/null
+++ b/include/hardware/local_time_hal.h
@@ -0,0 +1,117 @@
+/*
+ * 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_LOCAL_TIME_HAL_INTERFACE_H
+#define ANDROID_LOCAL_TIME_HAL_INTERFACE_H
+
+#include <stdint.h>
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define LOCAL_TIME_HARDWARE_MODULE_ID "local_time"
+
+/**
+ * Name of the local time devices to open
+ */
+#define LOCAL_TIME_HARDWARE_INTERFACE "local_time_hw_if"
+
+/**********************************************************************/
+
+/**
+ * A structure used to collect low level sync data in a lab environment.  Most
+ * HAL implementations will never need this structure.
+ */
+struct local_time_debug_event {
+    int64_t local_timesync_event_id;
+    int64_t local_time;
+};
+
+/**
+ * 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 local_time_module {
+    struct hw_module_t common;
+};
+
+struct local_time_hw_device {
+    struct hw_device_t common;
+
+    /**
+     *
+     * Returns the current value of the system wide local time counter
+     */
+    int64_t (*get_local_time)(struct local_time_hw_device* dev);
+
+    /**
+     *
+     * Returns the nominal frequency (in hertz) of the system wide local time
+     * counter
+     */
+    uint64_t (*get_local_freq)(struct local_time_hw_device* dev);
+
+    /**
+     *
+     * Sets the HW slew rate of oscillator which drives the system wide local
+     * time counter.  On success, platforms should return 0.  Platforms which
+     * do not support HW slew should leave this method set to NULL.
+     *
+     * Valid values for rate range from MIN_INT16 to MAX_INT16.  Platform
+     * implementations should attempt map this range linearly to the min/max
+     * slew rate of their hardware.
+     */
+    int (*set_local_slew)(struct local_time_hw_device* dev, int16_t rate);
+
+    /**
+     *
+     * A method used to collect low level sync data in a lab environments.
+     * Most HAL implementations will simply set this member to NULL, or return
+     * -EINVAL to indicate that this functionality is not supported.
+     * Production HALs should never support this method.
+     */
+    int (*get_debug_log)(struct local_time_hw_device* dev,
+                         struct local_time_debug_event* records,
+                         int max_records);
+};
+
+typedef struct local_time_hw_device local_time_hw_device_t;
+
+/** convenience API for opening and closing a supported device */
+
+static inline int local_time_hw_device_open(
+        const struct hw_module_t* module,
+        struct local_time_hw_device** device)
+{
+    return module->methods->open(module, LOCAL_TIME_HARDWARE_INTERFACE,
+                                 (struct hw_device_t**)device);
+}
+
+static inline int local_time_hw_device_close(struct local_time_hw_device* device)
+{
+    return device->common.close(&device->common);
+}
+
+
+__END_DECLS
+
+#endif  // ANDROID_LOCAL_TIME_INTERFACE_H
diff --git a/include/hardware/power.h b/include/hardware/power.h
new file mode 100644
index 0000000..825a74a
--- /dev/null
+++ b/include/hardware/power.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2012 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_INCLUDE_HARDWARE_POWER_H
+#define ANDROID_INCLUDE_HARDWARE_POWER_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define POWER_HARDWARE_MODULE_ID "power"
+
+/**
+ * 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 power_module {
+    struct hw_module_t common;
+
+    /*
+     * (*init)() performs power management setup actions at runtime
+     * startup, such as to set default cpufreq parameters.
+     */
+    void (*init)(struct power_module *module);
+
+    /*
+     * (*setInteractive)() performs power management actions upon the
+     * system entering interactive state (that is, the system is awake
+     * and ready for interaction, often with UI devices such as
+     * display and touchscreen enabled) or non-interactive state (the
+     * system appears asleep, display usually turned off).  The
+     * non-interactive state is usually entered after a period of
+     * inactivity, in order to conserve battery power during
+     * such inactive periods.
+     *
+     * Typical actions are to turn on or off devices and adjust
+     * cpufreq parameters.  This function may also call the
+     * appropriate interfaces to allow the kernel to suspend the
+     * system to low-power sleep state when entering non-interactive
+     * state, and to disallow low-power suspend when the system is in
+     * interactive state.  When low-power suspend state is allowed, the
+     * kernel may suspend the system whenever no wakelocks are held.
+     *
+     * on is non-zero when the system is transitioning to an
+     * interactive / awake state, and zero when transitioning to a
+     * non-interactive / asleep state.
+     *
+     * This function is called to enter non-interactive state after
+     * turning off the screen (if present), and called to enter
+     * interactive state prior to turning on the screen.
+     */
+    void (*setInteractive)(struct power_module *module, int on);
+} power_module_t;
+
+
+__END_DECLS
+
+#endif  // ANDROID_INCLUDE_HARDWARE_POWER_H
diff --git a/modules/Android.mk b/modules/Android.mk
index 6231e78..b8b83ba 100644
--- a/modules/Android.mk
+++ b/modules/Android.mk
@@ -1,2 +1,2 @@
-hardware_modules := gralloc hwcomposer audio nfc
+hardware_modules := gralloc hwcomposer audio nfc local_time power
 include $(call all-named-subdir-makefiles,$(hardware_modules))
diff --git a/modules/audio/audio_hw.c b/modules/audio/audio_hw.c
index a482604..4069ace 100644
--- a/modules/audio/audio_hw.c
+++ b/modules/audio/audio_hw.c
@@ -60,12 +60,12 @@
     return AUDIO_CHANNEL_OUT_STEREO;
 }
 
-static int out_get_format(const struct audio_stream *stream)
+static audio_format_t 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)
+static int out_set_format(struct audio_stream *stream, audio_format_t format)
 {
     return 0;
 }
@@ -126,6 +126,12 @@
     return 0;
 }
 
+static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
+                                        int64_t *timestamp)
+{
+    return -EINVAL;
+}
+
 /** audio_stream_in implementation **/
 static uint32_t in_get_sample_rate(const struct audio_stream *stream)
 {
@@ -147,12 +153,12 @@
     return AUDIO_CHANNEL_IN_MONO;
 }
 
-static int in_get_format(const struct audio_stream *stream)
+static audio_format_t 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)
+static int in_set_format(struct audio_stream *stream, audio_format_t format)
 {
     return 0;
 }
@@ -208,7 +214,7 @@
 }
 
 static int adev_open_output_stream(struct audio_hw_device *dev,
-                                   uint32_t devices, int *format,
+                                   uint32_t devices, audio_format_t *format,
                                    uint32_t *channels, uint32_t *sample_rate,
                                    struct audio_stream_out **stream_out)
 {
@@ -236,6 +242,7 @@
     out->stream.set_volume = out_set_volume;
     out->stream.write = out_write;
     out->stream.get_render_position = out_get_render_position;
+    out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
 
     *stream_out = &out->stream;
     return 0;
@@ -278,7 +285,13 @@
     return -ENOSYS;
 }
 
-static int adev_set_mode(struct audio_hw_device *dev, int mode)
+static int adev_get_master_volume(struct audio_hw_device *dev,
+                                  float *volume)
+{
+    return -ENOSYS;
+}
+
+static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
 {
     return 0;
 }
@@ -294,14 +307,14 @@
 }
 
 static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
-                                         uint32_t sample_rate, int format,
+                                         uint32_t sample_rate, audio_format_t 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,
+                                  audio_format_t *format, uint32_t *channels,
                                   uint32_t *sample_rate,
                                   audio_in_acoustics_t acoustics,
                                   struct audio_stream_in **stream_in)
@@ -401,6 +414,7 @@
     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.get_master_volume = adev_get_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;
diff --git a/modules/audio/audio_policy.c b/modules/audio/audio_policy.c
index 409f0a1..5fb6095 100644
--- a/modules/audio/audio_policy.c
+++ b/modules/audio/audio_policy.c
@@ -58,10 +58,11 @@
     return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
 }
 
-static void ap_set_phone_state(struct audio_policy *pol, int state)
+static void ap_set_phone_state(struct audio_policy *pol, audio_mode_t state)
 {
 }
 
+// deprecated, never called
 static void ap_set_ringer_mode(struct audio_policy *pol, uint32_t mode,
                                uint32_t mask)
 {
@@ -96,7 +97,7 @@
 static audio_io_handle_t ap_get_output(struct audio_policy *pol,
                                        audio_stream_type_t stream,
                                        uint32_t sampling_rate,
-                                       uint32_t format,
+                                       audio_format_t format,
                                        uint32_t channels,
                                        audio_policy_output_flags_t flags)
 {
@@ -120,9 +121,9 @@
 {
 }
 
-static audio_io_handle_t ap_get_input(struct audio_policy *pol, int inputSource,
+static audio_io_handle_t ap_get_input(struct audio_policy *pol, audio_source_t inputSource,
                                       uint32_t sampling_rate,
-                                      uint32_t format,
+                                      audio_format_t format,
                                       uint32_t channels,
                                       audio_in_acoustics_t acoustics)
 {
@@ -163,6 +164,22 @@
     return -ENOSYS;
 }
 
+static int ap_set_stream_volume_index_for_device(struct audio_policy *pol,
+                                      audio_stream_type_t stream,
+                                      int index,
+                                      audio_devices_t device)
+{
+    return -ENOSYS;
+}
+
+static int ap_get_stream_volume_index_for_device(const struct audio_policy *pol,
+                                      audio_stream_type_t stream,
+                                      int *index,
+                                      audio_devices_t device)
+{
+    return -ENOSYS;
+}
+
 static uint32_t ap_get_strategy_for_stream(const struct audio_policy *pol,
                                            audio_stream_type_t stream)
 {
@@ -201,7 +218,7 @@
     return -ENOSYS;
 }
 
-static bool ap_is_stream_active(const struct audio_policy *pol, int stream,
+static bool ap_is_stream_active(const struct audio_policy *pol, audio_stream_type_t stream,
                                 uint32_t in_past_ms)
 {
     return false;
@@ -250,6 +267,8 @@
     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.set_stream_volume_index_for_device = ap_set_stream_volume_index_for_device;
+    dap->policy.get_stream_volume_index_for_device = ap_get_stream_volume_index_for_device;
     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;
diff --git a/modules/gralloc/framebuffer.cpp b/modules/gralloc/framebuffer.cpp
index f908976..a37e2c0 100644
--- a/modules/gralloc/framebuffer.cpp
+++ b/modules/gralloc/framebuffer.cpp
@@ -98,7 +98,7 @@
         m->info.activate = FB_ACTIVATE_VBL;
         m->info.yoffset = offset / m->finfo.line_length;
         if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1) {
-            LOGE("FBIOPUT_VSCREENINFO failed");
+            ALOGE("FBIOPUT_VSCREENINFO failed");
             m->base.unlock(&m->base, buffer); 
             return -errno;
         }
@@ -181,14 +181,14 @@
     if (ioctl(fd, FBIOPUT_VSCREENINFO, &info) == -1) {
         info.yres_virtual = info.yres;
         flags &= ~PAGE_FLIP;
-        LOGW("FBIOPUT_VSCREENINFO failed, page flipping not supported");
+        ALOGW("FBIOPUT_VSCREENINFO failed, page flipping not supported");
     }
 
     if (info.yres_virtual < info.yres * 2) {
         // we need at least 2 for page-flipping
         info.yres_virtual = info.yres;
         flags &= ~PAGE_FLIP;
-        LOGW("page flipping not supported (yres_virtual=%d, requested=%d)",
+        ALOGW("page flipping not supported (yres_virtual=%d, requested=%d)",
                 info.yres_virtual, info.yres*2);
     }
 
@@ -222,7 +222,7 @@
     float ydpi = (info.yres * 25.4f) / info.height;
     float fps  = refreshRate / 1000.0f;
 
-    LOGI(   "using (fd=%d)\n"
+    ALOGI(   "using (fd=%d)\n"
             "id           = %s\n"
             "xres         = %d px\n"
             "yres         = %d px\n"
@@ -244,7 +244,7 @@
             info.blue.offset, info.blue.length
     );
 
-    LOGI(   "width        = %d mm (%f dpi)\n"
+    ALOGI(   "width        = %d mm (%f dpi)\n"
             "height       = %d mm (%f dpi)\n"
             "refresh rate = %.2f Hz\n",
             info.width,  xdpi,
@@ -280,7 +280,7 @@
 
     void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
     if (vaddr == MAP_FAILED) {
-        LOGE("Error mapping the framebuffer (%s)", strerror(errno));
+        ALOGE("Error mapping the framebuffer (%s)", strerror(errno));
         return -errno;
     }
     module->framebuffer->base = intptr_t(vaddr);
diff --git a/modules/gralloc/gralloc.cpp b/modules/gralloc/gralloc.cpp
index dcd2e2b..a6b4edd 100644
--- a/modules/gralloc/gralloc.cpp
+++ b/modules/gralloc/gralloc.cpp
@@ -175,7 +175,7 @@
     
     fd = ashmem_create_region("gralloc-buffer", size);
     if (fd < 0) {
-        LOGE("couldn't create ashmem (%s)", strerror(-errno));
+        ALOGE("couldn't create ashmem (%s)", strerror(-errno));
         err = -errno;
     }
 
@@ -189,7 +189,7 @@
         }
     }
     
-    LOGE_IF(err, "gralloc failed err=%s", strerror(-err));
+    ALOGE_IF(err, "gralloc failed err=%s", strerror(-err));
     
     return err;
 }
diff --git a/modules/gralloc/gralloc_priv.h b/modules/gralloc/gralloc_priv.h
index 75bcd1d..e1c502a 100644
--- a/modules/gralloc/gralloc_priv.h
+++ b/modules/gralloc/gralloc_priv.h
@@ -101,7 +101,7 @@
                 h->numInts != sNumInts || h->numFds != sNumFds ||
                 hnd->magic != sMagic) 
         {
-            LOGE("invalid gralloc handle (at %p)", h);
+            ALOGE("invalid gralloc handle (at %p)", h);
             return -EINVAL;
         }
         return 0;
diff --git a/modules/gralloc/mapper.cpp b/modules/gralloc/mapper.cpp
index 33d0958..c4096ae 100644
--- a/modules/gralloc/mapper.cpp
+++ b/modules/gralloc/mapper.cpp
@@ -53,11 +53,11 @@
         void* mappedAddress = mmap(0, size,
                 PROT_READ|PROT_WRITE, MAP_SHARED, hnd->fd, 0);
         if (mappedAddress == MAP_FAILED) {
-            LOGE("Could not mmap %s", strerror(errno));
+            ALOGE("Could not mmap %s", strerror(errno));
             return -errno;
         }
         hnd->base = intptr_t(mappedAddress) + hnd->offset;
-        //LOGD("gralloc_map() succeeded fd=%d, off=%d, size=%d, vaddr=%p",
+        //ALOGD("gralloc_map() succeeded fd=%d, off=%d, size=%d, vaddr=%p",
         //        hnd->fd, hnd->offset, hnd->size, mappedAddress);
     }
     *vaddr = (void*)hnd->base;
@@ -71,9 +71,9 @@
     if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
         void* base = (void*)hnd->base;
         size_t size = hnd->size;
-        //LOGD("unmapping from %p, size=%d", base, size);
+        //ALOGD("unmapping from %p, size=%d", base, size);
         if (munmap(base, size) < 0) {
-            LOGE("Could not unmap %s", strerror(errno));
+            ALOGE("Could not unmap %s", strerror(errno));
         }
     }
     hnd->base = 0;
diff --git a/modules/hwcomposer/hwcomposer.cpp b/modules/hwcomposer/hwcomposer.cpp
index 68b7070..0e04cac 100644
--- a/modules/hwcomposer/hwcomposer.cpp
+++ b/modules/hwcomposer/hwcomposer.cpp
@@ -55,7 +55,7 @@
 /*****************************************************************************/
 
 static void dump_layer(hwc_layer_t const* l) {
-    LOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}, {%d,%d,%d,%d}",
+    ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}, {%d,%d,%d,%d}",
             l->compositionType, l->flags, l->handle, l->transform, l->blending,
             l->sourceCrop.left,
             l->sourceCrop.top,
diff --git a/modules/local_time/Android.mk b/modules/local_time/Android.mk
new file mode 100644
index 0000000..f840dc7
--- /dev/null
+++ b/modules/local_time/Android.mk
@@ -0,0 +1,34 @@
+# 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 local time HAL module.  The default module simply uses the
+# system's clock_gettime(CLOCK_MONOTONIC) and does not support HW slewing.
+# Devices which use the default implementation should take care to ensure that
+# the oscillator backing the CLOCK_MONOTONIC implementation is phase locked to
+# the audio and video output hardware.  This default implementation 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 local_time.<hardware>.so
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := local_time.default
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_SRC_FILES := local_time_hw.c
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/local_time/local_time_hw.c b/modules/local_time/local_time_hw.c
new file mode 100644
index 0000000..308f7d9
--- /dev/null
+++ b/modules/local_time/local_time_hw.c
@@ -0,0 +1,109 @@
+/*
+ * 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 "local_time_hw_default"
+//#define LOG_NDEBUG 0
+
+#include <errno.h>
+#include <stdint.h>
+#include <sys/time.h>
+#include <linux/time.h>
+
+#include <cutils/log.h>
+
+#include <hardware/hardware.h>
+#include <hardware/local_time_hal.h>
+
+struct stub_local_time_device {
+    struct local_time_hw_device device;
+};
+
+static int64_t ltdev_get_local_time(struct local_time_hw_device* dev)
+{
+    struct timespec ts;
+    uint64_t now;
+    int ret;
+
+    ret = clock_gettime(CLOCK_MONOTONIC, &ts);
+    if (ret < 0) {
+        ALOGW("%s failed to fetch CLOCK_MONOTONIC value! (res = %d)",
+                dev->common.module->name, ret);
+        return 0;
+    }
+
+    now = (((uint64_t)ts.tv_sec) * 1000000000ull) +
+           ((uint64_t)ts.tv_nsec);
+
+    return (int64_t)now;
+}
+
+static uint64_t ltdev_get_local_freq(struct local_time_hw_device* dev)
+{
+    // For better or worse, linux clock_gettime routines normalize all clock
+    // frequencies to 1GHz
+    return 1000000000ull;
+}
+
+static int ltdev_close(hw_device_t *device)
+{
+    free(device);
+    return 0;
+}
+
+static int ltdev_open(const hw_module_t* module, const char* name,
+                     hw_device_t** device)
+{
+    struct stub_local_time_device *ltdev;
+    struct timespec ts;
+    int ret;
+
+    if (strcmp(name, LOCAL_TIME_HARDWARE_INTERFACE) != 0)
+        return -EINVAL;
+
+    ltdev = calloc(1, sizeof(struct stub_local_time_device));
+    if (!ltdev)
+        return -ENOMEM;
+
+    ltdev->device.common.tag = HARDWARE_DEVICE_TAG;
+    ltdev->device.common.version = 0;
+    ltdev->device.common.module = (struct hw_module_t *) module;
+    ltdev->device.common.close = ltdev_close;
+
+    ltdev->device.get_local_time = ltdev_get_local_time;
+    ltdev->device.get_local_freq = ltdev_get_local_freq;
+    ltdev->device.set_local_slew = NULL;
+    ltdev->device.get_debug_log  = NULL;
+
+    *device = &ltdev->device.common;
+
+    return 0;
+}
+
+static struct hw_module_methods_t hal_module_methods = {
+    .open = ltdev_open,
+};
+
+struct local_time_module HAL_MODULE_INFO_SYM = {
+    .common = {
+        .tag = HARDWARE_MODULE_TAG,
+        .version_major = 1,
+        .version_minor = 0,
+        .id = LOCAL_TIME_HARDWARE_MODULE_ID,
+        .name = "Default local_time HW HAL",
+        .author = "The Android Open Source Project",
+        .methods = &hal_module_methods,
+    },
+};
diff --git a/modules/power/Android.mk b/modules/power/Android.mk
new file mode 100644
index 0000000..50ab221
--- /dev/null
+++ b/modules/power/Android.mk
@@ -0,0 +1,25 @@
+# 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)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := power.default
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_SRC_FILES := power.c
+LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/power/power.c b/modules/power/power.c
new file mode 100644
index 0000000..ef3fe94
--- /dev/null
+++ b/modules/power/power.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define LOG_TAG "Legacy PowerHAL"
+#include <utils/Log.h>
+
+#include <hardware/hardware.h>
+#include <hardware/power.h>
+
+/*
+ * This module implements the legacy interface for requesting early
+ * suspend and late resume
+ */
+
+#define LEGACY_SYS_POWER_STATE "/sys/power/state"
+
+static int sPowerStatefd;
+static const char *pwr_states[] = { "mem", "on" };
+
+static void power_init(struct power_module *module)
+{
+    char buf[80];
+
+    sPowerStatefd = open(LEGACY_SYS_POWER_STATE, O_RDWR);
+
+    if (sPowerStatefd < 0) {
+        strerror_r(errno, buf, sizeof(buf));
+        ALOGE("Error opening %s: %s\n", LEGACY_SYS_POWER_STATE, buf);
+    }
+}
+
+static void power_set_interactive(struct power_module *module, int on)
+{
+    char buf[80];
+    int len;
+
+    len = write(sPowerStatefd, pwr_states[!!on], strlen(pwr_states[!!on]));
+    if (len < 0) {
+        strerror_r(errno, buf, sizeof(buf));
+        ALOGE("Error writing to %s: %s\n", LEGACY_SYS_POWER_STATE, buf);
+    }
+}
+
+
+static struct hw_module_methods_t power_module_methods = {
+    .open = NULL,
+};
+
+struct power_module HAL_MODULE_INFO_SYM = {
+    .common = {
+        .tag = HARDWARE_MODULE_TAG,
+        .version_major = 1,
+        .version_minor = 0,
+        .id = POWER_HARDWARE_MODULE_ID,
+        .name = "Default Power HAL",
+        .author = "The Android Open Source Project",
+        .methods = &power_module_methods,
+    },
+
+    .init = power_init,
+    .setInteractive = power_set_interactive,
+};