qcom/audio/hal: Move the check for network opeartor to proper place

- Check for the network operator at boot up does not return correct
  value always
- For the T-Mobile, US the HANDSET and MIC devices need different
  gain settings
- Do the check before enabling those devices

Bug: 8255423
Change-Id: I58011f9c239dce87507b581a62e0dcc09164d15a
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 7e9fc18..8b0bf97 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -160,6 +160,32 @@
 
 int edid_get_max_channels(void);
 
+static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
+static bool is_tmus = false;
+
+static void check_operator()
+{
+    char value[PROPERTY_VALUE_MAX];
+    int mccmnc;
+    property_get("gsm.sim.operator.numeric",value,"0");
+    mccmnc = atoi(value);
+    ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
+    switch(mccmnc) {
+    /* TMUS MCC(310), MNC(490, 260, 026) */
+    case 310490:
+    case 310260:
+    case 310026:
+        is_tmus = true;
+        break;
+    }
+}
+
+static bool is_operator_tmus()
+{
+    pthread_once(&check_op_once_ctl, check_operator);
+    return is_tmus;
+}
+
 static int get_pcm_device_id(struct audio_route *ar,
                              audio_usecase_t usecase,
                              int device_type)
@@ -364,7 +390,7 @@
         } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
             snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
         } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
-            if (adev->is_tmus)
+            if (is_operator_tmus())
                 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
             else
                 snd_device = SND_DEVICE_OUT_HANDSET;
@@ -463,7 +489,7 @@
                 snd_device = SND_DEVICE_IN_HANDSET_MIC;
             } else {
                 if (adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
-                    if (adev->is_tmus)
+                    if (is_operator_tmus())
                         snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS;
                     else
                         snd_device = SND_DEVICE_IN_VOICE_DMIC_EF;
@@ -1951,7 +1977,6 @@
     char platform[PROPERTY_VALUE_MAX];
     char baseband[PROPERTY_VALUE_MAX];
     char value[PROPERTY_VALUE_MAX];
-    int mccmnc;
 
     adev->dualmic_config = DUALMIC_CONFIG_NONE;
     adev->fluence_in_voice_call = false;
@@ -1983,21 +2008,6 @@
         }
     }
 
-    property_get("gsm.sim.operator.numeric",value,"0");
-    mccmnc = atoi(value);
-    ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
-    switch(mccmnc) {
-    /* TMUS MCC(310), MNC(490, 260, 026) */
-    case 310490:
-    case 310260:
-    case 310026:
-        adev->is_tmus = true;
-        break;
-    default:
-        adev->is_tmus = false;
-        break;
-    }
-
     adev->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
     if (adev->acdb_handle == NULL) {
         ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 263f13f..67f0b3a 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -219,7 +219,6 @@
     struct audio_route *audio_route;
     int acdb_settings;
 
-    bool is_tmus;
     bool mic_type_analog;
     bool fluence_in_voice_call;
     bool fluence_in_voice_rec;