xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 1 | |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <errno.h> |
| 5 | #include <string.h> |
| 6 | #include <sys/types.h> |
| 7 | #include <sys/socket.h> |
| 8 | #include <sys/un.h> |
| 9 | #include <unistd.h> |
| 10 | #include <dlfcn.h> |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 11 | #include <pthread.h> |
| 12 | #include <stdbool.h> |
| 13 | #include <time.h> |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 14 | |
| 15 | #define LOG_TAG "libautosuspend" |
| 16 | |
| 17 | // #include <liblog/lynq_deflog.h> |
| 18 | #include <log/log.h> |
| 19 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 20 | #define SERVER_CMD_PATH "/tmp/autosuspend.cmd.server" |
| 21 | #define SERVER_DATA_PATH "/tmp/autosuspend.data.server" |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 22 | // #define CLIENT_PATH "/tmp/autosuspend.client" |
| 23 | |
| 24 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 25 | static int client_sock_fd; |
| 26 | |
| 27 | static int client_data_sock_fd; |
| 28 | |
| 29 | static bool libautosuspend_inited; |
| 30 | |
jb.qi | 5fb6758 | 2023-02-09 00:12:59 -0800 | [diff] [blame] | 31 | bool feedback_flag = true; //add for after sleeping once calling lynq_wailt_wakeup_event does not return sleep time |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 32 | // static bool libautosuspend_enabled; |
| 33 | |
| 34 | // static pthread_mutex_t get_feedback_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 35 | |
| 36 | // static pthread_cond_t get_feedback_cond = PTHREAD_COND_INITIALIZER; |
| 37 | |
| 38 | static pthread_mutex_t client_fd_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 39 | |
| 40 | static pthread_mutex_t client_data_fd_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 41 | |
| 42 | static pthread_mutex_t feedback_got_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 43 | |
| 44 | static pthread_cond_t feedback_got_cond = PTHREAD_COND_INITIALIZER; |
| 45 | |
| 46 | struct time_info_t |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 47 | { |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 48 | long sleep_start_time; |
| 49 | long wakeup_time; |
| 50 | }; |
| 51 | |
| 52 | static struct time_info_t time_info_client; |
| 53 | |
| 54 | static ssize_t Read(int fd, void *ptr, size_t nbytes) |
| 55 | { |
| 56 | ssize_t n; |
| 57 | |
| 58 | while((n = read(fd, ptr, nbytes)) == -1) |
| 59 | { |
| 60 | //printf("READ,%d\n",fd); |
| 61 | if (errno == EINTR) |
| 62 | { |
| 63 | ALOGI("read error eintr\n"); |
| 64 | continue; |
| 65 | } |
| 66 | else if(errno == EAGAIN || errno == EWOULDBLOCK) |
| 67 | { |
| 68 | ALOGI("read time out\n"); |
| 69 | return -2; |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | ALOGI("read error\n"); |
| 74 | return -1; |
| 75 | } |
| 76 | } |
| 77 | //sleep(2); |
| 78 | //printf("READ1,%d\n", fd); |
| 79 | return n; |
| 80 | } |
| 81 | |
| 82 | static ssize_t Write(int fd, const void *ptr, size_t nbytes) |
| 83 | { |
| 84 | ssize_t n; |
| 85 | |
| 86 | while((n = write(fd, ptr, nbytes)) == -1) |
| 87 | { |
| 88 | if (errno == EINTR) |
| 89 | continue; |
| 90 | else if(errno == EPIPE) |
| 91 | { |
| 92 | ALOGI("write error epipe\n"); |
| 93 | return -1; |
| 94 | } |
| 95 | else |
| 96 | return -1; |
| 97 | } |
| 98 | return n; |
| 99 | } |
| 100 | |
| 101 | static int Close(int fd) |
| 102 | { |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 103 | if (close(fd) == -1) |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 104 | { |
| 105 | ALOGI("Close error\n"); |
| 106 | return -1; |
| 107 | } |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static int connect_to_server(int *cfd, char *client_path, char *server_path) |
| 112 | { |
| 113 | int rc; |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 114 | struct sockaddr_un server_sockaddr; |
| 115 | struct sockaddr_un client_sockaddr; |
| 116 | |
| 117 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 118 | ALOGI("Start bind and connect to the service.\n"); |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 119 | |
| 120 | /**************************************/ |
| 121 | /* Create a UNIX domain stream socket */ |
| 122 | /**************************************/ |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 123 | *cfd = socket(AF_UNIX, SOCK_STREAM, 0); |
| 124 | if (*cfd == -1) { |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 125 | ALOGI("SOCKET ERROR "); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 126 | return -1; |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /***************************************/ |
| 130 | /* Set up the UNIX sockaddr structure */ |
| 131 | /* by using AF_UNIX for the family and */ |
| 132 | /* giving it a filepath to bind to. */ |
| 133 | /* */ |
| 134 | /* Unlink the file so the bind will */ |
| 135 | /* succeed, then bind to that file. */ |
| 136 | /***************************************/ |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 137 | client_sockaddr.sun_family = AF_UNIX; |
| 138 | strcpy(client_sockaddr.sun_path, client_path); |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 139 | |
| 140 | unlink(client_sockaddr.sun_path); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 141 | |
| 142 | rc = bind(*cfd, (struct sockaddr *) &client_sockaddr, sizeof(client_sockaddr)); |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 143 | if (rc == -1){ |
| 144 | ALOGI("BIND ERROR "); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 145 | Close(*cfd); |
| 146 | return -1; |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /***************************************/ |
| 150 | /* Set up the UNIX sockaddr structure */ |
| 151 | /* for the server socket and connect */ |
| 152 | /* to it. */ |
| 153 | /***************************************/ |
| 154 | server_sockaddr.sun_family = AF_UNIX; |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 155 | |
| 156 | strcpy(server_sockaddr.sun_path, server_path); |
| 157 | |
| 158 | rc = connect(*cfd, (struct sockaddr *) &server_sockaddr, sizeof(client_sockaddr)); |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 159 | if(rc == -1){ |
| 160 | ALOGI("CONNECT ERROR "); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 161 | Close(*cfd); |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 162 | return -3; |
| 163 | } |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 164 | |
| 165 | return 0; |
| 166 | |
| 167 | } |
| 168 | |
| 169 | static void *deal_get_feedback(void *sockfd) |
| 170 | { |
| 171 | int rc; |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 172 | int ret; |
| 173 | int num[10]={5,5,10,10,30,30,60,60,90,90}; |
| 174 | int i = 0; |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 175 | while (1) |
| 176 | { |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 177 | |
| 178 | ALOGI("start get feedback from the service.\n"); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 179 | pthread_mutex_lock(&feedback_got_mutex); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 180 | memset(&time_info_client,0,sizeof(struct time_info_t)); |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 181 | rc = Read(client_data_sock_fd,&time_info_client,sizeof(struct time_info_t)); |
| 182 | ALOGI("deal_get_feedback: rc=%d, client_data_sock_fd=%d.\n", rc, client_data_sock_fd); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 183 | if(rc == -1) |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 184 | { |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 185 | ALOGI("client read wakeup_feedback struct fail.\n"); |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 186 | Close(client_data_sock_fd); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 187 | pthread_mutex_unlock(&feedback_got_mutex); |
| 188 | break ; |
| 189 | } |
| 190 | else if(rc == -2) |
| 191 | { |
| 192 | ALOGI("client read wakeup_feedback struct timeout.\n"); |
| 193 | pthread_mutex_unlock(&feedback_got_mutex); |
| 194 | continue; |
| 195 | } |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 196 | else if(rc == 0) |
| 197 | { |
| 198 | if(i<10) |
| 199 | { |
| 200 | sleep(num[i]); |
| 201 | } |
| 202 | else |
| 203 | { |
| 204 | sleep(120); |
| 205 | } |
| 206 | i++; |
| 207 | system("rm -rf /tmp/*data.client"); |
| 208 | system("rm -rf /tmp/*cmd.client"); |
| 209 | ret = lynq_autosleep_retry(); |
| 210 | if(ret > 0) |
| 211 | { |
| 212 | ALOGI("lynq autosuspend retry success\n"); |
| 213 | i = 0; |
| 214 | } |
| 215 | pthread_mutex_unlock(&feedback_got_mutex); |
| 216 | continue; |
| 217 | } |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 218 | |
| 219 | ALOGI("system sleep_start timestamps : %ld ms\n",time_info_client.sleep_start_time); |
| 220 | ALOGI("system wakeup timestamps : %ld ms\n",time_info_client.wakeup_time); |
| 221 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 222 | |
| 223 | pthread_mutex_unlock(&feedback_got_mutex); |
jb.qi | dd9c989 | 2022-09-15 00:48:16 -0700 | [diff] [blame] | 224 | usleep(10000); //给libautosuspend_get_feedback函数时间进入wait,不可删除,但可以减少 |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 225 | pthread_cond_broadcast(&feedback_got_cond); |
jb.qi | dd9c989 | 2022-09-15 00:48:16 -0700 | [diff] [blame] | 226 | usleep(10000); //希望多给libautosuspend_get_feedback函数拿到锁的机会,不可删除,但可以减少 |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 227 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 228 | } |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 229 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | |
| 233 | static int libautosuspend_init() |
| 234 | { |
| 235 | if (libautosuspend_inited) |
| 236 | { |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | ALOGI("Start libautosuspend_init.\n"); |
| 241 | |
| 242 | char client_cmd_path[40]; |
| 243 | char client_data_path[40]; |
| 244 | |
| 245 | |
| 246 | sprintf(client_cmd_path,"/tmp/autosuspend.%d.cmd.client",(int)getpid()); |
| 247 | sprintf(client_data_path,"/tmp/autosuspend.%d.data.client",(int)getpid()); |
| 248 | |
| 249 | pthread_mutex_lock(&client_fd_mutex); |
| 250 | |
| 251 | if(connect_to_server(&client_sock_fd,client_cmd_path,SERVER_CMD_PATH) < 0) |
| 252 | { |
| 253 | ALOGI("cmd channel connect error.\n"); |
| 254 | pthread_mutex_unlock(&client_fd_mutex); |
| 255 | return -1; |
| 256 | } |
| 257 | |
| 258 | if(connect_to_server(&client_data_sock_fd,client_data_path,SERVER_DATA_PATH) < 0) |
| 259 | { |
| 260 | ALOGI("data channel connect error.\n"); |
| 261 | pthread_mutex_unlock(&client_fd_mutex); |
| 262 | return -1; |
| 263 | } |
| 264 | |
| 265 | pthread_t feedback_tid; |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 266 | pthread_create(&feedback_tid,NULL,deal_get_feedback,NULL); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 267 | pthread_detach(feedback_tid); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 268 | libautosuspend_inited = true; |
| 269 | |
| 270 | pthread_mutex_unlock(&client_fd_mutex); |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 271 | |
| 272 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 273 | return 0; |
| 274 | |
| 275 | } |
| 276 | |
| 277 | static int send_cmd(char * value,int len) |
| 278 | { |
| 279 | int rc; |
| 280 | |
| 281 | if(value == NULL) |
| 282 | { |
| 283 | return -1; |
| 284 | } |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 285 | |
| 286 | /************************************/ |
| 287 | /* Copy the data to the buffer and */ |
| 288 | /* send it to the server socket. */ |
| 289 | /************************************/ |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 290 | // strcpy(buf, DATA); |
| 291 | |
| 292 | ALOGI("Sending data...\n"); |
| 293 | rc = send(client_sock_fd, value, len, 0); |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 294 | if (rc == -1) { |
| 295 | ALOGI("SEND ERROR "); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 296 | Close(client_sock_fd); |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 297 | return -2; |
| 298 | } |
| 299 | else { |
| 300 | ALOGI("Data sent: %s\n",value); |
| 301 | } |
| 302 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 303 | // Close(client_sock); |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 304 | |
| 305 | return rc; |
| 306 | |
| 307 | } |
| 308 | |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 309 | static int libautosuspend_reconnect(void) |
| 310 | { |
| 311 | |
| 312 | |
| 313 | ALOGI("Start libautosuspend_init.\n"); |
| 314 | |
| 315 | char client_cmd_path[40]; |
| 316 | char client_data_path[40]; |
| 317 | |
| 318 | sprintf(client_cmd_path,"/tmp/autosuspend.%d.cmd.client",(int)getpid()); |
| 319 | sprintf(client_data_path,"/tmp/autosuspend.%d.data.client",(int)getpid()); |
| 320 | |
| 321 | |
| 322 | pthread_mutex_lock(&client_fd_mutex); |
| 323 | |
| 324 | if(connect_to_server(&client_sock_fd,client_cmd_path,SERVER_CMD_PATH) < 0) |
| 325 | { |
| 326 | ALOGI("cmd channel connect error.\n"); |
| 327 | pthread_mutex_unlock(&client_fd_mutex); |
| 328 | return -1; |
| 329 | } |
| 330 | |
| 331 | if(connect_to_server(&client_data_sock_fd,client_data_path,SERVER_DATA_PATH) < 0) |
| 332 | { |
| 333 | ALOGI("data channel connect error.\n"); |
| 334 | pthread_mutex_unlock(&client_fd_mutex); |
| 335 | return -1; |
| 336 | } |
| 337 | |
| 338 | pthread_mutex_unlock(&client_fd_mutex); |
| 339 | |
| 340 | return 0; |
| 341 | |
| 342 | } |
| 343 | |
| 344 | |
| 345 | int lynq_autosleep_retry(void) |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 346 | { |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 347 | char value[15]="enable"; |
| 348 | char res[15]; |
| 349 | |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 350 | if(libautosuspend_reconnect() != 0) |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 351 | { |
| 352 | return -1; |
| 353 | } |
| 354 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 355 | pthread_mutex_lock(&client_fd_mutex); |
| 356 | |
| 357 | int rc = send_cmd(value,strlen(value)); |
| 358 | if(rc < 0) |
| 359 | { |
| 360 | ALOGI("libautosuspend send enable cmd fail.\n"); |
| 361 | pthread_mutex_unlock(&client_fd_mutex); |
| 362 | return -1; |
| 363 | } |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 364 | pthread_mutex_unlock(&client_fd_mutex); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 365 | |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 366 | return 1; |
| 367 | |
| 368 | } |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 369 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 370 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 371 | |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 372 | int lynq_autosleep_enable(void) |
| 373 | { |
| 374 | char value[15]="enable"; |
| 375 | char res[15]; |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 376 | |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 377 | if(libautosuspend_init() != 0) |
| 378 | { |
| 379 | return -1; |
| 380 | } |
| 381 | |
| 382 | pthread_mutex_lock(&client_fd_mutex); |
| 383 | |
| 384 | int rc = send_cmd(value,strlen(value)); |
| 385 | if(rc < 0) |
| 386 | { |
| 387 | ALOGI("libautosuspend send enable cmd fail.\n"); |
| 388 | pthread_mutex_unlock(&client_fd_mutex); |
| 389 | return -1; |
| 390 | } |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 391 | pthread_mutex_unlock(&client_fd_mutex); |
| 392 | |
xj | 0bb28dc | 2022-05-10 08:22:22 +0800 | [diff] [blame] | 393 | return 1; |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 394 | |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | int lynq_autosleep_disable(void) |
| 398 | { |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 399 | char value[15]="disable"; |
| 400 | char res[15]; |
| 401 | |
| 402 | if(libautosuspend_init() != 0) |
| 403 | { |
| 404 | return -1; |
| 405 | } |
| 406 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 407 | |
| 408 | pthread_mutex_lock(&client_fd_mutex); |
| 409 | |
| 410 | int rc = send_cmd(value,strlen(value)); |
| 411 | if(rc < 0) |
| 412 | { |
| 413 | ALOGI("libautosuspend send disable cmd fail.\n"); |
| 414 | pthread_mutex_unlock(&client_fd_mutex); |
| 415 | return -1; |
| 416 | } |
| 417 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 418 | pthread_mutex_unlock(&client_fd_mutex); |
| 419 | |
xj | 0bb28dc | 2022-05-10 08:22:22 +0800 | [diff] [blame] | 420 | return 1; |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 421 | |
| 422 | } |
| 423 | |
| 424 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 425 | |
xj | da4933f | 2022-05-09 10:34:43 +0800 | [diff] [blame] | 426 | int libautosuspend_get_feedback(struct time_info_t *time_info) |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 427 | { |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 428 | |
| 429 | ALOGI("start get feedback from the service.\n"); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 430 | memset(time_info,0,sizeof(struct time_info_t)); |
| 431 | |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 432 | |
| 433 | ALOGI("libautosuspend_get_feedback wait.\n"); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 434 | pthread_mutex_lock(&feedback_got_mutex); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 435 | pthread_cond_wait(&feedback_got_cond,&feedback_got_mutex); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 436 | memcpy(time_info,&time_info_client,sizeof(struct time_info_t)); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 437 | ALOGI("libautosuspend_get_feedback success.\n"); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 438 | pthread_mutex_unlock(&feedback_got_mutex); |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 439 | |
| 440 | return 0; |
| 441 | |
| 442 | } |
| 443 | |
| 444 | |
xj | da4933f | 2022-05-09 10:34:43 +0800 | [diff] [blame] | 445 | int lynq_wait_wakeup_event(long *sleep_start_time, long * wakeup_time) |
| 446 | { |
jb.qi | e82adab | 2023-12-10 17:19:08 -0800 | [diff] [blame] | 447 | int *socket_timeout = NULL; |
| 448 | struct time_info_t time_info; |
| 449 | int ret = 0; |
| 450 | /*add for after sleeping once calling lynq_wailt_wakeup_event does not return sleep time start*/ |
| 451 | if(feedback_flag == true) |
| 452 | { |
| 453 | if(libautosuspend_init() != 0) |
| 454 | { |
| 455 | return -1; |
| 456 | } |
| 457 | } |
| 458 | feedback_flag = false; |
| 459 | /*add for after sleeping once calling lynq_wailt_wakeup_event does not return sleep time end*/ |
| 460 | memset(&time_info,0,sizeof(struct time_info_t)); |
| 461 | if(sleep_start_time == NULL || wakeup_time == NULL ) |
| 462 | { |
| 463 | ALOGI("lynq_wait_wakeup_event input errors.\n"); |
| 464 | return -1; |
| 465 | } |
| 466 | ret=libautosuspend_get_feedback(&time_info); |
| 467 | if(ret == 0) |
| 468 | { |
| 469 | *sleep_start_time = time_info.sleep_start_time; |
| 470 | *wakeup_time = time_info.wakeup_time; |
| 471 | return 0; |
| 472 | } |
| 473 | else |
| 474 | { |
| 475 | return -1; |
| 476 | } |
xj | da4933f | 2022-05-09 10:34:43 +0800 | [diff] [blame] | 477 | |
| 478 | |
| 479 | } |
xj | ac56394 | 2022-05-04 16:50:24 +0800 | [diff] [blame] | 480 | |
xj | d5ccac0 | 2022-04-02 15:41:13 +0800 | [diff] [blame] | 481 | |