Add master branch change.

Change-Id: I8892b7102753d29fefb4e23a7a7cc67c01157560
diff --git a/mbtk/mbtk_rild/inc/info_data.h b/mbtk/mbtk_rild/inc/info_data.h
index ffc0aea..a8e8c3f 100755
--- a/mbtk/mbtk_rild/inc/info_data.h
+++ b/mbtk/mbtk_rild/inc/info_data.h
@@ -50,6 +50,7 @@
     INFO_URC_MSG_SIM_STATE,
     INFO_URC_MSG_PDP_STATE,
     INFO_URC_MSG_SMS_STATE,
+    INFO_URC_MSG_SET_BAND,
     INFO_URC_MSG_NET_STATE_LOG      // Save Network state into file.
 } info_urc_msg_id_enum;
 
diff --git a/mbtk/mbtk_rild/src/main.c b/mbtk/mbtk_rild/src/main.c
index eeabc7c..5812948 100755
--- a/mbtk/mbtk_rild/src/main.c
+++ b/mbtk/mbtk_rild/src/main.c
@@ -321,7 +321,7 @@
                 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));

             } else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>

                 //apn_state_set(atoi(s + 19), true);

-#ifdef MBTK_AF_SUPPORT

+#if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))

 				//data[0] = (uint8)1;

                 //data[1] = (uint8)atoi(s + 19);

 #else

diff --git a/mbtk/mbtk_rild/src/mbtk_info_server.c b/mbtk/mbtk_rild/src/mbtk_info_server.c
index 2659aaf..81633e1 100755
--- a/mbtk/mbtk_rild/src/mbtk_info_server.c
+++ b/mbtk/mbtk_rild/src/mbtk_info_server.c
@@ -23,6 +23,16 @@
 #include "cust_info.h"
 #include "mbtk_device.h"
 
+typedef struct {
+    bool band_set_success;
+
+    mbtk_modem_band_area_enum band_area;
+    uint32 band_gsm;
+    uint32 band_wcdma;
+    uint32 band_tdlte;
+    uint32 band_fddlte;
+} band_set_info_t;
+
 static int sock_listen_fd = -1;
 static int epoll_fd = -1;
 static list_node_t *sock_client_list = NULL;
@@ -32,6 +42,7 @@
 static mbtk_queue_node_t urc_queue;
 static pthread_cond_t urc_cond;
 static pthread_mutex_t urc_mutex;
+static band_set_info_t band_set_info;
 
 static mbtk_band_info_t band_support;
 net_info_t net_info;
@@ -5094,7 +5105,7 @@
 
                             int timeout = pack->data[2];
                             //mbtk wyq for data_call_ex add end
-#ifdef MBTK_AF_SUPPORT
+#if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))
                             if(cid == 1)
                             {
                                 char dev[20] = {0};
@@ -6154,6 +6165,34 @@
             }
             break;
         }
