am 1fbbb08d: Merge "remove seemed useless gralloc_open() call in fb_device_open()"
* commit '1fbbb08ddda4321ccdb05345658044c1f0235997':
remove seemed useless gralloc_open() call in fb_device_open()
diff --git a/hardware.c b/hardware.c
index 4d5f8fe..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;
}
@@ -108,7 +108,7 @@
handle = NULL;
}
} else {
- LOGV("loaded HAL id=%s path=%s hmi=%p handle=%p",
+ ALOGV("loaded HAL id=%s path=%s hmi=%p handle=%p",
id, path, *pHmi, handle);
}
diff --git a/include/hardware/audio.h b/include/hardware/audio.h
index 2d7f39d..01d79b2 100644
--- a/include/hardware/audio.h
+++ b/include/hardware/audio.h
@@ -41,6 +41,31 @@
*/
#define AUDIO_HARDWARE_INTERFACE "audio_hw_if"
+
+/* Use version 0.1 to be compatible with first generation of audio hw module with version_major
+ * hardcoded to 1. No audio module API change.
+ */
+#define AUDIO_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+#define AUDIO_MODULE_API_VERSION_CURRENT AUDIO_MODULE_API_VERSION_0_1
+
+/* First generation of audio devices had version hardcoded to 0. all devices with versions < 1.0
+ * will be considered of first generation API.
+ */
+#define AUDIO_DEVICE_API_VERSION_0_0 HARDWARE_DEVICE_API_VERSION(0, 0)
+#define AUDIO_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
+#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_1_0
+
+/**
+ * List of known audio HAL modules. This is the base name of the audio HAL
+ * library composed of the "audio." prefix, one of the base names below and
+ * a suffix specific to the device.
+ * e.g: audio.primary.goldfish.so or audio.a2dp.default.so
+ */
+
+#define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary"
+#define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp"
+#define AUDIO_HARDWARE_MODULE_ID_USB "usb"
+
/**************************************/
/**
@@ -63,23 +88,50 @@
#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco"
#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full"
+/* A2DP sink address set by framework */
+#define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address"
+
+/* Screen state */
+#define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state"
+
/**
* audio stream parameters
*/
-#define AUDIO_PARAMETER_STREAM_ROUTING "routing"
-#define AUDIO_PARAMETER_STREAM_FORMAT "format"
-#define AUDIO_PARAMETER_STREAM_CHANNELS "channels"
-#define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count"
-#define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source"
+#define AUDIO_PARAMETER_STREAM_ROUTING "routing" // audio_devices_t
+#define AUDIO_PARAMETER_STREAM_FORMAT "format" // audio_format_t
+#define AUDIO_PARAMETER_STREAM_CHANNELS "channels" // audio_channel_mask_t
+#define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" // size_t
+#define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" // audio_source_t
+#define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" // uint32_t
+
+/* Query supported formats. The response is a '|' separated list of strings from
+ * audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */
+#define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats"
+/* Query supported channel masks. The response is a '|' separated list of strings from
+ * audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */
+#define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels"
+/* Query supported sampling rates. The response is a '|' separated list of integer values e.g:
+ * "sup_sampling_rates=44100|48000" */
+#define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates"
+
/**************************************/
+/* common audio stream configuration parameters */
+struct audio_config {
+ uint32_t sample_rate;
+ audio_channel_mask_t channel_mask;
+ audio_format_t format;
+};
+
+typedef struct audio_config audio_config_t;
+
/* common audio stream parameters and operations */
struct audio_stream {
/**
- * sampling rate is in Hz - eg. 44100
+ * Return the sampling rate in Hz - eg. 44100.
*/
uint32_t (*get_sample_rate)(const struct audio_stream *stream);
@@ -89,28 +141,30 @@
int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
/**
- * size of output buffer in bytes - eg. 4800
+ * Return size of input/output buffer in bytes for this stream - eg. 4800.
+ * It should be a multiple of the frame size. See also get_input_buffer_size.
*/
size_t (*get_buffer_size)(const struct audio_stream *stream);
/**
- * the channel mask -
+ * Return the channel mask -
* e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
*/
- uint32_t (*get_channels)(const struct audio_stream *stream);
+ audio_channel_mask_t (*get_channels)(const struct audio_stream *stream);
/**
- * audio format - eg. AUDIO_FORMAT_PCM_16_BIT
+ * Return the audio format - e.g. 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.
+ * Driver should exit from standby mode at the next I/O operation.
* Returns 0 on success and <0 on failure.
*/
int (*standby)(struct audio_stream *stream);
@@ -118,7 +172,15 @@
/** dump the state of the audio input/output device */
int (*dump)(const struct audio_stream *stream, int fd);
+ /** Return the set of device(s) which this stream is connected to */
audio_devices_t (*get_device)(const struct audio_stream *stream);
+
+ /**
+ * Currently unused - set_device() corresponds to set_parameters() with key
+ * AUDIO_PARAMETER_STREAM_ROUTING for both input and output.
+ * AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by
+ * input streams only.
+ */
int (*set_device)(struct audio_stream *stream, audio_devices_t device);
/**
@@ -138,7 +200,7 @@
/*
* Returns a pointer to a heap allocated string. The caller is responsible
- * for freeing the memory for it.
+ * for freeing the memory for it using free().
*/
char * (*get_parameters)(const struct audio_stream *stream,
const char *keys);
@@ -160,7 +222,7 @@
struct audio_stream common;
/**
- * return the audio hardware driver latency in milli seconds.
+ * Return the audio hardware driver estimated latency in milliseconds.
*/
uint32_t (*get_latency)(const struct audio_stream_out *stream);
@@ -174,7 +236,10 @@
int (*set_volume)(struct audio_stream_out *stream, float left, float right);
/**
- * write audio buffer to driver. Returns number of bytes written
+ * Write audio buffer to driver. Returns number of bytes written, or a
+ * negative status_t. If at least one frame was written successfully prior to the error,
+ * it is suggested that the driver return that successful (short) byte count
+ * and then return an error in the subsequent call.
*/
ssize_t (*write)(struct audio_stream_out *stream, const void* buffer,
size_t bytes);
@@ -184,6 +249,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.
+ * The units are microseconds, where the epoch is decided by the local audio HAL.
+ */
+ int (*get_next_write_timestamp)(const struct audio_stream_out *stream,
+ int64_t *timestamp);
+
};
typedef struct audio_stream_out audio_stream_out_t;
@@ -194,7 +267,10 @@
* for future use */
int (*set_gain)(struct audio_stream_in *stream, float gain);
- /** read audio buffer in from audio driver */
+ /** Read audio buffer in from audio driver. Returns number of bytes read, or a
+ * negative status_t. If at least one frame was read prior to the error,
+ * read should return that byte count and then return an error in the subsequent call.
+ */
ssize_t (*read)(struct audio_stream_in *stream, void* buffer,
size_t bytes);
@@ -215,9 +291,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 +348,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);
@@ -287,36 +372,38 @@
/*
* Returns a pointer to a heap allocated string. The caller is responsible
- * for freeing the memory for it.
+ * for freeing the memory for it using free().
*/
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
+ * 0 if one of the parameters is not supported.
+ * See also get_buffer_size which is for a particular stream.
*/
size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,
- uint32_t sample_rate, int format,
- int channel_count);
+ const struct audio_config *config);
/** 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);
+ int (*open_output_stream)(struct audio_hw_device *dev,
+ audio_io_handle_t handle,
+ audio_devices_t devices,
+ audio_output_flags_t flags,
+ struct audio_config *config,
+ struct audio_stream_out **stream_out);
void (*close_output_stream)(struct audio_hw_device *dev,
- struct audio_stream_out* out);
+ struct audio_stream_out* stream_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,
+ int (*open_input_stream)(struct audio_hw_device *dev,
+ audio_io_handle_t handle,
+ audio_devices_t devices,
+ struct audio_config *config,
struct audio_stream_in **stream_in);
void (*close_input_stream)(struct audio_hw_device *dev,
- struct audio_stream_in *in);
+ struct audio_stream_in *stream_in);
/** This method dumps the state of the audio hardware */
int (*dump)(const struct audio_hw_device *dev, int fd);
diff --git a/include/hardware/audio_effect.h b/include/hardware/audio_effect.h
index 5adab12..65eba36 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:
@@ -624,7 +715,7 @@
// Audio buffer descriptor used by process(), bufferProvider() functions and buffer_config_t
// structure. Multi-channel audio is always interleaved. The channel order is from LSB to MSB with
-// regard to the channel mask definition in audio.h, audio_channels_t e.g :
+// regard to the channel mask definition in audio.h, audio_channel_mask_t e.g :
// Stereo: left, right
// 5 point 1: front left, front right, front center, low frequency, back left, back right
// The buffer size is expressed in frame count, a frame being composed of samples for all
@@ -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,11 +755,11 @@
// 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
- uint32_t channels; // channel mask (see audio_channels_t in audio.h)
+ uint32_t channels; // channel mask (see audio_channel_mask_t in audio.h)
buffer_provider_t bufferProvider; // buffer provider
uint8_t format; // Audio format (see see audio_format_t in audio.h)
uint8_t accessMode; // read/write or accumulate in buffer (effect_buffer_access_e)
@@ -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..78a1a62 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);
@@ -126,14 +126,14 @@
* Audio routing query functions
*/
- /* request an output appriate for playback of the supplied stream type and
+ /* request an output appropriate 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,
+ audio_format_t format,
uint32_t channels,
- audio_policy_output_flags_t flags);
+ audio_output_flags_t flags);
/* indicates to the audio policy manager that the output starts being used
* by corresponding stream. */
@@ -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,29 +174,43 @@
*/
/* 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);
/* return the enabled output devices for the given stream type */
- uint32_t (*get_devices_for_stream)(const struct audio_policy *pol,
+ audio_devices_t (*get_devices_for_stream)(const struct audio_policy *pol,
audio_stream_type_t stream);
/* Audio effect management */
@@ -215,13 +229,17 @@
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 */
int (*dump)(const struct audio_policy *pol, int fd);
};
+/* audio hw module handle used by load_hw_module(), open_output_on_module()
+ * and open_input_on_module() */
+typedef int audio_module_handle_t;
+
struct audio_policy_service_ops {
/*
* Audio output Control functions
@@ -240,12 +258,12 @@
* suitable or not and act accordingly.
*/
audio_io_handle_t (*open_output)(void *service,
- uint32_t *pDevices,
+ audio_devices_t *pDevices,
uint32_t *pSamplingRate,
- uint32_t *pFormat,
- uint32_t *pChannels,
+ audio_format_t *pFormat,
+ audio_channel_mask_t *pChannelMask,
uint32_t *pLatencyMs,
- audio_policy_output_flags_t flags);
+ audio_output_flags_t flags);
/* creates a special output that is duplicated to the two outputs passed as
* arguments. The duplication is performed by
@@ -275,11 +293,11 @@
/* opens an audio input */
audio_io_handle_t (*open_input)(void *service,
- uint32_t *pDevices,
+ audio_devices_t *pDevices,
uint32_t *pSamplingRate,
- uint32_t *pFormat,
- uint32_t *pChannels,
- uint32_t acoustics);
+ audio_format_t *pFormat,
+ audio_channel_mask_t *pChannelMask,
+ audio_in_acoustics_t acoustics);
/* closes an audio input */
int (*close_input)(void *service, audio_io_handle_t input);
@@ -315,7 +333,7 @@
* 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.
+ * for freeing the memory for it using free().
*/
char * (*get_parameters)(void *service, audio_io_handle_t io_handle,
@@ -341,6 +359,41 @@
int session,
audio_io_handle_t src_output,
audio_io_handle_t dst_output);
+
+ /* loads an audio hw module.
+ *
+ * The module name passed is the base name of the HW module library, e.g "primary" or "a2dp".
+ * The function returns a handle on the module that will be used to specify a particular
+ * module when calling open_output_on_module() or open_input_on_module()
+ */
+ audio_module_handle_t (*load_hw_module)(void *service,
+ const char *name);
+
+ /* Opens an audio output on a particular HW module.
+ *
+ * Same as open_output() but specifying a specific HW module on which the output must be opened.
+ */
+ audio_io_handle_t (*open_output_on_module)(void *service,
+ audio_module_handle_t module,
+ audio_devices_t *pDevices,
+ uint32_t *pSamplingRate,
+ audio_format_t *pFormat,
+ audio_channel_mask_t *pChannelMask,
+ uint32_t *pLatencyMs,
+ audio_output_flags_t flags);
+
+ /* Opens an audio input on a particular HW module.
+ *
+ * Same as open_input() but specifying a specific HW module on which the input must be opened.
+ * Also removed deprecated acoustics parameter
+ */
+ audio_io_handle_t (*open_input_on_module)(void *service,
+ audio_module_handle_t module,
+ audio_devices_t *pDevices,
+ uint32_t *pSamplingRate,
+ audio_format_t *pFormat,
+ audio_channel_mask_t *pChannelMask);
+
};
/**********************************************************************/
diff --git a/include/hardware/camera.h b/include/hardware/camera.h
index 4d25023..b7182f8 100644
--- a/include/hardware/camera.h
+++ b/include/hardware/camera.h
@@ -14,53 +14,29 @@
* 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
+#include "camera_common.h"
/**
- * The id of this module
+ * Camera device HAL, initial version [ CAMERA_DEVICE_API_VERSION_1_0 ]
+ *
+ * Supports the android.hardware.Camera API.
+ *
+ * Camera devices that support this version of the HAL must return a value in
+ * the range HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF) in
+ * camera_device_t.common.version. CAMERA_DEVICE_API_VERSION_1_0 is the
+ * recommended value.
+ *
+ * Camera modules that implement version 2.0 or higher of camera_module_t must
+ * also return the value of camera_device_t.common.version in
+ * camera_info_t.device_version.
+ *
+ * See camera_common.h for more details.
*/
-#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;
+__BEGIN_DECLS
struct camera_memory;
typedef void (*camera_release_memory)(struct camera_memory *mem);
@@ -109,6 +85,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;
@@ -299,6 +280,11 @@
} camera_device_ops_t;
typedef struct camera_device {
+ /**
+ * camera_device.common.version must be in the range
+ * HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF). CAMERA_DEVICE_API_VERSION_1_0 is
+ * recommended.
+ */
hw_device_t common;
camera_device_ops_t *ops;
void *priv;
@@ -306,4 +292,4 @@
__END_DECLS
-#endif /* ANDROID_INCLUDE_CAMERA_H */
+#endif /* #ifdef ANDROID_INCLUDE_CAMERA_H */
diff --git a/include/hardware/camera2.h b/include/hardware/camera2.h
new file mode 100644
index 0000000..36f2a9e
--- /dev/null
+++ b/include/hardware/camera2.h
@@ -0,0 +1,311 @@
+/*
+ * 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_CAMERA2_H
+#define ANDROID_INCLUDE_CAMERA2_H
+
+#include "camera_common.h"
+
+/**
+ * Camera device HAL 2.0 [ CAMERA_DEVICE_API_VERSION_2_0 ]
+ *
+ * EXPERIMENTAL.
+ *
+ * Supports both the android.hardware.ProCamera and
+ * android.hardware.Camera APIs.
+ *
+ * Camera devices that support this version of the HAL must return
+ * CAMERA_DEVICE_API_VERSION_2_0 in camera_device_t.common.version and in
+ * camera_info_t.device_version (from camera_module_t.get_camera_info).
+ *
+ * Camera modules that may contain version 2.0 devices must implement at least
+ * version 2.0 of the camera module interface (as defined by
+ * camera_module_t.common.module_api_version).
+ *
+ * See camera_common.h for more details.
+ *
+ */
+
+__BEGIN_DECLS
+
+struct camera2_device;
+
+/**
+ * Output image stream queue management
+ */
+
+typedef struct camera2_stream_ops {
+ int (*dequeue_buffer)(struct camera2_stream_ops* w,
+ buffer_handle_t** buffer, int *stride);
+ int (*enqueue_buffer)(struct camera2_stream_ops* w,
+ buffer_handle_t* buffer);
+ int (*cancel_buffer)(struct camera2_stream_ops* w,
+ buffer_handle_t* buffer);
+ int (*set_buffer_count)(struct camera2_stream_ops* w, int count);
+ int (*set_buffers_geometry)(struct camera2_stream_ops* pw,
+ int w, int h, int format);
+ int (*set_crop)(struct camera2_stream_ops *w,
+ int left, int top, int right, int bottom);
+ // 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.
+ // The timestamp must be the time at the start of image exposure.
+ int (*set_timestamp)(struct camera2_stream_ops *w, int64_t timestamp);
+ int (*set_usage)(struct camera2_stream_ops* w, int usage);
+ int (*get_min_undequeued_buffer_count)(const struct camera2_stream_ops *w,
+ int *count);
+ int (*lock_buffer)(struct camera2_stream_ops* w,
+ buffer_handle_t* buffer);
+} camera2_stream_ops_t;
+
+/**
+ * Metadata queue management, used for requests sent to HAL module, and for
+ * frames produced by the HAL.
+ *
+ * Queue protocol:
+ *
+ * The source holds the queue and its contents. At start, the queue is empty.
+ *
+ * 1. When the first metadata buffer is placed into the queue, the source must
+ * signal the destination by calling notify_queue_not_empty().
+ *
+ * 2. After receiving notify_queue_not_empty, the destination must call
+ * dequeue() once it's ready to handle the next buffer.
+ *
+ * 3. Once the destination has processed a buffer, it should try to dequeue
+ * another buffer. If there are no more buffers available, dequeue() will
+ * return NULL. In this case, when a buffer becomes available, the source
+ * must call notify_queue_not_empty() again. If the destination receives a
+ * NULL return from dequeue, it does not need to query the queue again until
+ * a notify_queue_not_empty() call is received from the source.
+ *
+ * 4. If the destination calls buffer_count() and receives 0, this does not mean
+ * that the source will provide a notify_queue_not_empty() call. The source
+ * must only provide such a call after the destination has received a NULL
+ * from dequeue, or on initial startup.
+ *
+ * 5. The dequeue() call in response to notify_queue_not_empty() may be on the
+ * same thread as the notify_queue_not_empty() call. The source must not
+ * deadlock in that case.
+ */
+
+typedef struct camera2_metadata_queue_src_ops {
+ /**
+ * Get count of buffers in queue
+ */
+ int (*buffer_count)(camera2_metadata_queue_src_ops *q);
+
+ /**
+ * Get a metadata buffer from the source. Returns OK if a request is
+ * available, placing a pointer to it in next_request.
+ */
+ int (*dequeue)(camera2_metadata_queue_src_ops *q,
+ camera_metadata_t **buffer);
+ /**
+ * Return a metadata buffer to the source once it has been used
+ */
+ int (*free)(camera2_metadata_queue_src_ops *q,
+ camera_metadata_t *old_buffer);
+
+} camera2_metadata_queue_src_ops_t;
+
+typedef struct camera2_metadata_queue_dst_ops {
+ /**
+ * Notify destination that the queue is no longer empty
+ */
+ int (*notify_queue_not_empty)(struct camera2_metadata_queue_dst_ops *);
+
+} camera2_metadata_queue_dst_ops_t;
+
+/* Defined in camera_metadata.h */
+typedef struct vendor_tag_query_ops vendor_tag_query_ops_t;
+
+/**
+ * Asynchronous notification callback from the HAL, fired for various
+ * reasons. Only for information independent of frame capture, or that require
+ * specific timing.
+ */
+typedef void (*camera2_notify_callback)(int32_t msg_type,
+ int32_t ext1,
+ int32_t ext2,
+ void *user);
+
+/**
+ * Possible message types for camera2_notify_callback
+ */
+enum {
+ /**
+ * A serious error has occurred. Argument ext1 contains the error code, and
+ * ext2 and user contain any error-specific information.
+ */
+ CAMERA2_MSG_ERROR = 0x0001,
+ /**
+ * The exposure of a given request has begun. Argument ext1 contains the
+ * request id.
+ */
+ CAMERA2_MSG_SHUTTER = 0x0002
+};
+
+/**
+ * Error codes for CAMERA_MSG_ERROR
+ */
+enum {
+ /**
+ * A serious failure occured. Camera device may not work without reboot, and
+ * no further frames or buffer streams will be produced by the
+ * device. Device should be treated as closed.
+ */
+ CAMERA2_MSG_ERROR_HARDWARE_FAULT = 0x0001,
+ /**
+ * A serious failure occured. No further frames or buffer streams will be
+ * produced by the device. Device should be treated as closed. The client
+ * must reopen the device to use it again.
+ */
+ CAMERA2_MSG_ERROR_DEVICE_FAULT = 0x0002,
+ /**
+ * The camera service has failed. Device should be treated as released. The client
+ * must reopen the device to use it again.
+ */
+ CAMERA2_MSG_ERROR_SERVER_FAULT = 0x0003
+};
+
+typedef struct camera2_device_ops {
+ /**
+ * Input request queue methods
+ */
+ int (*set_request_queue_src_ops)(struct camera2_device *,
+ camera2_metadata_queue_src_ops *queue_src_ops);
+
+ int (*get_request_queue_dst_ops)(struct camera2_device *,
+ camera2_metadata_queue_dst_ops **queue_dst_ops);
+
+ /**
+ * Input reprocessing queue methods
+ */
+ int (*set_reprocess_queue_ops)(struct camera2_device *,
+ camera2_metadata_queue_src_ops *queue_src_ops);
+
+ int (*get_reprocess_queue_dst_ops)(struct camera2_device *,
+ camera2_metadata_queue_dst_ops **queue_dst_ops);
+
+ /**
+ * Output frame queue methods
+ */
+ int (*set_frame_queue_dst_ops)(struct camera2_device *,
+ camera2_metadata_queue_dst_ops *queue_dst_ops);
+
+ int (*get_frame_queue_src_ops)(struct camera2_device *,
+ camera2_metadata_queue_src_ops **queue_dst_ops);
+
+ /**
+ * Pass in notification methods
+ */
+ int (*set_notify_callback)(struct camera2_device *,
+ camera2_notify_callback notify_cb);
+
+ /**
+ * Number of camera frames being processed by the device
+ * at the moment (frames that have had their request dequeued,
+ * but have not yet been enqueued onto output pipeline(s) )
+ */
+ int (*get_in_progress_count)(struct camera2_device *);
+
+ /**
+ * Flush all in-progress captures. This includes all dequeued requests
+ * (regular or reprocessing) that have not yet placed any outputs into a
+ * stream or the frame queue. Partially completed captures must be completed
+ * normally. No new requests may be dequeued from the request or
+ * reprocessing queues until the flush completes.
+ */
+ int (*flush_captures_in_progress)(struct camera2_device *);
+
+ /**
+ * Camera stream management
+ */
+
+ /**
+ * Operations on the input reprocessing stream
+ */
+ int (*get_reprocess_stream_ops)(struct camera2_device *,
+ camera2_stream_ops_t **stream_ops);
+
+ /**
+ * Get the number of streams that can be simultaneously allocated.
+ * A request may include any allocated pipeline for its output, without
+ * causing a substantial delay in frame production.
+ */
+ int (*get_stream_slot_count)(struct camera2_device *);
+
+ /**
+ * Allocate a new stream for use. Requires specifying which pipeline slot
+ * to use. Specifies the buffer width, height, and format.
+ * Error conditions:
+ * - Allocating an already-allocated slot without first releasing it
+ * - Requesting a width/height/format combination not listed as supported
+ * - Requesting a pipeline slot >= pipeline slot count.
+ */
+ int (*allocate_stream)(
+ struct camera2_device *,
+ uint32_t stream_slot,
+ uint32_t width,
+ uint32_t height,
+ uint32_t format,
+ camera2_stream_ops_t *camera2_stream_ops);
+
+ /**
+ * Release a stream. Returns an error if called when
+ * get_in_progress_count is non-zero, or if the pipeline slot is not
+ * allocated.
+ */
+ int (*release_stream)(
+ struct camera2_device *,
+ uint32_t stream_slot);
+
+ /**
+ * Get methods to query for vendor extension metadata tag infomation. May
+ * set ops to NULL if no vendor extension tags are defined.
+ */
+ int (*get_metadata_vendor_tag_ops)(struct camera2_device*,
+ vendor_tag_query_ops_t **ops);
+
+ /**
+ * Release the camera hardware. Requests that are in flight will be
+ * canceled. No further buffers will be pushed into any allocated pipelines
+ * once this call returns.
+ */
+ void (*release)(struct camera2_device *);
+
+ /**
+ * Dump state of the camera hardware
+ */
+ int (*dump)(struct camera2_device *, int fd);
+
+} camera2_device_ops_t;
+
+typedef struct camera2_device {
+ /**
+ * common.version must equal CAMERA_DEVICE_API_VERSION_2_0 to identify
+ * this device as implementing version 2.0 of the camera device HAL.
+ */
+ hw_device_t common;
+ camera2_device_ops_t *ops;
+ void *priv;
+} camera2_device_t;
+
+__END_DECLS
+
+#endif /* #ifdef ANDROID_INCLUDE_CAMERA2_H */
diff --git a/include/hardware/camera_common.h b/include/hardware/camera_common.h
new file mode 100644
index 0000000..5459b6c
--- /dev/null
+++ b/include/hardware/camera_common.h
@@ -0,0 +1,164 @@
+/*
+ * 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.
+ */
+
+// FIXME: add well-defined names for cameras
+
+#ifndef ANDROID_INCLUDE_CAMERA_COMMON_H
+#define ANDROID_INCLUDE_CAMERA_COMMON_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"
+
+/**
+ * Module versioning information for the Camera hardware module, based on
+ * camera_module_t.common.module_api_version. The two most significant hex
+ * digits represent the major version, and the two least significant represent
+ * the minor version.
+ *
+ *******************************************************************************
+ * Versions: 0.X - 1.X [CAMERA_MODULE_API_VERSION_1_0]
+ *
+ * Camera modules that report these version numbers implement the initial
+ * camera module HAL interface. All camera devices openable through this
+ * module support only version 1 of the camera device HAL. The device_version
+ * and static_camera_characteristics fields of camera_info are not valid. Only
+ * the android.hardware.Camera API can be supported by this module and its
+ * devices.
+ *
+ *******************************************************************************
+ * Version: 2.0 [CAMERA_MODULE_API_VERSION_2_0]
+ *
+ * Camera modules that report this version number implement the second version
+ * of the camera module HAL interface. Camera devices openable through this
+ * module may support either version 1.0 or version 2.0 of the camera device
+ * HAL interface. The device_version field of camera_info is always valid; the
+ * static_camera_characteristics field of camera_info is valid if the
+ * device_version field is 2.0 or higher.
+ */
+
+/**
+ * Predefined macros for currently-defined version numbers
+ */
+
+/**
+ * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
+ * as CAMERA_MODULE_API_VERSION_1_0
+ */
+#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
+#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
+
+#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_0
+
+/**
+ * All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
+ * as CAMERA_DEVICE_API_VERSION_1_0
+ */
+#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
+#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
+
+// Device version 2.0 is experimental
+#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_1_0
+
+/**
+ * Defined in /system/media/camera/include/system/camera_metadata.h
+ */
+typedef struct camera_metadata camera_metadata_t;
+
+struct camera_info {
+ /**
+ * The direction that the camera faces to. It should be CAMERA_FACING_BACK
+ * or CAMERA_FACING_FRONT.
+ *
+ * Version information:
+ * Valid in all camera_module versions
+ */
+ 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.
+ *
+ * Version information:
+ * Valid in all camera_module versions
+ */
+ int orientation;
+
+ /**
+ * The value of camera_device_t.common.version.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_1_0:
+ *
+ * Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
+ * not read this field.
+ *
+ * CAMERA_MODULE_API_VERSION_2_0:
+ *
+ * Always valid
+ *
+ */
+ uint32_t device_version;
+
+ /**
+ * The camera's fixed characteristics, which include all camera metadata in
+ * the android.*.info.* sections.
+ *
+ * Version information (based on camera_module_t.common.module_api_version):
+ *
+ * CAMERA_MODULE_API_VERSION_1_0:
+ *
+ * Not valid. Extra characteristics are not available. Do not read this
+ * field.
+ *
+ * CAMERA_MODULE_API_VERSION_2_0:
+ *
+ * Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
+ * otherwise.
+ *
+ */
+ camera_metadata_t *static_camera_characteristics;
+};
+
+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;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */
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/hardware.h b/include/hardware/hardware.h
index 7774b2b..78c4572 100644
--- a/include/hardware/hardware.h
+++ b/include/hardware/hardware.h
@@ -34,6 +34,38 @@
#define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
#define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')
+#define HARDWARE_MAKE_API_VERSION(maj,min) \
+ ((((maj) & 0xff) << 8) | ((min) & 0xff))
+
+/*
+ * The current HAL API version.
+ *
+ * All module implementations must set the hw_module_t.hal_api_version field
+ * to this value when declaring the module with HAL_MODULE_INFO_SYM.
+ *
+ * Note that previous implementations have always set this field to 0.
+ * Therefore, libhardware HAL API will always consider versions 0.0 and 1.0
+ * to be 100% binary compatible.
+ *
+ */
+#define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)
+
+/*
+ * Helper macros for module implementors.
+ *
+ * The derived modules should provide convenience macros for supported
+ * versions so that implementations can explicitly specify module/device
+ * versions at definition time.
+ *
+ * Use this macro to set the hw_module_t.module_api_version field.
+ */
+#define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
+
+/*
+ * Use this macro to set the hw_device_t.version field
+ */
+#define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
+
struct hw_module_t;
struct hw_module_methods_t;
struct hw_device_t;
@@ -47,11 +79,47 @@
/** tag must be initialized to HARDWARE_MODULE_TAG */
uint32_t tag;
- /** major version number for the module */
- uint16_t version_major;
+ /**
+ * The API version of the implemented module. The module owner is
+ * responsible for updating the version when a module interface has
+ * changed.
+ *
+ * The derived modules such as gralloc and audio own and manage this field.
+ * The module user must interpret the version field to decide whether or
+ * not to inter-operate with the supplied module implementation.
+ * For example, SurfaceFlinger is responsible for making sure that
+ * it knows how to manage different versions of the gralloc-module API,
+ * and AudioFlinger must know how to do the same for audio-module API.
+ *
+ * The module API version should include a major and a minor component.
+ * For example, version 1.0 could be represented as 0x0100. This format
+ * implies that versions 0x0100-0x01ff are all API-compatible.
+ *
+ * In the future, libhardware will expose a hw_get_module_version()
+ * (or equivalent) function that will take minimum/maximum supported
+ * versions as arguments and would be able to reject modules with
+ * versions outside of the supplied range.
+ */
+ uint16_t module_api_version;
+#define version_major module_api_version
+ /**
+ * version_major/version_minor defines are supplied here for temporary
+ * source code compatibility. They will be removed in the next version.
+ * ALL clients must convert to the new version format.
+ */
- /** minor version number of the module */
- uint16_t version_minor;
+ /**
+ * The API version of the HAL module interface. This is meant to
+ * version the hw_module_t, hw_module_methods_t, and hw_device_t
+ * structures and definitions.
+ *
+ * The HAL interface owns this field. Module users/implementations
+ * must NOT rely on this value for version information.
+ *
+ * Presently, 0 is the only valid value.
+ */
+ uint16_t hal_api_version;
+#define version_minor hal_api_version
/** Identifier of module */
const char *id;
@@ -88,7 +156,22 @@
/** tag must be initialized to HARDWARE_DEVICE_TAG */
uint32_t tag;
- /** version number for hw_device_t */
+ /**
+ * Version of the module-specific device API. This value is used by
+ * the derived-module user to manage different device implementations.
+ *
+ * The module user is responsible for checking the module_api_version
+ * and device version fields to ensure that the user is capable of
+ * communicating with the specific module implementation.
+ *
+ * One module can support multiple devices with different versions. This
+ * can be useful when a device interface changes in an incompatible way
+ * but it is still necessary to support older implementations at the same
+ * time. One such example is the Camera 2.0 API.
+ *
+ * This field is interpreted by the module user and is ignored by the
+ * HAL interface itself.
+ */
uint32_t version;
/** reference to the module this device belongs to */
diff --git a/include/hardware/hwcomposer.h b/include/hardware/hwcomposer.h
index b4a7a7a..98e665c 100644
--- a/include/hardware/hwcomposer.h
+++ b/include/hardware/hwcomposer.h
@@ -24,11 +24,16 @@
#include <hardware/hardware.h>
#include <cutils/native_handle.h>
+#include <hardware/hwcomposer_defs.h>
+
__BEGIN_DECLS
/*****************************************************************************/
-#define HWC_API_VERSION 1
+// for compatibility
+#define HWC_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1
+#define HWC_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1
+#define HWC_API_VERSION HWC_DEVICE_API_VERSION
/**
* The id of this module
@@ -41,87 +46,39 @@
#define HWC_HARDWARE_COMPOSER "composer"
-enum {
- /* hwc_composer_device_t::set failed in EGL */
- HWC_EGL_ERROR = -1
-};
+struct hwc_composer_device;
/*
- * hwc_layer_t::hints values
- * Hints are set by the HAL and read by SurfaceFlinger
+ * availability: HWC_DEVICE_API_VERSION_0_3
+ *
+ * struct hwc_methods cannot be embedded in other structures as
+ * sizeof(struct hwc_methods) cannot be relied upon.
+ *
*/
-enum {
- /*
- * HWC can set the HWC_HINT_TRIPLE_BUFFER hint to indicate to SurfaceFlinger
- * that it should triple buffer this layer. Typically HWC does this when
- * the layer will be unavailable for use for an extended period of time,
- * e.g. if the display will be fetching data directly from the layer and
- * the layer can not be modified until after the next set().
- */
- HWC_HINT_TRIPLE_BUFFER = 0x00000001,
+typedef struct hwc_methods {
+
+ /*************************************************************************
+ * HWC_DEVICE_API_VERSION_0_3
+ *************************************************************************/
/*
- * HWC sets HWC_HINT_CLEAR_FB to tell SurfaceFlinger that it should clear the
- * framebuffer with transparent pixels where this layer would be.
- * SurfaceFlinger will only honor this flag when the layer has no blending
+ * eventControl(..., event, enabled)
+ * Enables or disables h/w composer events.
*
+ * eventControl can be called from any thread and takes effect
+ * immediately.
+ *
+ * Supported events are:
+ * HWC_EVENT_VSYNC
+ *
+ * returns -EINVAL if the "event" parameter is not one of the value above
+ * or if the "enabled" parameter is not 0 or 1.
*/
- HWC_HINT_CLEAR_FB = 0x00000002
-};
-/*
- * hwc_layer_t::flags values
- * Flags are set by SurfaceFlinger and read by the HAL
- */
-enum {
- /*
- * HWC_SKIP_LAYER is set by SurfaceFlnger to indicate that the HAL
- * shall not consider this layer for composition as it will be handled
- * by SurfaceFlinger (just as if compositionType was set to HWC_OVERLAY).
- */
- HWC_SKIP_LAYER = 0x00000001,
-};
+ int (*eventControl)(
+ struct hwc_composer_device* dev, int event, int enabled);
-/*
- * hwc_layer_t::compositionType values
- */
-enum {
- /* this layer is to be drawn into the framebuffer by SurfaceFlinger */
- HWC_FRAMEBUFFER = 0,
-
- /* this layer will be handled in the HWC */
- HWC_OVERLAY = 1,
-};
-
-/*
- * hwc_layer_t::blending values
- */
-enum {
- /* no blending */
- HWC_BLENDING_NONE = 0x0100,
-
- /* ONE / ONE_MINUS_SRC_ALPHA */
- HWC_BLENDING_PREMULT = 0x0105,
-
- /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
- HWC_BLENDING_COVERAGE = 0x0405
-};
-
-/*
- * hwc_layer_t::transform values
- */
-enum {
- /* flip source image horizontally */
- HWC_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
- /* flip source image vertically */
- HWC_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
- /* rotate source image 90 degrees clock-wise */
- HWC_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
- /* rotate source image 180 degrees */
- HWC_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
- /* rotate source image 270 degrees clock-wise */
- HWC_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
-};
+} hwc_methods_t;
typedef struct hwc_rect {
int left;
@@ -135,12 +92,29 @@
hwc_rect_t const* rects;
} hwc_region_t;
+typedef struct hwc_color {
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ uint8_t a;
+} hwc_color_t;
+
typedef struct hwc_layer {
/*
- * initially set to HWC_FRAMEBUFFER, indicates the layer will
- * be drawn into the framebuffer using OpenGL ES.
- * The HWC can toggle this value to HWC_OVERLAY, to indicate
- * it will handle the layer.
+ * initially set to HWC_FRAMEBUFFER or HWC_BACKGROUND.
+ * HWC_FRAMEBUFFER
+ * indicates the layer will be drawn into the framebuffer
+ * using OpenGL ES.
+ * The HWC can toggle this value to HWC_OVERLAY, to indicate
+ * it will handle the layer.
+ *
+ * HWC_BACKGROUND
+ * indicates this is a special "background" layer. The only valid
+ * field is backgroundColor. HWC_BACKGROUND can only be used with
+ * HWC_API_VERSION >= 0.2
+ * The HWC can toggle this value to HWC_FRAMEBUFFER, to indicate
+ * it CANNOT handle the background color
+ *
*/
int32_t compositionType;
@@ -150,31 +124,42 @@
/* see hwc_layer_t::flags above */
uint32_t flags;
- /* handle of buffer to compose. this handle is guaranteed to have been
- * allocated with gralloc */
- buffer_handle_t handle;
+ union {
+ /* color of the background. hwc_color_t.a is ignored */
+ hwc_color_t backgroundColor;
- /* transformation to apply to the buffer during composition */
- uint32_t transform;
+ struct {
+ /* handle of buffer to compose. This handle is guaranteed to have been
+ * allocated from gralloc using the GRALLOC_USAGE_HW_COMPOSER usage flag. If
+ * the layer's handle is unchanged across two consecutive prepare calls and
+ * the HWC_GEOMETRY_CHANGED flag is not set for the second call then the
+ * HWComposer implementation may assume that the contents of the buffer have
+ * not changed. */
+ buffer_handle_t handle;
- /* blending to apply during composition */
- int32_t blending;
+ /* transformation to apply to the buffer during composition */
+ uint32_t transform;
- /* area of the source to consider, the origin is the top-left corner of
- * the buffer */
- hwc_rect_t sourceCrop;
+ /* blending to apply during composition */
+ int32_t blending;
- /* where to composite the sourceCrop onto the display. The sourceCrop
- * is scaled using linear filtering to the displayFrame. The origin is the
- * top-left corner of the screen.
- */
- hwc_rect_t displayFrame;
+ /* area of the source to consider, the origin is the top-left corner of
+ * the buffer */
+ hwc_rect_t sourceCrop;
- /* visible region in screen space. The origin is the
- * top-left corner of the screen.
- * The visible region INCLUDES areas overlapped by a translucent layer.
- */
- hwc_region_t visibleRegionScreen;
+ /* where to composite the sourceCrop onto the display. The sourceCrop
+ * is scaled using linear filtering to the displayFrame. The origin is the
+ * top-left corner of the screen.
+ */
+ hwc_rect_t displayFrame;
+
+ /* visible region in screen space. The origin is the
+ * top-left corner of the screen.
+ * The visible region INCLUDES areas overlapped by a translucent layer.
+ */
+ hwc_region_t visibleRegionScreen;
+ };
+ };
} hwc_layer_t;
@@ -221,6 +206,28 @@
* hooks, unless noted otherwise.
*/
void (*invalidate)(struct hwc_procs* procs);
+
+ /*
+ * (*vsync)() is called by the h/w composer HAL when a vsync event is
+ * received and HWC_EVENT_VSYNC is enabled (see: hwc_event_control).
+ *
+ * the "zero" parameter must always be 0.
+ * the "timestamp" parameter is the system monotonic clock timestamp in
+ * nanosecond of when the vsync event happened.
+ *
+ * vsync() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL.
+ *
+ * It is expected that vsync() is called from a thread of at least
+ * HAL_PRIORITY_URGENT_DISPLAY with as little latency as possible,
+ * typically less than 0.5 ms.
+ *
+ * It is a (silent) error to have HWC_EVENT_VSYNC enabled when calling
+ * hwc_composer_device.set(..., 0, 0, 0) (screen off). The implementation
+ * can either stop or continue to process VSYNC events, but must not
+ * crash or cause other problems.
+ *
+ */
+ void (*vsync)(struct hwc_procs* procs, int zero, int64_t timestamp);
} hwc_procs_t;
@@ -307,14 +314,14 @@
hwc_surface_t sur,
hwc_layer_list_t* list);
/*
- * This hook is OPTIONAL.
+ * This field is OPTIONAL and can be NULL.
*
* If non NULL it will be called by SurfaceFlinger on dumpsys
*/
void (*dump)(struct hwc_composer_device* dev, char *buff, int buff_len);
/*
- * This hook is OPTIONAL.
+ * This field is OPTIONAL and can be NULL.
*
* (*registerProcs)() registers a set of callbacks the h/w composer HAL
* can later use. It is FORBIDDEN to call any of the callbacks from
@@ -329,7 +336,26 @@
void (*registerProcs)(struct hwc_composer_device* dev,
hwc_procs_t const* procs);
- void* reserved_proc[6];
+ /*
+ * This field is OPTIONAL and can be NULL.
+ * availability: HWC_DEVICE_API_VERSION_0_2
+ *
+ * Used to retrieve information about the h/w composer
+ *
+ * Returns 0 on success or -errno on error.
+ */
+ int (*query)(struct hwc_composer_device* dev, int what, int* value);
+
+ /*
+ * Reserved for future use. Must be NULL.
+ */
+ void* reserved_proc[4];
+
+ /*
+ * This field is OPTIONAL and can be NULL.
+ * availability: HWC_DEVICE_API_VERSION_0_3
+ */
+ hwc_methods_t const *methods;
} hwc_composer_device_t;
diff --git a/include/hardware/hwcomposer_defs.h b/include/hardware/hwcomposer_defs.h
new file mode 100644
index 0000000..99465d3
--- /dev/null
+++ b/include/hardware/hwcomposer_defs.h
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2010 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_HWCOMPOSER_DEFS_H
+#define ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_DEFS_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+
+#include <hardware/gralloc.h>
+#include <hardware/hardware.h>
+#include <cutils/native_handle.h>
+
+__BEGIN_DECLS
+
+/*****************************************************************************/
+
+#define HWC_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+
+#define HWC_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1)
+#define HWC_DEVICE_API_VERSION_0_2 HARDWARE_DEVICE_API_VERSION(0, 2)
+#define HWC_DEVICE_API_VERSION_0_3 HARDWARE_DEVICE_API_VERSION(0, 3)
+
+
+enum {
+ /* hwc_composer_device_t::set failed in EGL */
+ HWC_EGL_ERROR = -1
+};
+
+/*
+ * hwc_layer_t::hints values
+ * Hints are set by the HAL and read by SurfaceFlinger
+ */
+enum {
+ /*
+ * HWC can set the HWC_HINT_TRIPLE_BUFFER hint to indicate to SurfaceFlinger
+ * that it should triple buffer this layer. Typically HWC does this when
+ * the layer will be unavailable for use for an extended period of time,
+ * e.g. if the display will be fetching data directly from the layer and
+ * the layer can not be modified until after the next set().
+ */
+ HWC_HINT_TRIPLE_BUFFER = 0x00000001,
+
+ /*
+ * HWC sets HWC_HINT_CLEAR_FB to tell SurfaceFlinger that it should clear the
+ * framebuffer with transparent pixels where this layer would be.
+ * SurfaceFlinger will only honor this flag when the layer has no blending
+ *
+ */
+ HWC_HINT_CLEAR_FB = 0x00000002
+};
+
+/*
+ * hwc_layer_t::flags values
+ * Flags are set by SurfaceFlinger and read by the HAL
+ */
+enum {
+ /*
+ * HWC_SKIP_LAYER is set by SurfaceFlnger to indicate that the HAL
+ * shall not consider this layer for composition as it will be handled
+ * by SurfaceFlinger (just as if compositionType was set to HWC_OVERLAY).
+ */
+ HWC_SKIP_LAYER = 0x00000001,
+};
+
+/*
+ * hwc_layer_t::compositionType values
+ */
+enum {
+ /* this layer is to be drawn into the framebuffer by SurfaceFlinger */
+ HWC_FRAMEBUFFER = 0,
+
+ /* this layer will be handled in the HWC */
+ HWC_OVERLAY = 1,
+
+ /* this is the background layer. it's used to set the background color.
+ * there is only a single background layer */
+ HWC_BACKGROUND = 2,
+};
+
+/*
+ * hwc_layer_t::blending values
+ */
+enum {
+ /* no blending */
+ HWC_BLENDING_NONE = 0x0100,
+
+ /* ONE / ONE_MINUS_SRC_ALPHA */
+ HWC_BLENDING_PREMULT = 0x0105,
+
+ /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
+ HWC_BLENDING_COVERAGE = 0x0405
+};
+
+/*
+ * hwc_layer_t::transform values
+ */
+enum {
+ /* flip source image horizontally */
+ HWC_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
+ /* flip source image vertically */
+ HWC_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
+ /* rotate source image 90 degrees clock-wise */
+ HWC_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
+ /* rotate source image 180 degrees */
+ HWC_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
+ /* rotate source image 270 degrees clock-wise */
+ HWC_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
+};
+
+/* attributes queriable with query() */
+enum {
+ /*
+ * availability: HWC_DEVICE_API_VERSION_0_2
+ * must return 1 if the background layer is supported, 0 otherwise
+ */
+ HWC_BACKGROUND_LAYER_SUPPORTED = 0,
+
+ /*
+ * availability: HWC_DEVICE_API_VERSION_0_3
+ * returns the vsync period in nanosecond
+ */
+ HWC_VSYNC_PERIOD = 1,
+};
+
+/* Allowed events for hwc_methods::eventControl() */
+enum {
+ HWC_EVENT_VSYNC = 0
+};
+
+/*****************************************************************************/
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_DEFS_H */
diff --git a/include/hardware/keymaster.h b/include/hardware/keymaster.h
new file mode 100644
index 0000000..e0014c8
--- /dev/null
+++ b/include/hardware/keymaster.h
@@ -0,0 +1,214 @@
+/*
+ * 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"
+
+/**
+ * The API level of this version of the header. The allows the implementing
+ * module to recognize which API level of the client it is dealing with in
+ * the case of pre-compiled binary clients.
+ */
+#define KEYMASTER_API_VERSION 1
+
+/**
+ * Flags for keymaster_device::flags
+ */
+enum {
+ /*
+ * Indicates this keymaster implementation does not have hardware that
+ * keeps private keys out of user space.
+ *
+ * This should not be implemented on anything other than the default
+ * implementation.
+ */
+ KEYMASTER_SOFTWARE_ONLY = 0x00000001,
+};
+
+struct keystore_module {
+ hw_module_t common;
+};
+
+/**
+ * Asymmetric key pair types.
+ */
+typedef enum {
+ TYPE_RSA = 1,
+} keymaster_keypair_t;
+
+/**
+ * Parameters needed to generate an RSA key.
+ */
+typedef struct {
+ uint32_t modulus_size;
+ uint64_t public_exponent;
+} keymaster_rsa_keygen_params_t;
+
+/**
+ * Digest type used for RSA operations.
+ */
+typedef enum {
+ DIGEST_NONE,
+} keymaster_rsa_digest_t;
+
+/**
+ * Type of padding used for RSA operations.
+ */
+typedef enum {
+ PADDING_NONE,
+} keymaster_rsa_padding_t;
+
+typedef struct {
+ keymaster_rsa_digest_t digest_type;
+ keymaster_rsa_padding_t padding_type;
+} keymaster_rsa_sign_params_t;
+
+/**
+ * The parameters that can be set for a given keymaster implementation.
+ */
+struct keymaster_device {
+ struct hw_device_t common;
+
+ uint32_t client_version;
+
+ /**
+ * See flags defined for keymaster_device::flags above.
+ */
+ uint32_t flags;
+
+ void* context;
+
+ /**
+ * Generates a public and private key. The key-blob returned is opaque
+ * and must subsequently provided for signing and verification.
+ *
+ * Returns: 0 on success or an error code less than 0.
+ */
+ int (*generate_keypair)(const struct keymaster_device* dev,
+ const keymaster_keypair_t key_type, const void* key_params,
+ uint8_t** key_blob, size_t* key_blob_length);
+
+ /**
+ * Imports a public and private key pair. The imported keys will be in
+ * PKCS#8 format with DER encoding (Java standard). The key-blob
+ * returned is opaque and will 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,
+ const uint8_t* key, const size_t key_length,
+ uint8_t** key_blob, size_t* key_blob_length);
+
+ /**
+ * Gets the public key part of a key pair. The public key must be in
+ * X.509 format (Java standard) encoded byte array.
+ *
+ * Returns: 0 on success or an error code less than 0.
+ * On error, x509_data should not be allocated.
+ */
+ int (*get_keypair_public)(const struct keymaster_device* dev,
+ const uint8_t* key_blob, const size_t key_blob_length,
+ uint8_t** x509_data, size_t* x509_data_length);
+
+ /**
+ * Deletes the key pair associated with the key blob.
+ *
+ * This function is optional and should be set to NULL if it is not
+ * implemented.
+ *
+ * Returns 0 on success or an error code less than 0.
+ */
+ int (*delete_keypair)(const struct keymaster_device* dev,
+ const uint8_t* key_blob, const size_t key_blob_length);
+
+ /**
+ * Deletes all keys in the hardware keystore. Used when keystore is
+ * reset completely.
+ *
+ * This function is optional and should be set to NULL if it is not
+ * implemented.
+ *
+ * Returns 0 on success or an error code less than 0.
+ */
+ int (*delete_all)(const struct keymaster_device* dev);
+
+ /**
+ * Signs data using a key-blob generated before. This can use either
+ * an asymmetric key or a secret key.
+ *
+ * Returns: 0 on success or an error code less than 0.
+ */
+ int (*sign_data)(const struct keymaster_device* dev,
+ const void* signing_params,
+ const uint8_t* key_blob, const size_t key_blob_length,
+ const uint8_t* data, const size_t data_length,
+ uint8_t** signed_data, size_t* signed_data_length);
+
+ /**
+ * Verifies data signed with a key-blob. This can use either
+ * an asymmetric key or a secret key.
+ *
+ * Returns: 0 on successful verification or an error code less than 0.
+ */
+ int (*verify_data)(const struct keymaster_device* dev,
+ const void* signing_params,
+ const uint8_t* key_blob, const size_t key_blob_length,
+ const uint8_t* signed_data, const size_t signed_data_length,
+ const uint8_t* signature, const size_t signature_length);
+};
+typedef struct keymaster_device keymaster_device_t;
+
+
+/* Convenience API for opening and closing keymaster devices */
+
+static inline int keymaster_open(const struct hw_module_t* module,
+ keymaster_device_t** device)
+{
+ int rc = module->methods->open(module, KEYSTORE_KEYMASTER,
+ (struct hw_device_t**) device);
+
+ if (!rc) {
+ (*device)->client_version = KEYMASTER_API_VERSION;
+ }
+
+ return rc;
+}
+
+static inline int keymaster_close(keymaster_device_t* device)
+{
+ return device->common.close(&device->common);
+}
+
+__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/nfc.h b/include/hardware/nfc.h
index ca3683b..74b3cfb 100644
--- a/include/hardware/nfc.h
+++ b/include/hardware/nfc.h
@@ -76,6 +76,11 @@
* Set to 0 to disable the workaround, 1 to enable it.
*/
uint8_t enable_i2c_workaround;
+ /* I2C slave address. Multiple I2C addresses are
+ * possible for PN544 module. Configure address according to
+ * board design.
+ */
+ uint8_t i2c_device_address;
} nfc_pn544_device_t;
static inline int nfc_pn544_open(const struct hw_module_t* module,
diff --git a/include/hardware/power.h b/include/hardware/power.h
new file mode 100644
index 0000000..6c55061
--- /dev/null
+++ b/include/hardware/power.h
@@ -0,0 +1,123 @@
+/*
+ * 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
+
+#define POWER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+#define POWER_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2)
+
+
+/**
+ * The id of this module
+ */
+#define POWER_HARDWARE_MODULE_ID "power"
+
+/*
+ * Power hint identifiers passed to (*powerHint)
+ */
+
+typedef enum {
+ POWER_HINT_VSYNC = 0x00000001,
+ POWER_HINT_INTERACTION = 0x00000002,
+} power_hint_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.
+ */
+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. This is
+ * called only by the Power HAL instance loaded by
+ * PowerManagerService.
+ */
+ 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);
+
+ /*
+ * (*powerHint) is called to pass hints on power requirements, which
+ * may result in adjustment of power/performance parameters of the
+ * cpufreq governor and other controls. The possible hints are:
+ *
+ * POWER_HINT_VSYNC
+ *
+ * Foreground app has started or stopped requesting a VSYNC pulse
+ * from SurfaceFlinger. If the app has started requesting VSYNC
+ * then CPU and GPU load is expected soon, and it may be appropriate
+ * to raise speeds of CPU, memory bus, etc. The data parameter is
+ * non-zero to indicate VSYNC pulse is now requested, or zero for
+ * VSYNC pulse no longer requested.
+ *
+ * POWER_HINT_INTERACTION
+ *
+ * User is interacting with the device, for example, touchscreen
+ * events are incoming. CPU and GPU load may be expected soon,
+ * and it may be appropriate to raise speeds of CPU, memory bus,
+ * etc. The data parameter is unused.
+ *
+ * A particular platform may choose to ignore any hint.
+ *
+ * availability: version 0.2
+ *
+ */
+ void (*powerHint)(struct power_module *module, power_hint_t hint,
+ void *data);
+} power_module_t;
+
+
+__END_DECLS
+
+#endif // ANDROID_INCLUDE_HARDWARE_POWER_H
diff --git a/modules/Android.mk b/modules/Android.mk
index 6231e78..871b984 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 usbaudio
include $(call all-named-subdir-makefiles,$(hardware_modules))
diff --git a/modules/audio/audio_hw.c b/modules/audio/audio_hw.c
index a482604..d860437 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,8 +214,10 @@
}
static int adev_open_output_stream(struct audio_hw_device *dev,
- uint32_t devices, int *format,
- uint32_t *channels, uint32_t *sample_rate,
+ audio_io_handle_t handle,
+ audio_devices_t devices,
+ audio_output_flags_t flags,
+ struct audio_config *config,
struct audio_stream_out **stream_out)
{
struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
@@ -236,6 +244,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 +287,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,16 +309,15 @@
}
static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
- uint32_t sample_rate, int format,
- int channel_count)
+ const struct audio_config *config)
{
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,
+static int adev_open_input_stream(struct audio_hw_device *dev,
+ audio_io_handle_t handle,
+ audio_devices_t devices,
+ struct audio_config *config,
struct audio_stream_in **stream_in)
{
struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
@@ -393,7 +407,7 @@
return -ENOMEM;
adev->device.common.tag = HARDWARE_DEVICE_TAG;
- adev->device.common.version = 0;
+ adev->device.common.version = AUDIO_DEVICE_API_VERSION_1_0;
adev->device.common.module = (struct hw_module_t *) module;
adev->device.common.close = adev_close;
@@ -401,6 +415,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;
@@ -425,8 +440,8 @@
struct audio_module HAL_MODULE_INFO_SYM = {
.common = {
.tag = HARDWARE_MODULE_TAG,
- .version_major = 1,
- .version_minor = 0,
+ .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
+ .hal_api_version = HARDWARE_HAL_API_VERSION,
.id = AUDIO_HARDWARE_MODULE_ID,
.name = "Default audio HW HAL",
.author = "The Android Open Source Project",
diff --git a/modules/audio/audio_policy.c b/modules/audio/audio_policy.c
index 409f0a1..ee95e92 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,9 +97,9 @@
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)
+ audio_output_flags_t flags)
{
return 0;
}
@@ -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,13 +164,29 @@
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)
{
return 0;
}
-static uint32_t ap_get_devices_for_stream(const struct audio_policy *pol,
+static audio_devices_t ap_get_devices_for_stream(const struct audio_policy *pol,
audio_stream_type_t stream)
{
return 0;
@@ -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 52c838b..326f2ae 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 = <dev->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/nfc/nfc_hw_example.c b/modules/nfc/nfc_hw_example.c
index 9769282..54c9c56 100644
--- a/modules/nfc/nfc_hw_example.c
+++ b/modules/nfc/nfc_hw_example.c
@@ -44,6 +44,7 @@
dev->linktype = PN544_LINK_TYPE_INVALID;
dev->device_node = NULL;
dev->enable_i2c_workaround = 0;
+ dev->i2c_device_address = 0;
*device = (hw_device_t*) dev;
return 0;
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..7cacc09
--- /dev/null
+++ b/modules/power/power.c
@@ -0,0 +1,62 @@
+/*
+ * 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>
+
+static void power_init(struct power_module *module)
+{
+}
+
+static void power_set_interactive(struct power_module *module, int on)
+{
+}
+
+static void power_hint(struct power_module *module, power_hint_t hint,
+ void *data) {
+ switch (hint) {
+ default:
+ break;
+ }
+}
+
+static struct hw_module_methods_t power_module_methods = {
+ .open = NULL,
+};
+
+struct power_module HAL_MODULE_INFO_SYM = {
+ .common = {
+ .tag = HARDWARE_MODULE_TAG,
+ .module_api_version = POWER_MODULE_API_VERSION_0_2,
+ .hal_api_version = HARDWARE_HAL_API_VERSION,
+ .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,
+ .powerHint = power_hint,
+};
diff --git a/modules/usbaudio/Android.mk b/modules/usbaudio/Android.mk
new file mode 100644
index 0000000..6b5e66d
--- /dev/null
+++ b/modules/usbaudio/Android.mk
@@ -0,0 +1,29 @@
+# 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := audio.usb.default
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_SRC_FILES := \
+ audio_hw.c
+LOCAL_C_INCLUDES += \
+ external/tinyalsa/include
+LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
+
diff --git a/modules/usbaudio/audio_hw.c b/modules/usbaudio/audio_hw.c
new file mode 100644
index 0000000..9283016
--- /dev/null
+++ b/modules/usbaudio/audio_hw.c
@@ -0,0 +1,440 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "usb_audio_hw"
+/*#define LOG_NDEBUG 0*/
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <sys/time.h>
+#include <stdlib.h>
+
+#include <cutils/log.h>
+#include <cutils/str_parms.h>
+#include <cutils/properties.h>
+
+#include <hardware/hardware.h>
+#include <system/audio.h>
+#include <hardware/audio.h>
+
+#include <tinyalsa/asoundlib.h>
+
+struct pcm_config pcm_config = {
+ .channels = 2,
+ .rate = 44100,
+ .period_size = 1024,
+ .period_count = 4,
+ .format = PCM_FORMAT_S16_LE,
+};
+
+struct audio_device {
+ struct audio_hw_device hw_device;
+
+ pthread_mutex_t lock; /* see note below on mutex acquisition order */
+ int card;
+ int device;
+ bool standby;
+};
+
+struct stream_out {
+ struct audio_stream_out stream;
+
+ pthread_mutex_t lock; /* see note below on mutex acquisition order */
+ struct pcm *pcm;
+ bool standby;
+
+ struct audio_device *dev;
+};
+
+/**
+ * NOTE: when multiple mutexes have to be acquired, always respect the
+ * following order: hw device > out stream
+ */
+
+/* Helper functions */
+
+/* must be called with hw device and output stream mutexes locked */
+static int start_output_stream(struct stream_out *out)
+{
+ struct audio_device *adev = out->dev;
+ int i;
+
+ if ((adev->card < 0) || (adev->device < 0))
+ return -EINVAL;
+
+ out->pcm = pcm_open(adev->card, adev->device, PCM_OUT, &pcm_config);
+
+ if (out->pcm && !pcm_is_ready(out->pcm)) {
+ ALOGE("pcm_open() failed: %s", pcm_get_error(out->pcm));
+ pcm_close(out->pcm);
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+/* API functions */
+
+static uint32_t out_get_sample_rate(const struct audio_stream *stream)
+{
+ return pcm_config.rate;
+}
+
+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 pcm_config.period_size *
+ audio_stream_frame_size((struct audio_stream *)stream);
+}
+
+static uint32_t out_get_channels(const struct audio_stream *stream)
+{
+ return AUDIO_CHANNEL_OUT_STEREO;
+}
+
+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, audio_format_t format)
+{
+ return 0;
+}
+
+static int out_standby(struct audio_stream *stream)
+{
+ struct stream_out *out = (struct stream_out *)stream;
+
+ pthread_mutex_lock(&out->dev->lock);
+ pthread_mutex_lock(&out->lock);
+
+ if (!out->standby) {
+ pcm_close(out->pcm);
+ out->pcm = NULL;
+ out->standby = true;
+ }
+
+ pthread_mutex_unlock(&out->lock);
+ pthread_mutex_unlock(&out->dev->lock);
+
+ 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)
+{
+ struct stream_out *out = (struct stream_out *)stream;
+ struct audio_device *adev = out->dev;
+ struct str_parms *parms;
+ char value[32];
+ int ret;
+ int routing = 0;
+
+ parms = str_parms_create_str(kvpairs);
+ pthread_mutex_lock(&adev->lock);
+
+ ret = str_parms_get_str(parms, "card", value, sizeof(value));
+ if (ret >= 0)
+ adev->card = atoi(value);
+
+ ret = str_parms_get_str(parms, "device", value, sizeof(value));
+ if (ret >= 0)
+ adev->device = atoi(value);
+
+ pthread_mutex_unlock(&adev->lock);
+ str_parms_destroy(parms);
+
+ 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 (pcm_config.period_size * pcm_config.period_count * 1000) /
+ out_get_sample_rate(&stream->common);
+}
+
+static int out_set_volume(struct audio_stream_out *stream, float left,
+ float right)
+{
+ return -ENOSYS;
+}
+
+static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
+ size_t bytes)
+{
+ int ret;
+ struct stream_out *out = (struct stream_out *)stream;
+
+ pthread_mutex_lock(&out->dev->lock);
+ pthread_mutex_lock(&out->lock);
+ if (out->standby) {
+ ret = start_output_stream(out);
+ if (ret != 0) {
+ goto err;
+ }
+ out->standby = false;
+ }
+
+ pcm_write(out->pcm, (void *)buffer, bytes);
+
+ pthread_mutex_unlock(&out->lock);
+ pthread_mutex_unlock(&out->dev->lock);
+
+ return bytes;
+
+err:
+ pthread_mutex_unlock(&out->lock);
+
+ if (ret != 0) {
+ 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;
+}
+
+static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
+{
+ return 0;
+}
+
+static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
+{
+ return 0;
+}
+
+static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
+ int64_t *timestamp)
+{
+ return -EINVAL;
+}
+
+static int adev_open_output_stream(struct audio_hw_device *dev,
+ audio_io_handle_t handle,
+ audio_devices_t devices,
+ audio_output_flags_t flags,
+ struct audio_config *config,
+ struct audio_stream_out **stream_out)
+{
+ struct audio_device *adev = (struct audio_device *)dev;
+ struct stream_out *out;
+ int ret;
+
+ out = (struct stream_out *)calloc(1, sizeof(struct 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.common.add_audio_effect = out_add_audio_effect;
+ out->stream.common.remove_audio_effect = out_remove_audio_effect;
+ 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;
+ out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
+
+ out->dev = adev;
+
+ config->format = out_get_format(&out->stream.common);
+ config->channel_mask = out_get_channels(&out->stream.common);
+ config->sample_rate = out_get_sample_rate(&out->stream.common);
+
+ out->standby = true;
+
+ adev->card = -1;
+ adev->device = -1;
+
+ *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)
+{
+ struct stream_out *out = (struct stream_out *)stream;
+
+ out_standby(&stream->common);
+ free(stream);
+}
+
+static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
+{
+ return 0;
+}
+
+static char * adev_get_parameters(const struct audio_hw_device *dev,
+ const char *keys)
+{
+ return strdup("");
+}
+
+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, audio_mode_t 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,
+ const struct audio_config *config)
+{
+ return 0;
+}
+
+static int adev_open_input_stream(struct audio_hw_device *dev,
+ audio_io_handle_t handle,
+ audio_devices_t devices,
+ struct audio_config *config,
+ struct audio_stream_in **stream_in)
+{
+ return -ENOSYS;
+}
+
+static void adev_close_input_stream(struct audio_hw_device *dev,
+ struct audio_stream_in *stream)
+{
+}
+
+static int adev_dump(const audio_hw_device_t *device, int fd)
+{
+ return 0;
+}
+
+static int adev_close(hw_device_t *device)
+{
+ struct audio_device *adev = (struct audio_device *)device;
+
+ free(device);
+ return 0;
+}
+
+static uint32_t adev_get_supported_devices(const struct audio_hw_device *dev)
+{
+ return AUDIO_DEVICE_OUT_ALL_USB;
+}
+
+static int adev_open(const hw_module_t* module, const char* name,
+ hw_device_t** device)
+{
+ struct audio_device *adev;
+ int ret;
+
+ if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
+ return -EINVAL;
+
+ adev = calloc(1, sizeof(struct audio_device));
+ if (!adev)
+ return -ENOMEM;
+
+ adev->hw_device.common.tag = HARDWARE_DEVICE_TAG;
+ adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_1_0;
+ adev->hw_device.common.module = (struct hw_module_t *) module;
+ adev->hw_device.common.close = adev_close;
+
+ adev->hw_device.get_supported_devices = adev_get_supported_devices;
+ adev->hw_device.init_check = adev_init_check;
+ adev->hw_device.set_voice_volume = adev_set_voice_volume;
+ adev->hw_device.set_master_volume = adev_set_master_volume;
+ adev->hw_device.set_mode = adev_set_mode;
+ adev->hw_device.set_mic_mute = adev_set_mic_mute;
+ adev->hw_device.get_mic_mute = adev_get_mic_mute;
+ adev->hw_device.set_parameters = adev_set_parameters;
+ adev->hw_device.get_parameters = adev_get_parameters;
+ adev->hw_device.get_input_buffer_size = adev_get_input_buffer_size;
+ adev->hw_device.open_output_stream = adev_open_output_stream;
+ adev->hw_device.close_output_stream = adev_close_output_stream;
+ adev->hw_device.open_input_stream = adev_open_input_stream;
+ adev->hw_device.close_input_stream = adev_close_input_stream;
+ adev->hw_device.dump = adev_dump;
+
+ *device = &adev->hw_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,
+ .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
+ .hal_api_version = HARDWARE_HAL_API_VERSION,
+ .id = AUDIO_HARDWARE_MODULE_ID,
+ .name = "USB audio HW HAL",
+ .author = "The Android Open Source Project",
+ .methods = &hal_module_methods,
+ },
+};
diff --git a/tests/camera2/Android.mk b/tests/camera2/Android.mk
new file mode 100644
index 0000000..340ec30
--- /dev/null
+++ b/tests/camera2/Android.mk
@@ -0,0 +1,27 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ camera2.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+ libutils \
+ libstlport \
+ libhardware \
+ libcamera_metadata
+
+LOCAL_STATIC_LIBRARIES := \
+ libgtest \
+ libgtest_main
+
+LOCAL_C_INCLUDES += \
+ bionic \
+ bionic/libstdc++/include \
+ external/gtest/include \
+ external/stlport/stlport \
+ system/media/camera/include \
+
+LOCAL_MODULE:= camera2_hal_tests
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_EXECUTABLE)
diff --git a/tests/camera2/camera2.cpp b/tests/camera2/camera2.cpp
new file mode 100644
index 0000000..d13d7cd
--- /dev/null
+++ b/tests/camera2/camera2.cpp
@@ -0,0 +1,123 @@
+/*
+ * 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 <system/camera_metadata.h>
+#include <hardware/camera2.h>
+#include <gtest/gtest.h>
+#include <iostream>
+
+class Camera2Test: public testing::Test {
+ public:
+ static void SetUpTestCase() {
+ int res;
+
+ hw_module_t *module = NULL;
+ res = hw_get_module(CAMERA_HARDWARE_MODULE_ID,
+ (const hw_module_t **)&module);
+
+ ASSERT_EQ(0, res)
+ << "Failure opening camera hardware module: " << res;
+ ASSERT_TRUE(NULL != module)
+ << "No camera module was set by hw_get_module";
+
+ std::cout << " Camera module name: " << module->name << std::endl;
+ std::cout << " Camera module author: " << module->author << std::endl;
+ std::cout << " Camera module API version: 0x" << std::hex
+ << module->module_api_version << std::endl;
+ std::cout << " Camera module HAL API version: 0x" << std::hex
+ << module->hal_api_version << std::endl;
+
+ int16_t version2_0 = CAMERA_MODULE_API_VERSION_2_0;
+ ASSERT_EQ(version2_0, module->module_api_version)
+ << "Camera module version is 0x"
+ << std::hex << module->module_api_version
+ << ", not 2.0. (0x"
+ << std::hex << CAMERA_MODULE_API_VERSION_2_0 << ")";
+
+ sCameraModule = reinterpret_cast<camera_module_t*>(module);
+
+ sNumCameras = sCameraModule->get_number_of_cameras();
+ ASSERT_LT(0, sNumCameras) << "No camera devices available!";
+
+ std::cout << " Camera device count: " << sNumCameras << std::endl;
+ sCameraSupportsHal2 = new bool[sNumCameras];
+
+ for (int i = 0; i < sNumCameras; i++) {
+ camera_info info;
+ res = sCameraModule->get_camera_info(i, &info);
+ ASSERT_EQ(0, res)
+ << "Failure getting camera info for camera " << i;
+ std::cout << " Camera device: " << std::dec
+ << i << std::endl;;
+ std::cout << " Facing: " << std::dec
+ << info.facing << std::endl;
+ std::cout << " Orientation: " << std::dec
+ << info.orientation << std::endl;
+ std::cout << " Version: 0x" << std::hex <<
+ info.device_version << std::endl;
+ if (info.device_version >= CAMERA_DEVICE_API_VERSION_2_0) {
+ sCameraSupportsHal2[i] = true;
+ ASSERT_TRUE(NULL != info.static_camera_characteristics);
+ std::cout << " Static camera metadata:" << std::endl;
+ dump_camera_metadata(info.static_camera_characteristics, 0, 1);
+ } else {
+ sCameraSupportsHal2[i] = false;
+ }
+ }
+ }
+
+ static const camera_module_t *getCameraModule() {
+ return sCameraModule;
+ }
+
+ static const camera2_device_t *openCameraDevice(int id) {
+ if (NULL == sCameraSupportsHal2) return NULL;
+ if (id >= sNumCameras) return NULL;
+ if (!sCameraSupportsHal2[id]) return NULL;
+
+ hw_device_t *device = NULL;
+ const camera_module_t *cam_module = getCameraModule();
+ char camId[10];
+ int res;
+
+ snprintf(camId, 10, "%d", id);
+ res = cam_module->common.methods->open(
+ (const hw_module_t*)cam_module,
+ camId,
+ &device);
+ if (res < 0 || cam_module == NULL) {
+ return NULL;
+ }
+ camera2_device_t *cam_device =
+ reinterpret_cast<camera2_device_t*>(device);
+ return cam_device;
+ }
+
+ private:
+
+ static camera_module_t *sCameraModule;
+ static int sNumCameras;
+ static bool *sCameraSupportsHal2;
+};
+
+camera_module_t *Camera2Test::sCameraModule = NULL;
+int Camera2Test::sNumCameras = 0;
+bool *Camera2Test::sCameraSupportsHal2 = NULL;
+
+
+TEST_F(Camera2Test, Basic) {
+ ASSERT_TRUE(NULL != getCameraModule());
+}
diff --git a/tests/keymaster/Android.mk b/tests/keymaster/Android.mk
new file mode 100644
index 0000000..2661211
--- /dev/null
+++ b/tests/keymaster/Android.mk
@@ -0,0 +1,29 @@
+# Build the keymaster unit tests
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ keymaster_test.cpp
+
+# Note that "bionic" is needed because of stlport
+LOCAL_C_INCLUDES := \
+ bionic \
+ external/gtest/include \
+ external/stlport/stlport
+
+LOCAL_SHARED_LIBRARIES := \
+ liblog \
+ libutils \
+ libstlport \
+ libhardware
+
+LOCAL_STATIC_LIBRARIES := \
+ libgtest \
+ libgtest_main
+
+LOCAL_MODULE := keymaster_test
+
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_EXECUTABLE)
diff --git a/tests/keymaster/keymaster_test.cpp b/tests/keymaster/keymaster_test.cpp
new file mode 100644
index 0000000..f4cfcd2
--- /dev/null
+++ b/tests/keymaster/keymaster_test.cpp
@@ -0,0 +1,793 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "keymaster_test"
+#include <utils/Log.h>
+#include <utils/UniquePtr.h>
+
+#include <hardware/keymaster.h>
+
+#include <gtest/gtest.h>
+
+#include <fstream>
+#include <iostream>
+
+namespace android {
+
+class UniqueBlob : public UniquePtr<uint8_t[]> {
+public:
+ UniqueBlob(uint8_t* bytes, size_t length) :
+ UniquePtr<uint8_t[]>(bytes), mLength(length) {
+ }
+
+ bool operator==(const UniqueBlob &other) const {
+ if (other.length() != mLength) {
+ return false;
+ }
+
+ const uint8_t* mine = get();
+ const uint8_t* theirs = other.get();
+
+ for (size_t i = 0; i < mLength; i++) {
+ if (mine[i] != theirs[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ size_t length() const {
+ return mLength;
+ }
+
+ friend std::ostream &operator<<(std::ostream &stream, const UniqueBlob& blob);
+
+private:
+ size_t mLength;
+};
+
+std::ostream &operator<<(std::ostream &stream, const UniqueBlob& blob) {
+ const size_t length = blob.mLength;
+ stream << "Blob length=" << length << " < ";
+
+ const uint8_t* data = blob.get();
+ for (size_t i = 0; i < length; i++) {
+ stream << std::hex << std::setw(2) << std::setfill('0')
+ << static_cast<unsigned int>(data[i]) << ' ';
+ }
+ stream << '>' << std::endl;
+
+ return stream;
+}
+
+class UniqueKey : public UniqueBlob {
+public:
+ UniqueKey(keymaster_device_t** dev, uint8_t* bytes, size_t length) :
+ UniqueBlob(bytes, length), mDevice(dev) {
+ }
+
+ ~UniqueKey() {
+ if (mDevice != NULL && *mDevice != NULL) {
+ keymaster_device_t* dev = *mDevice;
+ if (dev->delete_keypair != NULL) {
+ dev->delete_keypair(dev, get(), length());
+ }
+ }
+ }
+
+private:
+ keymaster_device_t** mDevice;
+};
+
+/*
+ * DER-encoded PKCS#8 format RSA key. Generated using:
+ *
+ * openssl genrsa 2048 | openssl pkcs8 -topk8 -nocrypt -outform der | recode ../x1
+ */
+static uint8_t TEST_KEY_1[] = {
+ 0x30, 0x82, 0x04, 0xBE, 0x02, 0x01, 0x00, 0x30, 0x0D, 0x06, 0x09, 0x2A,
+ 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
+ 0x04, 0xA8, 0x30, 0x82, 0x04, 0xA4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01,
+ 0x01, 0x00, 0xD8, 0x58, 0xD4, 0x9F, 0xC0, 0xE8, 0xF0, 0xFF, 0x87, 0x27,
+ 0x43, 0xE6, 0x2E, 0xE6, 0x9A, 0x42, 0x3B, 0x39, 0x94, 0x84, 0x43, 0x55,
+ 0x8D, 0x20, 0x5B, 0x71, 0x88, 0xE6, 0xD1, 0x62, 0xC8, 0xF2, 0x20, 0xD0,
+ 0x75, 0x13, 0x83, 0xA3, 0x5D, 0x19, 0xA8, 0x62, 0xD0, 0x5F, 0x3E, 0x8A,
+ 0x7C, 0x0E, 0x26, 0xA9, 0xFF, 0xB2, 0x5E, 0x63, 0xAA, 0x3C, 0x8D, 0x13,
+ 0x41, 0xAA, 0xD5, 0x03, 0x01, 0x01, 0x53, 0xC9, 0x02, 0x1C, 0xEC, 0xE8,
+ 0xC4, 0x70, 0x3F, 0x43, 0xE5, 0x51, 0xD0, 0x6E, 0x52, 0x0B, 0xC4, 0x0A,
+ 0xA3, 0x61, 0xDE, 0xE3, 0x72, 0x0C, 0x94, 0xF1, 0x1C, 0x2D, 0x36, 0x77,
+ 0xBB, 0x16, 0xA8, 0x63, 0x4B, 0xD1, 0x07, 0x00, 0x42, 0x2D, 0x2B, 0x10,
+ 0x80, 0x45, 0xF3, 0x0C, 0xF9, 0xC5, 0xAC, 0xCC, 0x64, 0x87, 0xFD, 0x5D,
+ 0xC8, 0x51, 0xD4, 0x1C, 0x9E, 0x6E, 0x9B, 0xC4, 0x27, 0x5E, 0x73, 0xA7,
+ 0x2A, 0xF6, 0x90, 0x42, 0x0C, 0x34, 0x93, 0xB7, 0x02, 0x19, 0xA9, 0x64,
+ 0x6C, 0x46, 0x3B, 0x40, 0x02, 0x2F, 0x54, 0x69, 0x79, 0x26, 0x7D, 0xF6,
+ 0x85, 0x90, 0x01, 0xD0, 0x21, 0x07, 0xD0, 0x14, 0x00, 0x65, 0x9C, 0xAC,
+ 0x24, 0xE8, 0x78, 0x42, 0x3B, 0x90, 0x75, 0x19, 0x55, 0x11, 0x4E, 0xD9,
+ 0xE6, 0x97, 0x87, 0xBC, 0x8D, 0x2C, 0x9B, 0xF0, 0x1F, 0x14, 0xEB, 0x6A,
+ 0x57, 0xCE, 0x78, 0xAD, 0xCE, 0xD9, 0xFB, 0xB9, 0xA1, 0xEF, 0x0C, 0x1F,
+ 0xDD, 0xE3, 0x5B, 0x73, 0xA0, 0xEC, 0x37, 0x9C, 0xE1, 0xFD, 0x86, 0x28,
+ 0xC3, 0x4A, 0x42, 0xD0, 0xA3, 0xFE, 0x57, 0x09, 0x29, 0xD8, 0xF6, 0xEC,
+ 0xE3, 0xC0, 0x71, 0x7C, 0x29, 0x27, 0xC2, 0xD1, 0x3E, 0x22, 0xBC, 0xBD,
+ 0x5A, 0x85, 0x41, 0xF6, 0x15, 0xDA, 0x0C, 0x58, 0x5A, 0x61, 0x5B, 0x78,
+ 0xB8, 0xAA, 0xEC, 0x5C, 0x1C, 0x79, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02,
+ 0x82, 0x01, 0x00, 0x1D, 0x10, 0x31, 0xE0, 0x14, 0x26, 0x36, 0xD9, 0xDC,
+ 0xEA, 0x25, 0x70, 0xF2, 0xB3, 0xFF, 0xDD, 0x0D, 0xDF, 0xBA, 0x57, 0xDA,
+ 0x43, 0xCF, 0xE5, 0x9C, 0xE3, 0x2F, 0xA4, 0xF2, 0x53, 0xF6, 0xF2, 0xAF,
+ 0xFD, 0xD0, 0xFC, 0x82, 0x1E, 0x9C, 0x0F, 0x2A, 0x53, 0xBB, 0xF2, 0x4F,
+ 0x90, 0x83, 0x01, 0xD3, 0xA7, 0xDA, 0xB5, 0xB7, 0x80, 0x64, 0x0A, 0x26,
+ 0x59, 0x83, 0xE4, 0xD3, 0x20, 0xC8, 0x2D, 0xC9, 0x77, 0xA3, 0x55, 0x07,
+ 0x6E, 0x6D, 0x95, 0x36, 0xAA, 0x84, 0x4F, 0xED, 0x54, 0x24, 0xA9, 0x77,
+ 0xF8, 0x85, 0xE2, 0x4B, 0xF2, 0xFA, 0x0B, 0x3E, 0xA6, 0xF5, 0x46, 0x0D,
+ 0x9F, 0x1F, 0xFE, 0xF7, 0x37, 0xFF, 0xA3, 0x60, 0xF1, 0x63, 0xF2, 0x75,
+ 0x6A, 0x8E, 0x10, 0xD7, 0x89, 0xD2, 0xB3, 0xFF, 0x76, 0xA5, 0xBA, 0xAF,
+ 0x0A, 0xBE, 0x32, 0x5F, 0xF0, 0x48, 0x48, 0x4B, 0x9C, 0x9A, 0x3D, 0x12,
+ 0xA7, 0xD2, 0x07, 0xC7, 0x59, 0x32, 0x94, 0x95, 0x65, 0x2F, 0x87, 0x34,
+ 0x76, 0xBA, 0x7C, 0x08, 0x4B, 0xAB, 0xA6, 0x24, 0xDF, 0x64, 0xDB, 0x48,
+ 0x63, 0x42, 0x06, 0xE2, 0x2C, 0x3D, 0xFB, 0xE5, 0x47, 0x81, 0x94, 0x98,
+ 0xF7, 0x32, 0x4B, 0x28, 0xEB, 0x42, 0xB8, 0xE9, 0x8E, 0xFC, 0xC9, 0x43,
+ 0xC9, 0x47, 0xE6, 0xE7, 0x1C, 0xDC, 0x71, 0xEF, 0x4D, 0x8A, 0xB1, 0xFC,
+ 0x45, 0x37, 0xEC, 0xB3, 0x16, 0x88, 0x5B, 0xE2, 0xEC, 0x8B, 0x6B, 0x75,
+ 0x16, 0xBE, 0x6B, 0xF8, 0x2C, 0xF8, 0xC9, 0xD1, 0xF7, 0x55, 0x87, 0x57,
+ 0x5F, 0xDE, 0xF4, 0x7E, 0x72, 0x13, 0x06, 0x2A, 0x21, 0xB7, 0x78, 0x21,
+ 0x05, 0xFD, 0xE2, 0x5F, 0x7B, 0x7C, 0xF0, 0x26, 0x2B, 0x75, 0x7F, 0x68,
+ 0xF9, 0xA6, 0x98, 0xFD, 0x54, 0x0E, 0xCC, 0x22, 0x41, 0x7F, 0x29, 0x81,
+ 0x2F, 0xA3, 0x3C, 0x3D, 0x64, 0xC8, 0x41, 0x02, 0x81, 0x81, 0x00, 0xFA,
+ 0xFA, 0xE4, 0x2E, 0x30, 0xF0, 0x7A, 0x8D, 0x95, 0xB8, 0x39, 0x58, 0x27,
+ 0x0F, 0x89, 0x0C, 0xDF, 0xFE, 0x2F, 0x55, 0x3B, 0x6F, 0xDD, 0x5F, 0x12,
+ 0xB3, 0xD1, 0xCF, 0x5B, 0x8D, 0xB6, 0x10, 0x1C, 0x87, 0x0C, 0x30, 0x89,
+ 0x2D, 0xBB, 0xB8, 0xA1, 0x78, 0x0F, 0x54, 0xA6, 0x36, 0x46, 0x05, 0x8B,
+ 0x5A, 0xFF, 0x48, 0x03, 0x13, 0xAE, 0x95, 0x96, 0x5D, 0x6C, 0xDA, 0x5D,
+ 0xF7, 0xAD, 0x1D, 0x33, 0xED, 0x23, 0xF5, 0x4B, 0x03, 0x78, 0xE7, 0x50,
+ 0xD1, 0x2D, 0x95, 0x22, 0x35, 0x02, 0x5B, 0x4A, 0x4E, 0x73, 0xC9, 0xB7,
+ 0x05, 0xC4, 0x21, 0x86, 0x1F, 0x1E, 0x40, 0x83, 0xBC, 0x8A, 0x3A, 0x95,
+ 0x24, 0x62, 0xF4, 0x58, 0x38, 0x64, 0x4A, 0x89, 0x8A, 0x27, 0x59, 0x12,
+ 0x9D, 0x21, 0xC3, 0xA6, 0x42, 0x1E, 0x2A, 0x3F, 0xD8, 0x65, 0x1F, 0x6E,
+ 0x3E, 0x4D, 0x5C, 0xCC, 0xEA, 0x8E, 0x15, 0x02, 0x81, 0x81, 0x00, 0xDC,
+ 0xAC, 0x9B, 0x00, 0xDB, 0xF9, 0xB2, 0xBF, 0xC4, 0x5E, 0xB6, 0xB7, 0x63,
+ 0xEB, 0x13, 0x4B, 0xE2, 0xA6, 0xC8, 0x72, 0x90, 0xD8, 0xC2, 0x33, 0x33,
+ 0xF0, 0x66, 0x75, 0xBD, 0x50, 0x7C, 0xA4, 0x8F, 0x82, 0xFB, 0xFF, 0x44,
+ 0x3B, 0xE7, 0x15, 0x3A, 0x0C, 0x7A, 0xF8, 0x92, 0x86, 0x4A, 0x79, 0x32,
+ 0x08, 0x82, 0x1D, 0x6A, 0xBA, 0xAD, 0x8A, 0xB3, 0x3D, 0x7F, 0xA5, 0xB4,
+ 0x6F, 0x67, 0x86, 0x7E, 0xB2, 0x9C, 0x2A, 0xF6, 0x7C, 0x49, 0x21, 0xC5,
+ 0x3F, 0x00, 0x3F, 0x9B, 0xF7, 0x0F, 0x6C, 0x35, 0x80, 0x75, 0x73, 0xC0,
+ 0xF8, 0x3E, 0x30, 0x5F, 0x74, 0x2F, 0x15, 0x41, 0xEA, 0x0F, 0xCE, 0x0E,
+ 0x18, 0x17, 0x68, 0xBA, 0xC4, 0x29, 0xF2, 0xE2, 0x2C, 0x1D, 0x55, 0x83,
+ 0xB6, 0x64, 0x2E, 0x03, 0x12, 0xA4, 0x0D, 0xBF, 0x4F, 0x2E, 0xBE, 0x7C,
+ 0x41, 0xD9, 0xCD, 0xD0, 0x52, 0x91, 0xD5, 0x02, 0x81, 0x81, 0x00, 0xD4,
+ 0x55, 0xEB, 0x32, 0xC1, 0x28, 0xD3, 0x26, 0x72, 0x22, 0xB8, 0x31, 0x42,
+ 0x6A, 0xBC, 0x52, 0x6E, 0x37, 0x48, 0xA8, 0x5D, 0x6E, 0xD8, 0xE5, 0x14,
+ 0x97, 0x99, 0xCC, 0x4A, 0xF2, 0xEB, 0xB3, 0x59, 0xCF, 0x4F, 0x9A, 0xC8,
+ 0x94, 0x2E, 0x9B, 0x97, 0xD0, 0x51, 0x78, 0x16, 0x5F, 0x18, 0x82, 0x9C,
+ 0x51, 0xD2, 0x64, 0x84, 0x65, 0xE4, 0x70, 0x9E, 0x14, 0x50, 0x81, 0xB6,
+ 0xBA, 0x52, 0x75, 0xC0, 0x76, 0xC2, 0xD3, 0x46, 0x31, 0x9B, 0xDA, 0x67,
+ 0xDF, 0x71, 0x27, 0x19, 0x17, 0xAB, 0xF4, 0xBC, 0x3A, 0xFF, 0x6F, 0x0B,
+ 0x2F, 0x0F, 0xAE, 0x25, 0x20, 0xB2, 0xA1, 0x76, 0x52, 0xCE, 0xC7, 0x9D,
+ 0x62, 0x79, 0x6D, 0xAC, 0x2D, 0x99, 0x7C, 0x0E, 0x3D, 0x19, 0xE9, 0x1B,
+ 0xFC, 0x60, 0x92, 0x7C, 0x58, 0xB7, 0xD8, 0x9A, 0xC7, 0x63, 0x56, 0x62,
+ 0x18, 0xC7, 0xAE, 0xD9, 0x97, 0x1F, 0xB9, 0x02, 0x81, 0x81, 0x00, 0x91,
+ 0x40, 0xC4, 0x1E, 0x82, 0xAD, 0x0F, 0x6D, 0x8E, 0xD2, 0x51, 0x2E, 0xD1,
+ 0x84, 0x30, 0x85, 0x68, 0xC1, 0x23, 0x7B, 0xD5, 0xBF, 0xF7, 0xC4, 0x40,
+ 0x51, 0xE2, 0xFF, 0x69, 0x07, 0x8B, 0xA3, 0xBE, 0x1B, 0x17, 0xC8, 0x64,
+ 0x9F, 0x91, 0x71, 0xB5, 0x6D, 0xF5, 0x9B, 0x9C, 0xC6, 0xEC, 0x4A, 0x6E,
+ 0x16, 0x8F, 0x9E, 0xD1, 0x5B, 0xE3, 0x53, 0x42, 0xBC, 0x1E, 0x43, 0x72,
+ 0x4B, 0x4A, 0x37, 0x8B, 0x3A, 0x01, 0xF5, 0x7D, 0x9D, 0x3D, 0x7E, 0x0F,
+ 0x19, 0x73, 0x0E, 0x6B, 0x98, 0xE9, 0xFB, 0xEE, 0x13, 0x8A, 0x3C, 0x11,
+ 0x2E, 0xD5, 0xB0, 0x7D, 0x84, 0x3A, 0x61, 0xA1, 0xAB, 0x71, 0x8F, 0xCE,
+ 0x53, 0x29, 0x45, 0x74, 0x7A, 0x1E, 0xAA, 0x93, 0x19, 0x3A, 0x8D, 0xC9,
+ 0x4E, 0xCB, 0x0E, 0x46, 0x53, 0x84, 0xCC, 0xCF, 0xBA, 0x4D, 0x28, 0x71,
+ 0x1D, 0xDF, 0x41, 0xCB, 0xF8, 0x2D, 0xA9, 0x02, 0x81, 0x80, 0x04, 0x8B,
+ 0x4A, 0xEA, 0xBD, 0x39, 0x0B, 0x96, 0xC5, 0x1D, 0xA4, 0x47, 0xFD, 0x46,
+ 0xD2, 0x8A, 0xEA, 0x2A, 0xF3, 0x9D, 0x3A, 0x7E, 0x16, 0x74, 0xFC, 0x13,
+ 0xDE, 0x4D, 0xA9, 0x85, 0x42, 0x33, 0x02, 0x92, 0x0B, 0xB6, 0xDB, 0x7E,
+ 0xEA, 0x85, 0xC2, 0x94, 0x43, 0x52, 0x37, 0x5A, 0x77, 0xAB, 0xCB, 0x61,
+ 0x88, 0xDE, 0xF8, 0xFA, 0xDB, 0xE8, 0x0B, 0x95, 0x7D, 0x39, 0x19, 0xA2,
+ 0x89, 0xB9, 0x32, 0xB2, 0x50, 0x38, 0xF7, 0x88, 0x69, 0xFD, 0xA4, 0x63,
+ 0x1F, 0x9B, 0x03, 0xD8, 0xA6, 0x7A, 0x05, 0x76, 0x02, 0x28, 0x93, 0x82,
+ 0x73, 0x7F, 0x14, 0xCC, 0xBE, 0x29, 0x10, 0xAD, 0x8A, 0x2E, 0xAC, 0xED,
+ 0x11, 0xA7, 0x72, 0x7C, 0x60, 0x78, 0x72, 0xFB, 0x78, 0x20, 0x18, 0xC9,
+ 0x7E, 0x63, 0xAD, 0x55, 0x54, 0x51, 0xDB, 0x9F, 0x7B, 0xD4, 0x8F, 0xB2,
+ 0xDE, 0x3B, 0xF1, 0x70, 0x23, 0xE5,
+};
+
+/*
+ * Generated using keys on the keyboard and lack of imagination.
+ */
+static unsigned char BOGUS_KEY_1[] = { 0xFF, 0xFF, 0xFF, 0xFF };
+
+
+class KeymasterTest : public testing::Test {
+protected:
+ static void SetUpTestCase() {
+ const hw_module_t* mod;
+ ASSERT_EQ(0, hw_get_module_by_class(KEYSTORE_HARDWARE_MODULE_ID, NULL, &mod))
+ << "Should be able to find a keymaster hardware module";
+
+ std::cout << "Using keymaster module: " << mod->name << std::endl;
+
+ ASSERT_EQ(0, keymaster_open(mod, &sDevice))
+ << "Should be able to open the keymaster device";
+
+ ASSERT_TRUE(sDevice->generate_keypair != NULL)
+ << "Should implement generate_keypair";
+
+ ASSERT_TRUE(sDevice->import_keypair != NULL)
+ << "Should implement import_keypair";
+
+ ASSERT_TRUE(sDevice->get_keypair_public != NULL)
+ << "Should implement get_keypair_public";
+
+ ASSERT_TRUE(sDevice->sign_data != NULL)
+ << "Should implement sign_data";
+
+ ASSERT_TRUE(sDevice->verify_data != NULL)
+ << "Should implement verify_data";
+ }
+
+ static void TearDownTestCase() {
+ ASSERT_EQ(0, keymaster_close(sDevice));
+ }
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+
+ static keymaster_device_t* sDevice;
+};
+
+keymaster_device_t* KeymasterTest::sDevice = NULL;
+
+TEST_F(KeymasterTest, GenerateKeyPair_RSA_512_Success) {
+ keymaster_keypair_t key_type = TYPE_RSA;
+ keymaster_rsa_keygen_params_t params = {
+ modulus_size: 512,
+ public_exponent: 0x10001L,
+ };
+
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ EXPECT_EQ(0,
+ sDevice->generate_keypair(sDevice, key_type, ¶ms, &key_blob, &key_blob_length))
+ << "Should generate an RSA key with 512 bit modulus size";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+}
+
+TEST_F(KeymasterTest, GenerateKeyPair_RSA_1024_Success) {
+ keymaster_keypair_t key_type = TYPE_RSA;
+ keymaster_rsa_keygen_params_t params = {
+ modulus_size: 1024,
+ public_exponent: 0x3L,
+ };
+
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ EXPECT_EQ(0,
+ sDevice->generate_keypair(sDevice, key_type, ¶ms, &key_blob, &key_blob_length))
+ << "Should generate an RSA key with 2048 bit modulus size";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+}
+
+TEST_F(KeymasterTest, GenerateKeyPair_RSA_2048_Success) {
+ keymaster_keypair_t key_type = TYPE_RSA;
+ keymaster_rsa_keygen_params_t params = {
+ modulus_size: 2048,
+ public_exponent: 0x3L,
+ };
+
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ EXPECT_EQ(0,
+ sDevice->generate_keypair(sDevice, key_type, ¶ms, &key_blob, &key_blob_length))
+ << "Should generate an RSA key with 2048 bit modulus size";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+}
+
+TEST_F(KeymasterTest, GenerateKeyPair_RSA_NullParams_Failure) {
+ keymaster_keypair_t key_type = TYPE_RSA;
+
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ EXPECT_EQ(-1,
+ sDevice->generate_keypair(sDevice, key_type, NULL, &key_blob, &key_blob_length))
+ << "Should not be able to generate an RSA key with null params";
+}
+
+TEST_F(KeymasterTest, GenerateKeyPair_UnknownType_Failure) {
+ keymaster_keypair_t key_type = static_cast<keymaster_keypair_t>(0xFFFF);
+
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ EXPECT_EQ(-1,
+ sDevice->generate_keypair(sDevice, key_type, NULL, &key_blob, &key_blob_length))
+ << "Should not generate an unknown key type";
+}
+
+TEST_F(KeymasterTest, ImportKeyPair_RSA_Success) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ EXPECT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_KEY_1, sizeof(TEST_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+}
+
+TEST_F(KeymasterTest, ImportKeyPair_BogusKey_Failure) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ EXPECT_EQ(-1,
+ sDevice->import_keypair(sDevice, BOGUS_KEY_1, sizeof(BOGUS_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should not import an unknown key type";
+}
+
+TEST_F(KeymasterTest, ImportKeyPair_NullKey_Failure) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ EXPECT_EQ(-1,
+ sDevice->import_keypair(sDevice, NULL, 0,
+ &key_blob, &key_blob_length))
+ << "Should not import a null key";
+}
+
+TEST_F(KeymasterTest, GetKeypairPublic_RSA_Success) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_KEY_1, sizeof(TEST_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+
+ uint8_t* x509_data;
+ size_t x509_data_length;
+ EXPECT_EQ(0,
+ sDevice->get_keypair_public(sDevice, key_blob, key_blob_length,
+ &x509_data, &x509_data_length))
+ << "Should be able to retrieve RSA public key successfully";
+ UniqueBlob x509_blob(x509_data, x509_data_length);
+}
+
+TEST_F(KeymasterTest, GetKeypairPublic_RSA_NullKey_Failure) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ uint8_t* x509_data = NULL;
+ size_t x509_data_length;
+ EXPECT_EQ(-1,
+ sDevice->get_keypair_public(sDevice, NULL, 0,
+ &x509_data, &x509_data_length))
+ << "Should not be able to retrieve RSA public key from null key";
+ UniqueBlob x509_blob(x509_data, x509_data_length);
+}
+
+TEST_F(KeymasterTest, GetKeypairPublic_RSA_NullDestination_Failure) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_KEY_1, sizeof(TEST_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+
+ EXPECT_EQ(-1,
+ sDevice->get_keypair_public(sDevice, key.get(), key.length(),
+ NULL, NULL))
+ << "Should not be able to succeed with NULL destination blob";
+}
+
+TEST_F(KeymasterTest, DeleteKeyPair_RSA_Success) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ EXPECT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_KEY_1, sizeof(TEST_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+}
+
+TEST_F(KeymasterTest, DeleteKeyPair_RSA_DoubleDelete_Failure) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ /*
+ * This is only run if the module indicates it implements key deletion
+ * by implementing delete_keypair.
+ */
+ if (sDevice->delete_keypair != NULL) {
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_KEY_1, sizeof(TEST_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueBlob blob(key_blob, key_blob_length);
+
+ EXPECT_EQ(0, sDevice->delete_keypair(sDevice, key_blob, key_blob_length))
+ << "Should delete key after import";
+
+ EXPECT_EQ(-1, sDevice->delete_keypair(sDevice, key_blob, key_blob_length))
+ << "Should not be able to delete key twice";
+ }
+}
+
+TEST_F(KeymasterTest, DeleteKeyPair_RSA_NullKey_Failure) {
+ /*
+ * This is only run if the module indicates it implements key deletion
+ * by implementing delete_keypair.
+ */
+ if (sDevice->delete_keypair != NULL) {
+ EXPECT_EQ(-1, sDevice->delete_keypair(sDevice, NULL, 0))
+ << "Should not be able to delete null key";
+ }
+}
+
+/*
+ * DER-encoded PKCS#8 format RSA key. Generated using:
+ *
+ * openssl genrsa 512 | openssl pkcs8 -topk8 -nocrypt -outform der | recode ../x1
+ */
+static uint8_t TEST_SIGN_KEY_1[] = {
+ 0x30, 0x82, 0x01, 0x56, 0x02, 0x01, 0x00, 0x30, 0x0D, 0x06, 0x09, 0x2A,
+ 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
+ 0x01, 0x40, 0x30, 0x82, 0x01, 0x3C, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00,
+ 0xBD, 0xC0, 0x7F, 0xEF, 0x75, 0x1D, 0x63, 0x2A, 0xD0, 0x9A, 0x26, 0xE5,
+ 0x5B, 0xB9, 0x84, 0x7C, 0xE5, 0xC7, 0xE7, 0xDE, 0xFE, 0xB6, 0x54, 0xD9,
+ 0xF0, 0x9B, 0xC2, 0xCF, 0x36, 0xDA, 0xE5, 0x4D, 0xC5, 0xD9, 0x25, 0x78,
+ 0xBD, 0x55, 0x05, 0xBD, 0x86, 0xFB, 0x37, 0x15, 0x33, 0x42, 0x52, 0xED,
+ 0xE5, 0xCD, 0xCB, 0xB7, 0xA2, 0x51, 0xFA, 0x36, 0xE9, 0x9C, 0x2E, 0x5D,
+ 0xE3, 0xA5, 0x1F, 0x01, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x41, 0x00,
+ 0x96, 0x71, 0xDE, 0xBD, 0x83, 0x94, 0x96, 0x40, 0xA6, 0xFD, 0xE1, 0xA2,
+ 0xED, 0xD3, 0xAC, 0x28, 0xBE, 0xA2, 0x7D, 0xC3, 0xFF, 0x1D, 0x9F, 0x2E,
+ 0xE0, 0xA7, 0x0E, 0x90, 0xEE, 0x44, 0x25, 0x92, 0xE3, 0x54, 0xDD, 0x55,
+ 0xA3, 0xEF, 0x42, 0xF5, 0x52, 0x55, 0x41, 0x47, 0x5E, 0x00, 0xFB, 0x8B,
+ 0x47, 0x5E, 0x45, 0x49, 0xEA, 0x3D, 0x2C, 0xFD, 0x9F, 0xEC, 0xC8, 0x4E,
+ 0x4E, 0x86, 0x90, 0x31, 0x02, 0x21, 0x00, 0xE6, 0xA5, 0x55, 0xB3, 0x64,
+ 0xAB, 0x90, 0x5E, 0xA2, 0xF5, 0x6B, 0x21, 0x4B, 0x15, 0xD6, 0x4A, 0xB6,
+ 0x60, 0x24, 0x95, 0x65, 0xA2, 0xBE, 0xBA, 0x2A, 0x73, 0xFB, 0xFF, 0x2C,
+ 0x61, 0x88, 0x9D, 0x02, 0x21, 0x00, 0xD2, 0x9C, 0x5B, 0xFE, 0x82, 0xA5,
+ 0xFC, 0x52, 0x6A, 0x29, 0x38, 0xDB, 0x22, 0x3B, 0xEB, 0x74, 0x3B, 0xCA,
+ 0xB4, 0xDD, 0x1D, 0xE4, 0x48, 0x60, 0x70, 0x19, 0x9B, 0x81, 0xC1, 0x83,
+ 0x28, 0xB5, 0x02, 0x21, 0x00, 0x89, 0x2D, 0xFE, 0xF9, 0xF2, 0xBF, 0x43,
+ 0xDF, 0xB5, 0xA6, 0xA8, 0x30, 0x26, 0x1B, 0x77, 0xD7, 0xF9, 0xFE, 0xD6,
+ 0xE3, 0x70, 0x8E, 0xCA, 0x47, 0xA9, 0xA6, 0x50, 0x54, 0x25, 0xCE, 0x60,
+ 0xD5, 0x02, 0x21, 0x00, 0xBE, 0x5A, 0xF8, 0x82, 0xE6, 0xCE, 0xE3, 0x6A,
+ 0x11, 0xED, 0xC4, 0x27, 0xBB, 0x9F, 0x70, 0xC6, 0x93, 0xAC, 0x39, 0x20,
+ 0x89, 0x7D, 0xE5, 0x34, 0xD4, 0xDD, 0x30, 0x42, 0x6D, 0x07, 0x00, 0xE9,
+ 0x02, 0x20, 0x05, 0x91, 0xEF, 0x12, 0xD2, 0xD3, 0x6A, 0xD2, 0x96, 0x6B,
+ 0x10, 0x62, 0xF9, 0xBA, 0xA4, 0x91, 0x48, 0x84, 0x40, 0x61, 0x67, 0x80,
+ 0x68, 0x68, 0xC8, 0x60, 0xB3, 0x66, 0xC8, 0xF9, 0x08, 0x9A,
+};
+
+/*
+ * PKCS#1 v1.5 padded raw "Hello, world" Can be generated be generated by verifying
+ * the signature below in no padding mode:
+ *
+ * openssl rsautl -keyform der -inkey rsa.der -raw -verify -in test.sig
+ */
+static uint8_t TEST_SIGN_DATA_1[] = {
+ 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x77,
+ 0x6F, 0x72, 0x6C, 0x64,
+};
+
+/*
+ * Signature of TEST_SIGN_DATA_1 using TEST_SIGN_KEY_1. Generated using:
+ *
+ * echo 'Hello, world' | openssl rsautl -keyform der -inkey rsa.der -sign | recode ../x1
+ */
+static uint8_t TEST_SIGN_SIGNATURE_1[] = {
+ 0xA4, 0xBB, 0x76, 0x87, 0xFE, 0x61, 0x0C, 0x9D, 0xD6, 0xFF, 0x4B, 0x76,
+ 0x96, 0x08, 0x36, 0x23, 0x11, 0xC6, 0x44, 0x3F, 0x88, 0x77, 0x97, 0xB2,
+ 0xA8, 0x3B, 0xFB, 0x9C, 0x3C, 0xD3, 0x20, 0x65, 0xFD, 0x26, 0x3B, 0x2A,
+ 0xB8, 0xB6, 0xD4, 0xDC, 0x91, 0xF7, 0xE2, 0xDE, 0x4D, 0xF7, 0x0E, 0xB9,
+ 0x72, 0xA7, 0x29, 0x72, 0x82, 0x12, 0x7C, 0x53, 0x23, 0x21, 0xC4, 0xFF,
+ 0x79, 0xE4, 0x91, 0x40,
+};
+
+/*
+ * Identical to TEST_SIGN_SIGNATURE_1 except the last octet is '1' instead of '0'
+ * This should fail any test.
+ */
+static uint8_t TEST_SIGN_SIGNATURE_BOGUS_1[] = {
+ 0xA4, 0xBB, 0x76, 0x87, 0xFE, 0x61, 0x0C, 0x9D, 0xD6, 0xFF, 0x4B, 0x76,
+ 0x96, 0x08, 0x36, 0x23, 0x11, 0xC6, 0x44, 0x3F, 0x88, 0x77, 0x97, 0xB2,
+ 0xA8, 0x3B, 0xFB, 0x9C, 0x3C, 0xD3, 0x20, 0x65, 0xFD, 0x26, 0x3B, 0x2A,
+ 0xB8, 0xB6, 0xD4, 0xDC, 0x91, 0xF7, 0xE2, 0xDE, 0x4D, 0xF7, 0x0E, 0xB9,
+ 0x72, 0xA7, 0x29, 0x72, 0x82, 0x12, 0x7C, 0x53, 0x23, 0x21, 0xC4, 0xFF,
+ 0x79, 0xE4, 0x91, 0x41,
+};
+
+TEST_F(KeymasterTest, SignData_RSA_Raw_Success) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_SIGN_KEY_1, sizeof(TEST_SIGN_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+
+ keymaster_rsa_sign_params_t params = {
+ digest_type: DIGEST_NONE,
+ padding_type: PADDING_NONE,
+ };
+
+ uint8_t* sig;
+ size_t sig_length;
+
+ EXPECT_EQ(0,
+ sDevice->sign_data(sDevice, ¶ms, key_blob, key_blob_length,
+ TEST_SIGN_DATA_1, sizeof(TEST_SIGN_DATA_1),
+ &sig, &sig_length))
+ << "Should sign data successfully";
+ UniqueBlob sig_blob(sig, sig_length);
+
+ UniqueBlob expected_sig(TEST_SIGN_SIGNATURE_1, sizeof(TEST_SIGN_SIGNATURE_1));
+
+ EXPECT_EQ(expected_sig, sig_blob)
+ << "Generated signature should match expected signature";
+
+ // The expected signature is actually stack data, so don't let it try to free.
+ uint8_t* unused __attribute__((unused)) = expected_sig.release();
+}
+
+TEST_F(KeymasterTest, SignData_RSA_Raw_InvalidSizeInput_Failure) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_SIGN_KEY_1, sizeof(TEST_SIGN_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+
+ keymaster_rsa_sign_params_t params = {
+ digest_type: DIGEST_NONE,
+ padding_type: PADDING_NONE,
+ };
+
+ uint8_t* sig;
+ size_t sig_length;
+
+ EXPECT_EQ(-1,
+ sDevice->sign_data(sDevice, ¶ms, key_blob, key_blob_length,
+ TEST_KEY_1, sizeof(TEST_KEY_1),
+ &sig, &sig_length))
+ << "Should not be able to do raw signature on incorrect size data";
+}
+
+TEST_F(KeymasterTest, SignData_RSA_Raw_NullKey_Failure) {
+ keymaster_rsa_sign_params_t params = {
+ digest_type: DIGEST_NONE,
+ padding_type: PADDING_NONE,
+ };
+
+ uint8_t* sig;
+ size_t sig_length;
+
+ EXPECT_EQ(-1,
+ sDevice->sign_data(sDevice, ¶ms, NULL, 0,
+ TEST_KEY_1, sizeof(TEST_KEY_1),
+ &sig, &sig_length))
+ << "Should not be able to do raw signature on incorrect size data";
+}
+
+TEST_F(KeymasterTest, SignData_RSA_Raw_NullInput_Failure) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_SIGN_KEY_1, sizeof(TEST_SIGN_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+
+ keymaster_rsa_sign_params_t params = {
+ digest_type: DIGEST_NONE,
+ padding_type: PADDING_NONE,
+ };
+
+ uint8_t* sig;
+ size_t sig_length;
+
+ EXPECT_EQ(-1,
+ sDevice->sign_data(sDevice, ¶ms, key_blob, key_blob_length,
+ NULL, 0,
+ &sig, &sig_length))
+ << "Should error when input data is null";
+}
+
+TEST_F(KeymasterTest, SignData_RSA_Raw_NullOutput_Failure) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_SIGN_KEY_1, sizeof(TEST_SIGN_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+
+ keymaster_rsa_sign_params_t params = {
+ digest_type: DIGEST_NONE,
+ padding_type: PADDING_NONE,
+ };
+
+ uint8_t* sig;
+ size_t sig_length;
+
+ EXPECT_EQ(-1,
+ sDevice->sign_data(sDevice, ¶ms, key_blob, key_blob_length,
+ TEST_KEY_1, sizeof(TEST_KEY_1),
+ NULL, NULL))
+ << "Should error when output is null";
+}
+
+TEST_F(KeymasterTest, VerifyData_RSA_Raw_Success) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_SIGN_KEY_1, sizeof(TEST_SIGN_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+
+ keymaster_rsa_sign_params_t params = {
+ digest_type: DIGEST_NONE,
+ padding_type: PADDING_NONE,
+ };
+
+ EXPECT_EQ(0,
+ sDevice->verify_data(sDevice, ¶ms, key_blob, key_blob_length,
+ TEST_SIGN_DATA_1, sizeof(TEST_SIGN_DATA_1),
+ TEST_SIGN_SIGNATURE_1, sizeof(TEST_SIGN_SIGNATURE_1)))
+ << "Should verify data successfully";
+}
+
+TEST_F(KeymasterTest, VerifyData_RSA_Raw_BadSignature_Failure) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_SIGN_KEY_1, sizeof(TEST_SIGN_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+
+ keymaster_rsa_sign_params_t params = {
+ digest_type: DIGEST_NONE,
+ padding_type: PADDING_NONE,
+ };
+
+ EXPECT_EQ(-1,
+ sDevice->verify_data(sDevice, ¶ms, key_blob, key_blob_length,
+ TEST_SIGN_DATA_1, sizeof(TEST_SIGN_DATA_1),
+ TEST_SIGN_SIGNATURE_BOGUS_1, sizeof(TEST_SIGN_SIGNATURE_BOGUS_1)))
+ << "Should sign data successfully";
+}
+
+TEST_F(KeymasterTest, VerifyData_RSA_Raw_NullKey_Failure) {
+ keymaster_rsa_sign_params_t params = {
+ digest_type: DIGEST_NONE,
+ padding_type: PADDING_NONE,
+ };
+
+ EXPECT_EQ(-1,
+ sDevice->verify_data(sDevice, ¶ms, NULL, 0,
+ TEST_SIGN_DATA_1, sizeof(TEST_SIGN_DATA_1),
+ TEST_SIGN_SIGNATURE_BOGUS_1, sizeof(TEST_SIGN_SIGNATURE_BOGUS_1)))
+ << "Should fail when key is null";
+}
+
+TEST_F(KeymasterTest, VerifyData_RSA_NullInput_Failure) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_SIGN_KEY_1, sizeof(TEST_SIGN_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+
+ keymaster_rsa_sign_params_t params = {
+ digest_type: DIGEST_NONE,
+ padding_type: PADDING_NONE,
+ };
+
+ EXPECT_EQ(-1,
+ sDevice->verify_data(sDevice, ¶ms, key_blob, key_blob_length,
+ NULL, 0,
+ TEST_SIGN_SIGNATURE_1, sizeof(TEST_SIGN_SIGNATURE_1)))
+ << "Should fail on null input";
+}
+
+TEST_F(KeymasterTest, VerifyData_RSA_NullSignature_Failure) {
+ uint8_t* key_blob;
+ size_t key_blob_length;
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_SIGN_KEY_1, sizeof(TEST_SIGN_KEY_1),
+ &key_blob, &key_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key(&sDevice, key_blob, key_blob_length);
+
+ keymaster_rsa_sign_params_t params = {
+ digest_type: DIGEST_NONE,
+ padding_type: PADDING_NONE,
+ };
+
+ EXPECT_EQ(-1,
+ sDevice->verify_data(sDevice, ¶ms, key.get(), key.length(),
+ TEST_SIGN_DATA_1, sizeof(TEST_SIGN_DATA_1),
+ NULL, 0))
+ << "Should fail on null signature";
+}
+
+TEST_F(KeymasterTest, EraseAll_Success) {
+ uint8_t *key1_blob, *key2_blob;
+ size_t key1_blob_length, key2_blob_length;
+
+ // Only test this if the device says it supports delete_all
+ if (sDevice->delete_all == NULL) {
+ return;
+ }
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_SIGN_KEY_1, sizeof(TEST_SIGN_KEY_1),
+ &key1_blob, &key1_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key1(&sDevice, key1_blob, key1_blob_length);
+
+ ASSERT_EQ(0,
+ sDevice->import_keypair(sDevice, TEST_KEY_1, sizeof(TEST_KEY_1),
+ &key2_blob, &key2_blob_length))
+ << "Should successfully import an RSA key";
+ UniqueKey key2(&sDevice, key2_blob, key2_blob_length);
+
+ EXPECT_EQ(0, sDevice->delete_all(sDevice))
+ << "Should erase all keys";
+
+ key1.reset();
+
+ uint8_t* x509_data;
+ size_t x509_data_length;
+ ASSERT_EQ(-1,
+ sDevice->get_keypair_public(sDevice, key1_blob, key1_blob_length,
+ &x509_data, &x509_data_length))
+ << "Should be able to retrieve RSA public key 1 successfully";
+
+ ASSERT_EQ(-1,
+ sDevice->get_keypair_public(sDevice, key2_blob, key2_blob_length,
+ &x509_data, &x509_data_length))
+ << "Should be able to retrieve RSA public key 2 successfully";
+}
+
+}