hal: Fix warnings in audio HAL and policy

Enable Wall and Werror and fix warnings in
HAL and policy manager

CRs-Fixed: 962049

Change-Id: Ie93c8f933943875ac68e8318d777602ed864f531
diff --git a/hal/Android.mk b/hal/Android.mk
index ea54bd5..229b3f4 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -282,6 +282,8 @@
     LOCAL_SHARED_LIBRARIES += libperipheral_client
 endif
 
+LOCAL_CFLAGS += -Wall -Werror
+
 LOCAL_COPY_HEADERS_TO   := mm-audio
 LOCAL_COPY_HEADERS      := audio_extn/audio_defs.h
 
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index b8b8b85..28a0b2d 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -222,7 +222,7 @@
 #else
 void audio_extn_source_track_set_parameters(struct audio_device *adev,
                                             struct str_parms *parms);
-void audio_extn_source_track_get_parameters(struct audio_device *adev,
+void audio_extn_source_track_get_parameters(const struct audio_device *adev,
                                             struct str_parms *query,
                                             struct str_parms *reply);
 #endif
@@ -1110,7 +1110,8 @@
 {
 
     if (!perf_lock_opts || !size || !perf_lock_acq || !handle) {
-        ALOGE("%s: Invalid arguments", __func__);
+        ALOGE("%s: Incorrect params, Failed to acquire perf lock, err ",
+              __func__);
         return;
     }
     /*
diff --git a/hal/audio_extn/dolby.c b/hal/audio_extn/dolby.c
index c8bf543..115057c 100644
--- a/hal/audio_extn/dolby.c
+++ b/hal/audio_extn/dolby.c
@@ -655,7 +655,8 @@
     ds2extnmod.dap_hal_set_hw_info(SND_CARD, (void*)(&snd_card));
     ALOGV("%s Sound card number is:%d",__func__,snd_card);
 
-    platform_get_device_to_be_id_map(&device_be_id_map.device_id_to_be_id, &device_be_id_map.len);
+    platform_get_device_to_be_id_map((int**)&device_be_id_map.device_id_to_be_id,
+            &device_be_id_map.len);
     ds2extnmod.dap_hal_set_hw_info(DEVICE_BE_ID_MAP, (void*)(&device_be_id_map));
     ALOGV("%s Set be id map len:%d",__func__,device_be_id_map.len);
     ret = 0;
@@ -771,8 +772,9 @@
     if (ds2extnmod.dap_hal_set_hw_info) {
         ds2extnmod.dap_hal_set_hw_info(DMID, (void*)(&dolby_license.dmid));
     } else {
-        ALOGV("%s: dap_hal_set_hw_info is NULL", __func__);
+        ALOGE("%s: dap_hal_set_hw_info is NULL", __func__);
     }
+    return;
 }
 
 
diff --git a/hal/audio_extn/source_track.c b/hal/audio_extn/source_track.c
index 316e52d..8bf4c67 100644
--- a/hal/audio_extn/source_track.c
+++ b/hal/audio_extn/source_track.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -91,8 +91,8 @@
 #define MAX_SECTORS                                         8
 #define MAX_STR_SIZE                                       2048
 
-struct audio_device_to_audio_interface audio_device_to_interface_table[];
-int audio_device_to_interface_table_len;
+extern struct audio_device_to_audio_interface audio_device_to_interface_table[];
+extern int audio_device_to_interface_table_len;
 
 struct sound_focus_param {
     uint16_t start_angle[MAX_SECTORS];
@@ -203,7 +203,7 @@
     return in_device;
 }
 
-static int derive_mixer_ctl_from_usecase_intf(struct audio_device *adev,
+static int derive_mixer_ctl_from_usecase_intf(const struct audio_device *adev,
                                               char *mixer_ctl_name) {
     struct audio_usecase *usecase = NULL;
     audio_devices_t in_device;
@@ -330,7 +330,7 @@
     return ret;
 }
 
-static int get_soundfocus_sourcetracking_data(struct audio_device *adev,
+static int get_soundfocus_sourcetracking_data(const struct audio_device *adev,
                                         const int bitmask,
                                         struct sound_focus_param *sound_focus_data,
                                         struct source_tracking_param *source_tracking_data)
@@ -496,7 +496,7 @@
     }
 }
 
-void audio_extn_source_track_get_parameters(struct audio_device *adev,
+void audio_extn_source_track_get_parameters(const struct audio_device *adev,
                                             struct str_parms *query,
                                             struct str_parms *reply)
 {
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 3698294..35522ac 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -835,7 +835,7 @@
     return ret;
 }
 
-audio_usecase_t get_usecase_id_from_usecase_type(struct audio_device *adev,
+audio_usecase_t get_usecase_id_from_usecase_type(const struct audio_device *adev,
                                                  usecase_type_t type)
 {
     struct audio_usecase *usecase;
@@ -851,7 +851,7 @@
     return USECASE_INVALID;
 }
 
-struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
+struct audio_usecase *get_usecase_from_list(const struct audio_device *adev,
                                             audio_usecase_t uc_id)
 {
     struct audio_usecase *usecase;
@@ -1341,7 +1341,7 @@
 {
     audio_usecase_t ret_uc = USECASE_INVALID;
     unsigned int offload_uc_index;
-    int num_usecase = sizeof(offload_usecases)/sizeof(offload_usecases[0]);
+    unsigned int num_usecase = sizeof(offload_usecases)/sizeof(offload_usecases[0]);
     if (!adev->multi_offload_enable) {
         if (is_direct_pcm)
             ret_uc = USECASE_AUDIO_PLAYBACK_OFFLOAD2;
@@ -1373,7 +1373,7 @@
                                  audio_usecase_t uc_id)
 {
     unsigned int offload_uc_index;
-    int num_usecase = sizeof(offload_usecases)/sizeof(offload_usecases[0]);
+    unsigned int num_usecase = sizeof(offload_usecases)/sizeof(offload_usecases[0]);
 
     if (!adev->multi_offload_enable)
         return;
@@ -2349,7 +2349,7 @@
     }
 
     if (adev->is_channel_status_set == false && (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)){
-        audio_utils_set_hdmi_channel_status(out, buffer, bytes);
+        audio_utils_set_hdmi_channel_status(out, (void *)buffer, bytes);
         adev->is_channel_status_set = true;
     }
 
@@ -2429,7 +2429,7 @@
 
     if (ret != 0) {
         if (out->pcm)
-            ALOGE("%s: error %zu - %s", __func__, ret, pcm_get_error(out->pcm));
+            ALOGE("%s: error %d, %s", __func__, (int)ret, pcm_get_error(out->pcm));
         if (out->usecase == USECASE_COMPRESS_VOIP_CALL) {
             pthread_mutex_lock(&adev->lock);
             voice_extn_compress_voip_close_output_stream(&out->stream.common);
@@ -3131,7 +3131,7 @@
         }
 
         if (out->usecase == USECASE_INVALID) {
-            ALOGE("%s: Max allowed OFFLOAD usecase reached ... ");
+            ALOGE("%s, Max allowed OFFLOAD usecase reached ... ", __func__);
             ret = -EEXIST;
             goto error_open;
         }
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 47c9070..a7d4483 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
  * Not a contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -373,7 +373,7 @@
 int enable_audio_route(struct audio_device *adev,
                        struct audio_usecase *usecase);
 
-struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
+struct audio_usecase *get_usecase_from_list(const struct audio_device *adev,
                                                    audio_usecase_t uc_id);
 
 bool is_offload_usecase(audio_usecase_t uc_id);
@@ -383,7 +383,7 @@
 int pcm_ioctl(struct pcm *pcm, int request, ...);
 
 int get_snd_card_state(struct audio_device *adev);
-audio_usecase_t get_usecase_id_from_usecase_type(struct audio_device *adev,
+audio_usecase_t get_usecase_id_from_usecase_type(const struct audio_device *adev,
                                                  usecase_type_t type);
 
 #define LITERAL_TO_STRING(x) #x
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 2f9c2e8..fe502da 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -1303,7 +1303,7 @@
     backend_table[SND_DEVICE_OUT_VOICE_SPEAKER_VBAT] = strdup("vbat-voice-speaker");
 
     /*remove ALAC & APE from DSP decoder list based on software decoder availability*/
-    for (count = 0; count < sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]);
+    for (count = 0; count < (int32_t) (sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]));
             count++) {
 
         if (!strncmp(MEDIA_MIMETYPE_AUDIO_ALAC, dsp_only_decoders_mime[count],
@@ -1619,10 +1619,10 @@
         /* update wsa combo supported flag based on sound card name */
         /* wsa combo flag needs to be set to true only for hardware
            combinations which has support for both wsa and non-wsa speaker */
-        if (snd_card_name && (!strncmp(snd_card_name, "msm8953-snd-card-mtp",
+        if (snd_card_name && ((!strncmp(snd_card_name, "msm8953-snd-card-mtp",
                 sizeof("msm8953-snd-card-mtp"))) ||
-            !strncmp(snd_card_name, "msm8952-skum-snd-card",
-                sizeof("msm8952-skum-snd-card"))) {
+            (!strncmp(snd_card_name, "msm8952-skum-snd-card",
+                sizeof("msm8952-skum-snd-card"))))) {
             *is_wsa_combo_supported = true;
         } else {
             *is_wsa_combo_supported = false;
@@ -1763,7 +1763,7 @@
         }
     }
 
-    if (check_and_get_wsa_info(snd_card_name, &wsaCount, &is_wsa_combo_supported)) {
+    if (check_and_get_wsa_info((char *)snd_card_name, &wsaCount, &is_wsa_combo_supported)) {
         /*Set ACDB ID of Stereo speaker if two WSAs are present*/
         /*Default ACDB ID for wsa speaker is that for mono*/
         if (wsaCount == 2) {
@@ -2359,7 +2359,7 @@
                     OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
                          ALOGD("%s:napb: triggering dynamic device switch for usecase(%d: %s)"
                                " stream(%p), device(%d)", __func__, usecase->id,
-                               use_case_table[usecase->id], usecase->stream,
+                               use_case_table[usecase->id], (void*) usecase->stream.out,
                                usecase->stream.out->devices);
                          select_devices(platform->adev, usecase->id);
                  }
@@ -3467,7 +3467,7 @@
 
 static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len) {
     struct platform_data *my_data = (struct platform_data *)platform;
-    struct stream_out out={0};
+    struct stream_out out;
     acdb_audio_cal_cfg_t cal={0};
     uint8_t *dptr = NULL;
     int32_t dlen;
@@ -3708,7 +3708,7 @@
 
 static void get_audiocal(void *platform, void *keys, void *pReply) {
     struct platform_data *my_data = (struct platform_data *)platform;
-    struct stream_out out={0};
+    struct stream_out out;
     struct str_parms *query = (struct str_parms *)keys;
     struct str_parms *reply=(struct str_parms *)pReply;
     acdb_audio_cal_cfg_t cal={0};
@@ -3857,7 +3857,7 @@
 
             //check if unsupported mime type or not
             if(decoder_mime_type) {
-                int i = 0;
+                unsigned int i = 0;
                 for (i = 0; i < sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]); i++) {
                     if (!strncmp(decoder_mime_type, dsp_only_decoders_mime[i],
                     strlen(dsp_only_decoders_mime[i]))) {
@@ -4439,7 +4439,7 @@
 
 void platform_get_device_to_be_id_map(int **device_to_be_id, int *length)
 {
-     *device_to_be_id = msm_device_to_be_id;
+     *device_to_be_id = (int*) msm_device_to_be_id;
      *length = msm_be_id_array_len;
 }
 int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask, int snd_id)
@@ -5019,7 +5019,7 @@
  * corresponding entry in audio_platform_info.xml file.
  */
 struct speaker_device_to_tz_names speaker_device_tz_names = {
-    {SND_DEVICE_OUT_SPEAKER, "", ""},
+    SND_DEVICE_OUT_SPEAKER, "", ""
 };
 
 const char *platform_get_spkr_1_tz_name(snd_device_t snd_device)
@@ -5050,7 +5050,7 @@
         goto done;
     }
     if (index != speaker_device_tz_names.snd_device) {
-        ALOGE("%s: not matching speaker device\n");
+        ALOGE("%s: not matching speaker device\n", __func__);
         ret = -EINVAL;
         goto done;
     }
@@ -5071,7 +5071,7 @@
 int platform_spkr_prot_is_wsa_analog_mode(void *adev)
 {
     struct audio_device *adev_h = adev;
-    char *snd_card_name;
+    const char *snd_card_name;
 
     /*
      * wsa analog mode is decided based on the sound card name
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 516179a..d9e7745 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -1067,7 +1067,7 @@
 
 
      /*remove ALAC & APE from DSP decoder list based on software decoder availability*/
-     for (count = 0; count < sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]);
+     for (count = 0; count < (int32_t)(sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]));
             count++) {
 
          if (!strncmp(MEDIA_MIMETYPE_AUDIO_ALAC, dsp_only_decoders_mime[count],
@@ -1300,7 +1300,7 @@
     char value[PROPERTY_VALUE_MAX];
     struct platform_data *my_data = NULL;
     int retry_num = 0, snd_card_num = 0, key = 0;
-    const char *snd_card_name = NULL, *snd_card_name_t = NULL;
+    char *snd_card_name = NULL, *snd_card_name_t = NULL;
     char *cvd_version = NULL;
     char *snd_internal_name = NULL;
     char *tmp = NULL;
@@ -1399,9 +1399,12 @@
             if (!adev->audio_route) {
                 ALOGE("%s: Failed to init audio route controls, aborting.",
                        __func__);
-                free(my_data);
-                free(snd_card_name);
-                free(snd_card_name_t);
+                if (my_data)
+                    free(my_data);
+                if (snd_card_name)
+                    free(snd_card_name);
+                if (snd_card_name_t)
+                    free(snd_card_name_t);
                 mixer_close(adev->mixer);
                 return NULL;
             }
@@ -1416,11 +1419,13 @@
 
     if (snd_card_num >= MAX_SND_CARD) {
         ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
-        free(my_data);
+        if (my_data)
+            free(my_data);
         if (snd_card_name)
             free(snd_card_name);
         if (snd_card_name_t)
             free(snd_card_name_t);
+        mixer_close(adev->mixer);
         return NULL;
     }
 
@@ -1891,6 +1896,7 @@
 
 int platform_get_default_app_type_v2(void *platform, usecase_type_t  type)
 {
+    ALOGV("%s: Platform: %p, type: %d", __func__, platform, type);
     if(type == PCM_CAPTURE)
         return DEFAULT_APP_TYPE_TX_PATH;
     else
@@ -2035,9 +2041,10 @@
                     (usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
                     usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) &&
                     OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
-                         ALOGD("%s:napb: triggering dynamic device switch for usecase(%d: %s)"
-                               " stream(%p), device(%d)", __func__, usecase->id,
-                               use_case_table[usecase->id], usecase->stream,
+                         ALOGD("%s:napb: triggering dynamic device switch for usecase %d, %s"
+                               " stream %p, device (%u)", __func__, usecase->id,
+                               use_case_table[usecase->id],
+                               (void*) usecase->stream.out,
                                usecase->stream.out->devices);
                          select_devices(platform->adev, usecase->id);
                  }
@@ -3540,7 +3547,7 @@
 
             //check if unsupported mime type or not
             if(decoder_mime_type) {
-                int i = 0;
+                unsigned int i = 0;
                 for (i = 0; i < sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]); i++) {
                     if (!strncmp(decoder_mime_type, dsp_only_decoders_mime[i],
                     strlen(dsp_only_decoders_mime[i]))) {
@@ -3995,7 +4002,7 @@
 
 void platform_get_device_to_be_id_map(int **device_to_be_id, int *length)
 {
-     *device_to_be_id = msm_device_to_be_id;
+     *device_to_be_id = (int*) msm_device_to_be_id;
      *length = msm_be_id_array_len;
 }
 int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask, int snd_id)
diff --git a/hal/voice.c b/hal/voice.c
index b10de17..d1db987 100644
--- a/hal/voice.c
+++ b/hal/voice.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
  * Not a contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -276,12 +276,12 @@
     return call_state;
 }
 
-bool voice_is_in_call(struct audio_device *adev)
+bool voice_is_in_call(const struct audio_device *adev)
 {
     return adev->voice.in_call;
 }
 
-bool voice_is_in_call_rec_stream(struct stream_in *in)
+bool voice_is_in_call_rec_stream(const struct stream_in *in)
 {
     bool in_call_rec = false;
 
diff --git a/hal/voice.h b/hal/voice.h
index 7cb9e1a..efe48d8 100644
--- a/hal/voice.h
+++ b/hal/voice.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
  * Not a contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -81,8 +81,8 @@
 void voice_get_parameters(struct audio_device *adev, struct str_parms *query,
                           struct str_parms *reply);
 void voice_init(struct audio_device *adev);
-bool voice_is_in_call(struct audio_device *adev);
-bool voice_is_in_call_rec_stream(struct stream_in *in);
+bool voice_is_in_call(const struct audio_device *adev);
+bool voice_is_in_call_rec_stream(const struct stream_in *in);
 int voice_set_mic_mute(struct audio_device *dev, bool state);
 bool voice_get_mic_mute(struct audio_device *dev);
 int voice_set_volume(struct audio_device *adev, float volume);
diff --git a/hal/voice_extn/compress_voip.c b/hal/voice_extn/compress_voip.c
index 1dcf865..61a7f3e 100644
--- a/hal/voice_extn/compress_voip.c
+++ b/hal/voice_extn/compress_voip.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
  * Not a contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -689,7 +689,7 @@
         return false;
 }
 
-bool voice_extn_compress_voip_is_active(struct audio_device *adev)
+bool voice_extn_compress_voip_is_active(const struct audio_device *adev)
 {
     struct audio_usecase *voip_usecase = NULL;
     voip_usecase = get_usecase_from_list(adev, USECASE_COMPRESS_VOIP_CALL);
diff --git a/hal/voice_extn/voice_extn.h b/hal/voice_extn/voice_extn.h
index af0ad08..989ee79 100644
--- a/hal/voice_extn/voice_extn.h
+++ b/hal/voice_extn/voice_extn.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2014, 2016, The Linux Foundation. All rights reserved.
  * Not a contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -142,7 +142,7 @@
                                                 struct str_parms *query,
                                                 struct str_parms *reply);
 bool voice_extn_compress_voip_pcm_prop_check();
-bool voice_extn_compress_voip_is_active(struct audio_device *adev);
+bool voice_extn_compress_voip_is_active(const struct audio_device *adev);
 bool voice_extn_compress_voip_is_format_supported(audio_format_t format);
 bool voice_extn_compress_voip_is_config_supported(struct audio_config *config);
 bool voice_extn_compress_voip_is_started(struct audio_device *adev);
diff --git a/policy_hal/Android.mk b/policy_hal/Android.mk
index 70814d8..811c2c9 100644
--- a/policy_hal/Android.mk
+++ b/policy_hal/Android.mk
@@ -27,6 +27,8 @@
 LOCAL_STATIC_LIBRARIES := \
     libmedia_helper \
 
+LOCAL_CFLAGS += -Wall -Werror
+
 ifeq ($(strip $(AUDIO_FEATURE_ENABLED_VOICE_CONCURRENCY)),true)
 LOCAL_CFLAGS += -DVOICE_CONCURRENCY
 endif