+        case INFO_URC_MSG_SET_BAND:
+        {
+            mbtk_band_info_t band;
+            int cme_err = MBTK_INFO_ERR_CME_NON;
+
+            band.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF;  // 15
+            band.gsm_band = band_set_info.band_gsm;
+            band.umts_band = band_set_info.band_wcdma;
+            band.tdlte_band = band_set_info.band_tdlte;
+            band.fddlte_band = band_set_info.band_fddlte;
+            if(req_band_set(&band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
+            {
+                LOG("Set band fail.");
+            }
+            else // Set band success.
+            {
+                band_set_info.band_set_success = TRUE;
+                if(band_set_info.band_area == MBTK_MODEM_BAND_AREA_CN) {
+                    property_set("persist.mbtk.band_config", "CN");
+                } else if(band_set_info.band_area == MBTK_MODEM_BAND_AREA_EU) {
+                    property_set("persist.mbtk.band_config", "EU");
+                } else {
+                    property_set("persist.mbtk.band_config", "ALL");
+                }
+                LOG("Set band success.");
+            }
+            break;
+        }
         case INFO_URC_MSG_NET_STATE_LOG:
         {
             // Get network state and signal.
@@ -6393,83 +6432,48 @@
 */
 static void* band_config_thread()
 {
-    int err = -1;
-    ATResponse *p_response = NULL;
-
-#if 0
-    mbtk_cust_info_t cust_info;
-retry:
-    memset(&cust_info, 0x0, sizeof(mbtk_cust_info_t));
-    if(!custom_partition_read("cust_info", &cust_info)) {
-        if(cust_info.band_type == 1) { // CN
-            // GSM : B3/B8
-            // WCDMA : B1/B5/B8
-            // TDD-LTE : B34/B38/B39/B40/B41
-            // FDD-LTE : B1/B3/B5/B8
-            err = at_send_command("AT*BAND=15,11,145,482,149", &p_response);
-        } else if(cust_info.band_type == 2) { // EU
-            // GSM : B3/B8
-            // WCDMA : B1/B5/B8
-            // TDD-LTE : B38/B40/B41
-            // FDD-LTE : B1/B3/B5/B7/B8/B20/B28
-            err = at_send_command("AT*BAND=15,11,145,416,134742229", &p_response);
-        } else {
-            err = at_send_command("AT*BAND=15,78,147,482,134742231", &p_response);
-        }
-    } else {
-        err = at_send_command("AT*BAND=15,78,147,482,134742231", &p_response);
-    }
-
-    if ((err < 0) || (p_response == NULL) || (p_response->success == 0))
-    {
-        LOGE("*BAND exec error, will retry in 3s.");
-        sleep(3);
-        goto retry;
-    }
-
-    LOGD("Set Band Success.");
-    property_set("persist.mbtk.band_config", "ALL");
-#else
     mbtk_device_info_modem_t info_modem;
+    memset(&band_set_info, 0, sizeof(band_set_info_t));
     memset(&info_modem, 0, sizeof(mbtk_device_info_modem_t));
-    if(mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_MODEM, &info_modem, sizeof(mbtk_device_info_modem_t))) {
+    band_set_info.band_set_success = FALSE;
+    if(mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_MODEM, &(info_modem), sizeof(mbtk_device_info_modem_t))) {
         LOGD("mbtk_dev_info_read(MODEM) fail, use default band.");
-retry_default:
-        err = at_send_command("AT*BAND=15,78,147,482,134742231", &p_response);
-        if ((err < 0) || (p_response == NULL) || (p_response->success == 0))
-        {
-            LOGE("*BAND exec error, will retry in 3s.");
-            sleep(3);
-            goto retry_default;
-        }
-
-        property_set("persist.mbtk.band_config", "ALL");
+        band_set_info.band_area = MBTK_MODEM_BAND_AREA_ALL;
+        band_set_info.band_gsm = MBTK_BAND_ALL_GSM_DEFAULT;
+        band_set_info.band_wcdma = MBTK_BAND_ALL_WCDMA_DEFAULT;
+        band_set_info.band_tdlte = MBTK_BAND_ALL_TDLTE_DEFAULT;
+        band_set_info.band_fddlte = MBTK_BAND_ALL_FDDLTE_DEFAULT;
     } else {
-        char cmd[128] = {0};
-        snprintf(cmd, 128, "AT*BAND=15,%d,%d,%d,%d", info_modem.band_gsm,
-            info_modem.band_wcdma, info_modem.band_tdlte, info_modem.band_fddlte);
-retry_by_dev:
-        err = at_send_command(cmd, &p_response);
-        if ((err < 0) || (p_response == NULL) || (p_response->success == 0))
-        {
-            LOGE("*BAND exec error, will retry in 3s.");
-            sleep(3);
-            goto retry_by_dev;
-        }
+        band_set_info.band_area = info_modem.band_area;
+        band_set_info.band_gsm = info_modem.band_gsm;
+        band_set_info.band_wcdma = info_modem.band_wcdma;
+        band_set_info.band_tdlte = info_modem.band_tdlte;
+        band_set_info.band_fddlte = info_modem.band_fddlte;
+    }
 
-        if(info_modem.band_area == MBTK_MODEM_BAND_AREA_CN) {
-            property_set("persist.mbtk.band_config", "CN");
-        } else if(info_modem.band_area == MBTK_MODEM_BAND_AREA_EU) {
-            property_set("persist.mbtk.band_config", "EU");
+    bool is_first = TRUE;
+    while(!band_set_info.band_set_success) {
+        info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
+        if(!urc)
+        {
+            LOG("malloc() fail[%d].", errno);
+            break;
         } else {
-            property_set("persist.mbtk.band_config", "ALL");
+            urc->msg = INFO_URC_MSG_SET_BAND;
+            urc->data = NULL;
+            urc->data_len = 0;
+            send_pack_to_queue(NULL, urc);
+
+            if(is_first) {
+                is_first = FALSE;
+            } else {
+                LOGE("*BAND exec error, will retry in 3s.");
+            }
+            sleep(3);
         }
     }
 
-    LOGD("Set Band Success.");
-#endif
-
-    at_response_free(p_response);
+    LOGD("Set Band thread exit.");
     return NULL;
 }