blob: 91a8e285eca5da64283dec331f3753cbf6aa928a [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001#include "lynq-qser-autosuspend.h"
2
3#include <stdio.h>
4#include <unistd.h>
5#include <stddef.h>
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <fcntl.h>
9#include <pthread.h>
10#include <string.h>
11#include <stdlib.h>
12#include <errno.h>
13#include <sys/epoll.h>
14#include <linux/input.h>
15
16#include "mbtk_type.h"
17#include "mbtk_log.h"
18#include "mbtk_power.h"
19#include "mbtk_lpm.h"
20#include "mbtk_sleep.h"
21#include "mbtk_utils.h"
22#include "mbtk_ril_api.h"
23
24
25static bool call_Off = FALSE;
26static bool nw_off = FALSE;
27static bool sms_off = FALSE;
28static bool data_off = FALSE;
29
30static mbtk_ril_handle* whitelist_info_handle = NULL;
31
32
33int qser_autosuspend_enable(char enable)
34{
35 int ret = 0;
36
37 ret = mbtk_autosuspend_enable(enable);
38 if (ret == -1)
39 {
40 LOGE("qser_autosuspend_enable is error");
41 }
42
43 return ret;
44}
45
46int qser_wakelock_create(const char* name , size_t len)
47{
48 int ret = 0;
49
50 ret = mbtk_wakelock_create(name, len);
51 if (ret == -1)
52 {
53 LOGE("qser_wakelock_create is error");
54 }
55
56 return ret;
57}
58
59int qser_wakelock_lock(int fd)
60{
61 int ret = 0;
62
63 ret = mbtk_wakelock_lock(fd);
64 if (ret == -1)
65 {
66 LOGE("qser_wakelock_lock is error");
67 }
68
69 return ret;
70}
71
72int qser_wakelock_unlock(int fd)
73{
74 int ret = 0;
75
76 ret = mbtk_wakelock_unlock(fd);
77 if (ret == -1)
78 {
79 LOGE("qser_wakelock_unlock is error");
80 }
81
82 return ret;
83}
84
85int qser_wakelock_destroy(int fd)
86{
87 int ret = 0;
88
89 ret = mbtk_wakelock_destroy(fd);
90 if (ret == -1)
91 {
92 LOGE("qser_wakelock_destroy is error");
93 }
94
95 return ret;
96}
97
98int qser_lpm_init(qser_lpm_Handler_t qser_lpm_handler, qser_pm_cfg_t *qser_lpm_cfg)
99{
100 UNUSED(qser_lpm_cfg);
101
102 if(mbtk_lpm_init((mbtk_lpm_handler_t)qser_lpm_handler))
103 {
104 LOGE("qser_lpm_init fail");
105 return -1;
106 }
107
108 return 0;
109}
110
111int qser_lpm_deinit(void)
112{
113 mbtk_lpm_deinit();
114
115 return 0;
116}
117
118/*
119例如AT*POWERIND=31,就相当于设置NETWORK、SIM、SMS、CS CALL、PS DATA变化时都不主动上报,
120其中PS DATA目前暂时不支持,只是保留了这个标志位;
121AP power state: 1~31 means suspend, bitmap: bit0 - NETWORK;bit1 - SIM;bit2 - SMS;bit3 - CS CALL;bit4 - PS DATA
1220 means resume all.
123目标文件"/system/etc/powerind"
124如果bit0-bit3都配置可以采用的值是1-15,如果是当前采用NETWORK SMS CALL 则值的取值是 1 4 8 5 9 12 13
125
126*/
127
128int qser_whitelist_set(char* whitelish)
129{
130 //UNUSED(whitelish);
131 uint32 on = 0;
132 int call_t, nw_t, data_t, sms_t, tmp;
133
134 int len = strlen(whitelish);
135
136 if (len != 4)
137 {
138 LOGE("whitelish num error num=[%d]",len);
139 return -1;
140 }
141
142 tmp = atoi(whitelish);
143
144 call_t = tmp/1000;
145 nw_t = tmp%1000/100;
146 data_t = tmp%1000%100/10;
147 sms_t = tmp%1000%100%10;
148
149 if (call_t == 1)
150 call_Off = TRUE;
151 else
152 call_Off = FALSE;
153
154 if (nw_t == 1)
155 nw_off = TRUE;
156 else
157 nw_off = FALSE;
158
159 if (data_t == 1)
160 data_off = TRUE;
161 else
162 data_off = FALSE;
163
164 if (sms_t == 1)
165 sms_off = TRUE;
166 else
167 sms_off = FALSE;
168
169 if (call_Off == FALSE && nw_off == FALSE && data_off == FALSE && sms_off == FALSE)
170 {
171 on = 29;//0000的情况,所有上报源都屏蔽,SIM的上报会一直被包含在内
172 }
173 else
174 {
175 if (call_Off == TRUE)
176 call_t = 8;
177 else
178 call_t = 0;
179
180 if (nw_off == TRUE)
181 nw_t = 1;
182 else
183 nw_t = 0;
184
185 if (data_off == TRUE)
186 data_t = 16;
187 else
188 data_t = 0;
189
190 if (sms_off == TRUE)
191 sms_t = 4;
192 else
193 sms_t = 0;
194
195 on = 29 - (call_t + nw_t + data_t + sms_t);//SIM的上报会一直被包含在内
196 }
197
198 if(whitelist_info_handle == NULL)
199 {
200 whitelist_info_handle = mbtk_ril_open(MBTK_AT_PORT_DEF);
201 if(whitelist_info_handle)
202 {
203 LOGI("creat whitelist_info_handle is success");
204 }
205 else
206 {
207 LOGE("creat whitelist_info_handle is fail");
208 return -1;
209 }
210 }
211
212 int err = mbtk_wakeup_state_set(whitelist_info_handle, on);
213 if(err)
214 {
215 LOGE("whitelist_info_handle Error : %d", err);
216 return -1;
217 }
218
219 if(whitelist_info_handle != NULL)
220 {
221 int ret_ril = mbtk_ril_close(MBTK_AT_PORT_DEF);
222 if (ret_ril == MBTK_RIL_ERR_SUCCESS)
223 {
224 LOGI("deinit whitelist_info_handle is succuess");
225 whitelist_info_handle = NULL;
226 }
227 else
228 {
229 LOGE("deinit whitelist_info_handle is error(%d)",ret_ril);
230 return -1;
231 }
232 }
233
234 return 0;
235}
236
237
238int qser_whitelist_get(char* whitelish)
239{
240 //UNUSED(whitelish);
241 char list[10] = {0};
242 int get_tmp;
243
244 get_tmp = mbtk_powerrind_get();
245 LOGI(">>>powerrind_get: %d",get_tmp);
246 //call 8 nw 1 data 16 sms 4 SIM的上报会一直被包含在内
247 switch(get_tmp)
248 {
249 case 0:
250 sprintf(list, "%d%d%d%d", 1, 1, 1, 1);
251 break;
252 case 8:
253 sprintf(list, "%d%d%d%d", 0, 1, 1, 1);
254 break;
255 case 1:
256 sprintf(list, "%d%d%d%d", 1, 0, 1, 1);
257 break;
258 case 16:
259 sprintf(list, "%d%d%d%d", 1, 1, 0, 1);
260 break;
261 case 4:
262 sprintf(list, "%d%d%d%d", 1, 1, 1, 0);
263 break;
264
265 case 9:
266 sprintf(list, "%d%d%d%d", 0, 0, 1, 1);
267 break;
268 case 24:
269 sprintf(list, "%d%d%d%d", 0, 1, 0, 1);
270 break;
271 case 12:
272 sprintf(list, "%d%d%d%d", 0, 1, 1, 0);
273 break;
274 case 17:
275 sprintf(list, "%d%d%d%d", 1, 0, 0, 1);
276 break;
277 case 5:
278 sprintf(list, "%d%d%d%d", 1, 0, 1, 0);
279 break;
280 case 20:
281 sprintf(list, "%d%d%d%d", 1, 1, 0, 0);
282 break;
283
284 case 25:
285 sprintf(list, "%d%d%d%d", 0, 0, 0, 1);
286 break;
287 case 13:
288 sprintf(list, "%d%d%d%d", 0, 0, 1, 0);
289 break;
290 case 28:
291 sprintf(list, "%d%d%d%d", 0, 1, 0, 0);
292 break;
293 case 21:
294 sprintf(list, "%d%d%d%d", 1, 0, 0, 0);
295 break;
296
297 case 29:
298 sprintf(list, "%d%d%d%d", 0, 0, 0, 0);
299 break;
300
301 default :
302 LOGE("qser_whitelist_get is error");
303 return -1;
304 }
305
306 LOGI("whitelist list: %s",list);
307 strncpy(whitelish, list, strlen(list));
308
309 return 0;
310}
311
312
313int qser_suspend_timer_set(int time, mbtk_sleep_callback_func cb)
314{
315 int ret = 0;
316 ret = mbtk_suspend_timer_set(time, cb);
317 if(0 > ret)
318 {
319 LOGE("qser_suspend_timer_set failed");
320 }
321
322
323 return ret;
324}
325
326