blob: d571f15a1f85f5bfe258fa94af59636afb38447b [file] [log] [blame]
wangyouqiang16aadb02024-04-12 15:47:13 +08001#if 1
2#include <stdio.h>
3//#include <stdlib.h>
b.liu9e8584b2024-11-06 19:21:28 +08004#include <unistd.h>
wangyouqiang16aadb02024-04-12 15:47:13 +08005#include <errno.h>
6#include <pthread.h>
7//#include <string.h>
8#include <fcntl.h>
9//#include <signal.h>
b.liu9e8584b2024-11-06 19:21:28 +080010#include <cutils/properties.h>
wangyouqiang16aadb02024-04-12 15:47:13 +080011
12#include "mbtk_log.h"
13#include "mbtk_info_api.h"
b.liu9e8584b2024-11-06 19:21:28 +080014#include "mbtk_utils.h"
wangyouqiang16aadb02024-04-12 15:47:13 +080015
16#define MBTK_RESULT_FAIL -1
17#define MBTK_RESULT_SUCCESS 0
18
19typedef enum{
20 MBTK_READY_INIT = -1,
21 MBTK_READY_SUCCESS,
22 MBTK_READY_MODEM_FAIL,
23 MBTK_READY_RESPONSE_FAIL,
24 MBTK_READY_SOCKET_FAIL,
25 MBTK_READY_RIL_FAIL
26}mbtk_ready_status_type;
b.liubcf86c92024-08-19 19:48:28 +080027
wangyouqiang16aadb02024-04-12 15:47:13 +080028static mbtk_ready_status_type mbtk_ready_status = MBTK_READY_INIT;
29static mbtk_info_handle_t* mbtk_handle = NULL;
30#if 1
31static mbtk_ready_status_type modem_check(void)
32{
33 char imei[16]= {0};
34 int cme_err = 0;
35
36 if(mbtk_handle == NULL)
37 {
38 mbtk_handle = mbtk_info_handle_get();
39 if(mbtk_handle == NULL)
40 {
41 LOGE("[SDK_READY] mbtk_info_handle_get fail.");
42 return MBTK_READY_RIL_FAIL;
43 }
44 }
45
46 mbtk_handle->info_err = 0;
47 cme_err = mbtk_imei_get(mbtk_handle, imei);
48 //LOGE("[SDK_READY] imei = [%s], cme_err = [%d]", imei, cme_err);
49 if(cme_err == 0 && strlen(imei) == 0)
50 {
51 mbtk_info_handle_free(&mbtk_handle);
52 mbtk_handle = NULL;
53 return MBTK_READY_RIL_FAIL;
54 }
55 if(cme_err != 0 || strlen(imei) == 0)
56 {
57 mbtk_info_handle_free(&mbtk_handle);
58 mbtk_handle = NULL;
59 return MBTK_READY_MODEM_FAIL;
60 }
61 return MBTK_READY_SUCCESS;
62}
63#endif
64
65static void* sdk_ready_check_pthread(void *arg)
66{
67 UNUSED(arg);
68 LOGE("[SDK_READY] sdk_ready_check_pthread entry.");
69
70 mbtk_ready_status_type now_ready_status = MBTK_READY_INIT;
71 char buf[2] = {0};
72 int sleep_time = 30;
73 while(1)
74 {
75 now_ready_status = modem_check();
76 if(now_ready_status != mbtk_ready_status)
77 {
78 buf[0] = '0' + now_ready_status;
79 property_set("persist.mbtk.sdk.state", buf);
80 mbtk_ready_status = now_ready_status;
81 }
82
83 if(now_ready_status != MBTK_READY_SUCCESS)
84 {
85 sleep_time += 2;
86 }
87 else
88 {
89 sleep_time = 30;
90 }
b.liubcf86c92024-08-19 19:48:28 +080091
wangyouqiang16aadb02024-04-12 15:47:13 +080092 sleep(sleep_time);
93 }
94 LOGE("[SDK_READY] sdk_ready_check_pthread exit.");
95 return NULL;
96}
97
98int main(int argc, char *argv[])
99{
b.liubcf86c92024-08-19 19:48:28 +0800100 mbtk_log_init("radio", "MBTK_SDK_READY");
101
102 MBTK_SOURCE_INFO_PRINT("mbtk_sdk_ready");
103
wangyouqiang16aadb02024-04-12 15:47:13 +0800104 if(mbtk_ready_status != MBTK_READY_INIT)
105 {
106 LOGE("[SDK_READY] sdk has check.");
107 return MBTK_RESULT_FAIL;
108 }
109
b.liubb590492024-06-13 16:42:08 +0800110#ifdef MBTK_DUMP_SUPPORT
111 mbtk_debug_open(NULL, TRUE);
112#endif
113
wangyouqiang16aadb02024-04-12 15:47:13 +0800114 LOGE("[SDK_READY] sdk check init.");
115 pthread_t sdk_ready_pid;
116 pthread_attr_t thread_attr;
117 pthread_attr_init(&thread_attr);
118 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
119 {
120 LOGE("[SDK_READY] pthread_attr_setdetachstate() fail.");
121 return MBTK_RESULT_FAIL;
122 }
b.liubcf86c92024-08-19 19:48:28 +0800123
wangyouqiang16aadb02024-04-12 15:47:13 +0800124 if(pthread_create(&sdk_ready_pid, &thread_attr, sdk_ready_check_pthread, NULL))
125 {
126 LOGE("[SDK_READY] pthread_create() fail.");
127 }
128
129 pthread_attr_destroy(&thread_attr);
130
131 LOGE("[SDK_READY] sdk check start.");
132 while(1)
133 {
134 sleep(24 * 60 * 60);
135 }
136
137 LOGE("[SDK_READY]!!!mbtk_sdk_ready exit!!!");
138 return MBTK_RESULT_SUCCESS;
139}
140#endif