Merge "Camera: update test per interface change"
diff --git a/include/hardware/keyguard.h b/include/hardware/gatekeeper.h
similarity index 71%
rename from include/hardware/keyguard.h
rename to include/hardware/gatekeeper.h
index a0600cd..9150e70 100644
--- a/include/hardware/keyguard.h
+++ b/include/hardware/gatekeeper.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_HARDWARE_KEYGUARD_H
-#define ANDROID_HARDWARE_KEYGUARD_H
+#ifndef ANDROID_HARDWARE_GATEKEEPER_H
+#define ANDROID_HARDWARE_GATEKEEPER_H
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
@@ -23,24 +23,24 @@
 
 __BEGIN_DECLS
 
-#define KEYGUARD_HARDWARE_MODULE_ID "keyguard"
+#define GATEKEEPER_HARDWARE_MODULE_ID "gatekeeper"
 
-#define KEYGUARD_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
+#define GATEKEEPER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
 
-#define HARDWARE_KEYGUARD "keyguard"
+#define HARDWARE_GATEKEEPER "gatekeeper"
 
-struct keyguard_module {
+struct gatekeeper_module {
     /**
-     * Comon methods of the keyguard module. This *must* be the first member of
-     * keyguard_module as users of this structure will cast a hw_module_t to
-     * a keyguard_module pointer in the appropriate context.
+     * Comon methods of the gatekeeper module. This *must* be the first member of
+     * gatekeeper_module as users of this structure will cast a hw_module_t to
+     * a gatekeeper_module pointer in the appropriate context.
      */
     hw_module_t common;
 };
 
-struct keyguard_device {
+struct gatekeeper_device {
     /**
-     * Common methods of the keyguard device. As above, this must be the first
+     * Common methods of the gatekeeper device. As above, this must be the first
      * member of keymaster_device.
      */
     hw_device_t common;
@@ -57,7 +57,7 @@
      * Returns: 0 on success or an error code less than 0 on error.
      * On error, enrolled_password_handle will not be allocated.
      */
-    int (*enroll)(const struct keyguard_device *dev, uint32_t uid,
+    int (*enroll)(const struct gatekeeper_device *dev, uint32_t uid,
             const uint8_t *current_password_handle, size_t current_password_handle_length,
             const uint8_t *current_password, size_t current_password_length,
             const uint8_t *desired_password, size_t desired_password_length,
@@ -76,24 +76,24 @@
      * Returns: 0 on success or an error code less than 0 on error
      * On error, verification token will not be allocated
      */
-    int (*verify)(const struct keyguard_device *dev, uint32_t uid,
+    int (*verify)(const struct gatekeeper_device *dev, uint32_t uid,
             const uint8_t *enrolled_password_handle, size_t enrolled_password_handle_length,
             const uint8_t *provided_password, size_t provided_password_length,
             uint8_t **auth_token, size_t *auth_token_length);
 
 };
-typedef struct keyguard_device keyguard_device_t;
+typedef struct gatekeeper_device gatekeeper_device_t;
 
-static inline int keyguard_open(const struct hw_module_t *module,
-        keyguard_device_t **device) {
-    return module->methods->open(module, HARDWARE_KEYGUARD,
+static inline int gatekeeper_open(const struct hw_module_t *module,
+        gatekeeper_device_t **device) {
+    return module->methods->open(module, HARDWARE_GATEKEEPER,
             (struct hw_device_t **) device);
 }
 
-static inline int keyguard_close(keyguard_device_t *device) {
+static inline int gatekeeper_close(gatekeeper_device_t *device) {
     return device->common.close(&device->common);
 }
 
 __END_DECLS
 
-#endif // ANDROID_HARDWARE_KEYGUARD_H
+#endif // ANDROID_HARDWARE_GATEKEEPER_H
diff --git a/include/hardware/keymaster_defs.h b/include/hardware/keymaster_defs.h
index 664d3a7..dd2c764 100644
--- a/include/hardware/keymaster_defs.h
+++ b/include/hardware/keymaster_defs.h
@@ -41,6 +41,7 @@
     KM_BOOL = 7 << 28,
     KM_BIGNUM = 8 << 28,
     KM_BYTES = 9 << 28,
+    KM_LONG_REP = 10 << 28, /* Repeatable long value */
 } keymaster_tag_type_t;
 
 typedef enum {
@@ -92,20 +93,23 @@
                                                            boot. */
 
     /* User authentication */
-    KM_TAG_ALL_USERS = KM_BOOL | 500,        /* If key is usable by all users. */
-    KM_TAG_USER_ID = KM_INT | 501,           /* ID of authorized user.  Disallowed if
-                                                KM_TAG_ALL_USERS is present. */
-    KM_TAG_NO_AUTH_REQUIRED = KM_BOOL | 502, /* If key is usable without authentication. */
-    KM_TAG_USER_AUTH_ID = KM_INT_REP | 503,  /* ID of the authenticator to use (e.g. password,
-                                                fingerprint, etc.).  Repeatable to support
-                                                multi-factor auth.  Disallowed if
-                                                KM_TAG_NO_AUTH_REQUIRED is present. */
-    KM_TAG_AUTH_TIMEOUT = KM_INT | 504,      /* Required freshness of user authentication for
-                                                private/secret key operations, in seconds.
-                                                Public key operations require no authentication.
-                                                If absent, authentication is required for every
-                                                use.  Authentication state is lost when the
-                                                device is powered off. */
+    KM_TAG_ALL_USERS = KM_BOOL | 500,          /* If key is usable by all users. */
+    KM_TAG_USER_ID = KM_INT | 501,             /* ID of authorized user.  Disallowed if
+                                                  KM_TAG_ALL_USERS is present. */
+    KM_TAG_USER_SECURE_ID = KM_LONG_REP | 502, /* Secure ID of authorized user or authenticator(s).
+                                                  Disallowed if KM_TAG_ALL_USERS or
+                                                  KM_TAG_NO_AUTH_REQUIRED is present. */
+    KM_TAG_NO_AUTH_REQUIRED = KM_BOOL | 503,   /* If key is usable without authentication. */
+    KM_TAG_USER_AUTH_TYPE = KM_ENUM | 504,     /* Bitmask of authenticator types allowed when
+                                                * KM_TAG_USER_SECURE_ID contains a secure user ID,
+                                                * rather than a secure authenticator ID.  Defined in
+                                                * hw_authenticator_type_t in hw_auth_token.h. */
+    KM_TAG_AUTH_TIMEOUT = KM_INT | 505,        /* Required freshness of user authentication for
+                                                  private/secret key operations, in seconds.
+                                                  Public key operations require no authentication.
+                                                  If absent, authentication is required for every
+                                                  use.  Authentication state is lost when the
+                                                  device is powered off. */
 
     /* Application access control */
     KM_TAG_ALL_APPLICATIONS = KM_BOOL | 600, /* If key is usable by all applications. */
@@ -486,6 +490,7 @@
     case KM_INT_REP:
         return KEYMASTER_SIMPLE_COMPARE(a->integer, b->integer);
     case KM_LONG:
+    case KM_LONG_REP:
         return KEYMASTER_SIMPLE_COMPARE(a->long_integer, b->long_integer);
     case KM_DATE:
         return KEYMASTER_SIMPLE_COMPARE(a->date_time, b->date_time);
diff --git a/modules/audio/Android.mk b/modules/audio/Android.mk
index a31c85f..ef4b8f5 100644
--- a/modules/audio/Android.mk
+++ b/modules/audio/Android.mk
@@ -31,6 +31,23 @@
 
 include $(BUILD_SHARED_LIBRARY)
 
+# The stub audio HAL module, identical to the default audio hal, but with
+# different name to be loaded concurrently with other audio HALs if necessary.
+# This can also be used as skeleton for new implementations
+#
+# The format of the name is audio.<type>.<hardware/etc>.so where the only
+# required type is 'primary'. Other possibilites are 'a2dp', 'usb', etc.
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := audio.stub.default
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := audio_hw.c
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS := -Wno-unused-parameter
+
+include $(BUILD_SHARED_LIBRARY)
+
 # The stub audio policy HAL module that can be used as a skeleton for
 # new implementations.
 include $(CLEAR_VARS)
diff --git a/modules/audio/audio_hw.c b/modules/audio/audio_hw.c
index 637e3f4..a1a322f 100644
--- a/modules/audio/audio_hw.c
+++ b/modules/audio/audio_hw.c
@@ -48,65 +48,78 @@
 
 static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
 {
-    return 0;
+    ALOGV("out_set_sample_rate: %d", 0);
+    return -ENOSYS;
 }
 
 static size_t out_get_buffer_size(const struct audio_stream *stream)
 {
+    ALOGV("out_get_buffer_size: %d", 4096);
     return 4096;
 }
 
 static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
 {
+    ALOGV("out_get_channels");
     return AUDIO_CHANNEL_OUT_STEREO;
 }
 
 static audio_format_t out_get_format(const struct audio_stream *stream)
 {
+    ALOGV("out_get_format");
     return AUDIO_FORMAT_PCM_16_BIT;
 }
 
 static int out_set_format(struct audio_stream *stream, audio_format_t format)
 {
-    return 0;
+    ALOGV("out_set_format: %d",format);
+    return -ENOSYS;
 }
 
 static int out_standby(struct audio_stream *stream)
 {
+    ALOGV("out_standby");
+
     return 0;
 }
 
 static int out_dump(const struct audio_stream *stream, int fd)
 {
+    ALOGV("out_dump");
     return 0;
 }
 
 static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
 {
+    ALOGV("out_set_parameters");
     return 0;
 }
 
 static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
 {
+    ALOGV("out_get_parameters");
     return strdup("");
 }
 
 static uint32_t out_get_latency(const struct audio_stream_out *stream)
 {
+    ALOGV("out_get_latency");
     return 0;
 }
 
 static int out_set_volume(struct audio_stream_out *stream, float left,
                           float right)
 {
+    ALOGV("out_set_volume: Left:%f Right:%f", left, right);
     return 0;
 }
 
 static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
                          size_t bytes)
 {
+    ALOGV("out_write: bytes: %d", bytes);
     /* XXX: fake timing for audio output */
-    usleep(bytes * 1000000 / audio_stream_out_frame_size(stream) /
+    usleep((int64_t)bytes * 1000000 / audio_stream_out_frame_size(stream) /
            out_get_sample_rate(&stream->common));
     return bytes;
 }
@@ -114,43 +127,53 @@
 static int out_get_render_position(const struct audio_stream_out *stream,
                                    uint32_t *dsp_frames)
 {
+    *dsp_frames = 0;
+    ALOGV("out_get_render_position: dsp_frames: %p", dsp_frames);
     return -EINVAL;
 }
 
 static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
 {
+    ALOGV("out_add_audio_effect: %p", effect);
     return 0;
 }
 
 static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
 {
+    ALOGV("out_remove_audio_effect: %p", effect);
     return 0;
 }
 
 static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
                                         int64_t *timestamp)
 {
+    *timestamp = 0;
+    ALOGV("out_get_next_write_timestamp: %ld", (long int)(*timestamp));
     return -EINVAL;
 }
 
 /** audio_stream_in implementation **/
 static uint32_t in_get_sample_rate(const struct audio_stream *stream)
 {
+    ALOGV("in_get_sample_rate");
     return 8000;
 }
 
 static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
 {
-    return 0;
+    ALOGV("in_set_sample_rate: %d", rate);
+    return -ENOSYS;
 }
 
 static size_t in_get_buffer_size(const struct audio_stream *stream)
 {
+    ALOGV("in_get_buffer_size: %d", 320);
     return 320;
 }
 
 static audio_channel_mask_t in_get_channels(const struct audio_stream *stream)
 {
+    ALOGV("in_get_channels: %d", AUDIO_CHANNEL_IN_MONO);
     return AUDIO_CHANNEL_IN_MONO;
 }
 
@@ -161,7 +184,7 @@
 
 static int in_set_format(struct audio_stream *stream, audio_format_t format)
 {
-    return 0;
+    return -ENOSYS;
 }
 
 static int in_standby(struct audio_stream *stream)
@@ -193,9 +216,11 @@
 static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
                        size_t bytes)
 {
+    ALOGV("in_read: bytes %d", bytes);
     /* XXX: fake timing for audio input */
-    usleep(bytes * 1000000 / audio_stream_in_frame_size(stream) /
+    usleep((int64_t)bytes * 1000000 / audio_stream_in_frame_size(stream) /
            in_get_sample_rate(&stream->common));
+    memset(buffer, 0, bytes);
     return bytes;
 }
 
@@ -222,6 +247,8 @@
                                    struct audio_stream_out **stream_out,
                                    const char *address __unused)
 {
+    ALOGV("adev_open_output_stream...");
+
     struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
     struct stub_stream_out *out;
     int ret;
@@ -260,68 +287,81 @@
 static void adev_close_output_stream(struct audio_hw_device *dev,
                                      struct audio_stream_out *stream)
 {
+    ALOGV("adev_close_output_stream...");
     free(stream);
 }
 
 static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
 {
+    ALOGV("adev_set_parameters");
     return -ENOSYS;
 }
 
 static char * adev_get_parameters(const struct audio_hw_device *dev,
                                   const char *keys)
 {
-    return NULL;
+    ALOGV("adev_get_parameters");
+    return strdup("");
 }
 
 static int adev_init_check(const struct audio_hw_device *dev)
 {
+    ALOGV("adev_init_check");
     return 0;
 }
 
 static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
 {
+    ALOGV("adev_set_voice_volume: %f", volume);
     return -ENOSYS;
 }
 
 static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
 {
+    ALOGV("adev_set_master_volume: %f", volume);
     return -ENOSYS;
 }
 
 static int adev_get_master_volume(struct audio_hw_device *dev, float *volume)
 {
+    ALOGV("adev_get_master_volume: %f", *volume);
     return -ENOSYS;
 }
 
 static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
 {
+    ALOGV("adev_set_master_mute: %d", muted);
     return -ENOSYS;
 }
 
 static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted)
 {
+    ALOGV("adev_get_master_mute: %d", *muted);
     return -ENOSYS;
 }
 
 static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
 {
+    ALOGV("adev_set_mode: %d", mode);
     return 0;
 }
 
 static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
 {
+    ALOGV("adev_set_mic_mute: %d",state);
     return -ENOSYS;
 }
 
 static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
 {
+    ALOGV("adev_get_mic_mute");
     return -ENOSYS;
 }
 
 static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
                                          const struct audio_config *config)
 {
+    ALOGV("adev_get_input_buffer_size: %d", 320);
     return 320;
 }
 
@@ -334,6 +374,8 @@
                                   const char *address __unused,
                                   audio_source_t source __unused)
 {
+    ALOGV("adev_open_input_stream...");
+
     struct stub_audio_device *ladev = (struct stub_audio_device *)dev;
     struct stub_stream_in *in;
     int ret;
@@ -370,16 +412,19 @@
 static void adev_close_input_stream(struct audio_hw_device *dev,
                                    struct audio_stream_in *in)
 {
+    ALOGV("adev_close_input_stream...");
     return;
 }
 
 static int adev_dump(const audio_hw_device_t *device, int fd)
 {
+    ALOGV("adev_dump");
     return 0;
 }
 
 static int adev_close(hw_device_t *device)
 {
+    ALOGV("adev_close");
     free(device);
     return 0;
 }
@@ -387,6 +432,8 @@
 static int adev_open(const hw_module_t* module, const char* name,
                      hw_device_t** device)
 {
+    ALOGV("adev_open: %s", name);
+
     struct stub_audio_device *adev;
     int ret;