Change mbtk_ril for band set.

Change-Id: I2a05f2b8493f2d88750f499189c8c25d025a9f7f
diff --git a/mbtk/mbtk_ril/src/mbtk_info_server.c b/mbtk/mbtk_ril/src/mbtk_info_server.c
index 6a3454d..2659aaf 100755
--- a/mbtk/mbtk_ril/src/mbtk_info_server.c
+++ b/mbtk/mbtk_ril/src/mbtk_info_server.c
@@ -21,6 +21,7 @@
 #include "info_data.h"
 #include "mbtk_led.h"
 #include "cust_info.h"
+#include "mbtk_device.h"
 
 static int sock_listen_fd = -1;
 static int epoll_fd = -1;
@@ -6390,12 +6391,14 @@
 
 OK
 */
-static int band_config()
+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
@@ -6416,19 +6419,58 @@
     } 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.");
-        err = -1;
-        goto error;
+        LOGE("*BAND exec error, will retry in 3s.");
+        sleep(3);
+        goto retry;
     }
 
     LOGD("Set Band Success.");
-    err = 0;
+    property_set("persist.mbtk.band_config", "ALL");
+#else
+    mbtk_device_info_modem_t info_modem;
+    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))) {
+        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;
+        }
 
-error:
+        property_set("persist.mbtk.band_config", "ALL");
+    } 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;
+        }
+
+        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");
+        } else {
+            property_set("persist.mbtk.band_config", "ALL");
+        }
+    }
+
+    LOGD("Set Band Success.");
+#endif
+
     at_response_free(p_response);
-    return err;
+    return NULL;
 }
 
 static void* net_monitor_thread(void* arg)
@@ -6605,17 +6647,6 @@
     {
         LOGE("SIM NOT READY!");
     }
-
-    // Set Band
-    // AT*BAND=15,78,147,482,134742231
-    char buff[10];
-    memset(buff, 0, 10);
-    property_get("persist.mbtk.band_config", buff, "0");
-    if(atoi(buff) == 0) {
-        if(!band_config()) { // Set band success.
-            property_set("persist.mbtk.band_config", "1");
-        }
-    }
 }
 
 int mbtk_info_server_start()
@@ -6704,6 +6735,19 @@
 
     ril_at_ready_process();
 
+    // Set Band
+    // AT*BAND=15,78,147,482,134742231
+    char buff[10];
+    memset(buff, 0, 10);
+    property_get("persist.mbtk.band_config", buff, "");
+    if(strlen(buff) == 0) {
+        pthread_t band_pid;
+        if(pthread_create(&band_pid, &thread_attr, band_config_thread, NULL))
+        {
+            LOG("pthread_create() fail.");
+        }
+    }
+
     if(pthread_create(&monitor_pid, &thread_attr, net_monitor_thread, NULL))
     {
         LOG("pthread_create() fail.");