add reboot reason function

Change-Id: I5bde2e878f6c2252aed46efe606e388af18988cb
diff --git a/mbtk/mbtk_rild/src/mbtk_info_server.c b/mbtk/mbtk_rild/src/mbtk_info_server.c
old mode 100644
new mode 100755
index 365215d..8862a33
--- a/mbtk/mbtk_rild/src/mbtk_info_server.c
+++ b/mbtk/mbtk_rild/src/mbtk_info_server.c
@@ -7304,6 +7304,45 @@
     return NULL;
 }
 
+static void* reboot_reason_thread(void* arg)
+{
+    UNUSED(arg);
+    int ret = 0;
+    char buff[32] = {0};
+    mbtk_device_info_reboot_flag_enum reboot_reason = MBTK_REBOOT_FLAG_NORMAL;
+    mbtk_device_info_basic_t info_basic = {0};
+    memset(&info_basic, 0, sizeof(mbtk_device_info_basic_t));
+    
+    
+    ret = mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_BASIC, &(info_basic), sizeof(mbtk_device_info_basic_t));
+    if(ret != 0)
+    {
+        LOGE("[%s] mbtk_dev_info_read(BASIC) fail.", __func__);
+        reboot_reason = MBTK_REBOOT_FLAG_UNKNOWN;
+    }
+    else
+    {
+        reboot_reason = info_basic.reboot_flag;
+        if(info_basic.reboot_flag != MBTK_REBOOT_FLAG_NORMAL)
+        {
+            info_basic.reboot_flag = MBTK_REBOOT_FLAG_NORMAL;
+            ret = mbtk_dev_info_write(MBTK_DEVICE_INFO_ITEM_BASIC, &info_basic, sizeof(mbtk_device_info_basic_t));
+            if(ret != 0) {
+                LOGE("[%s] mbtk_dev_info_write(BASIC) fail.", __func__);
+            }
+        }
+    }
+
+    LOGD("[%s] reboot reason [%d].", __func__, reboot_reason);
+    memset(buff, 0x0, 32);
+    sprintf(buff, "%d", reboot_reason);
+    property_set("persist.mbtk.reboot_reason", buff);
+    
+    LOGD("[%s] reboot reason thread exit.", __func__);
+    return NULL;
+}
+
+
 #if 0
 static void* net_monitor_thread(void* arg)
 {
@@ -7583,7 +7622,7 @@
         goto error;
     }
 
-    pthread_t info_pid, pack_pid/*, monitor_pid, urc_pid*/, bootconn_pid;
+    pthread_t info_pid, pack_pid/*, monitor_pid, urc_pid*/, bootconn_pid, reboot_reason_pid;
     pthread_attr_t thread_attr;
     pthread_attr_init(&thread_attr);
     if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
@@ -7625,6 +7664,11 @@
         }
     }
 
+    if(pthread_create(&reboot_reason_pid, &thread_attr, reboot_reason_thread, NULL))
+    {
+        LOGE("[%s] reboot_reason pthread_create() fail.", __func__);
+        goto error;
+    }
 #if 0
     if(pthread_create(&monitor_pid, &thread_attr, net_monitor_thread, NULL))
     {