wangyouqiang | 16aadb0 | 2024-04-12 15:47:13 +0800 | [diff] [blame] | 1 | #if 1 |
| 2 | #include <stdio.h> |
| 3 | //#include <stdlib.h> |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame^] | 4 | #include <unistd.h> |
wangyouqiang | 16aadb0 | 2024-04-12 15:47:13 +0800 | [diff] [blame] | 5 | #include <errno.h> |
| 6 | #include <pthread.h> |
| 7 | //#include <string.h> |
| 8 | #include <fcntl.h> |
| 9 | //#include <signal.h> |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame^] | 10 | #include <cutils/properties.h> |
wangyouqiang | 16aadb0 | 2024-04-12 15:47:13 +0800 | [diff] [blame] | 11 | |
| 12 | #include "mbtk_log.h" |
| 13 | #include "mbtk_info_api.h" |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame^] | 14 | #include "mbtk_utils.h" |
wangyouqiang | 16aadb0 | 2024-04-12 15:47:13 +0800 | [diff] [blame] | 15 | |
| 16 | #define MBTK_RESULT_FAIL -1 |
| 17 | #define MBTK_RESULT_SUCCESS 0 |
| 18 | |
| 19 | typedef 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.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 27 | |
wangyouqiang | 16aadb0 | 2024-04-12 15:47:13 +0800 | [diff] [blame] | 28 | static mbtk_ready_status_type mbtk_ready_status = MBTK_READY_INIT; |
| 29 | static mbtk_info_handle_t* mbtk_handle = NULL; |
| 30 | #if 1 |
| 31 | static 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 | |
| 65 | static 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.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 91 | |
wangyouqiang | 16aadb0 | 2024-04-12 15:47:13 +0800 | [diff] [blame] | 92 | sleep(sleep_time); |
| 93 | } |
| 94 | LOGE("[SDK_READY] sdk_ready_check_pthread exit."); |
| 95 | return NULL; |
| 96 | } |
| 97 | |
| 98 | int main(int argc, char *argv[]) |
| 99 | { |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 100 | mbtk_log_init("radio", "MBTK_SDK_READY"); |
| 101 | |
| 102 | MBTK_SOURCE_INFO_PRINT("mbtk_sdk_ready"); |
| 103 | |
wangyouqiang | 16aadb0 | 2024-04-12 15:47:13 +0800 | [diff] [blame] | 104 | if(mbtk_ready_status != MBTK_READY_INIT) |
| 105 | { |
| 106 | LOGE("[SDK_READY] sdk has check."); |
| 107 | return MBTK_RESULT_FAIL; |
| 108 | } |
| 109 | |
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 110 | #ifdef MBTK_DUMP_SUPPORT |
| 111 | mbtk_debug_open(NULL, TRUE); |
| 112 | #endif |
| 113 | |
wangyouqiang | 16aadb0 | 2024-04-12 15:47:13 +0800 | [diff] [blame] | 114 | 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.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 123 | |
wangyouqiang | 16aadb0 | 2024-04-12 15:47:13 +0800 | [diff] [blame] | 124 | 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 |