blob: 91a8e285eca5da64283dec331f3753cbf6aa928a [file] [log] [blame]
#include "lynq-qser-autosuspend.h"
#include <stdio.h>
#include <unistd.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/epoll.h>
#include <linux/input.h>
#include "mbtk_type.h"
#include "mbtk_log.h"
#include "mbtk_power.h"
#include "mbtk_lpm.h"
#include "mbtk_sleep.h"
#include "mbtk_utils.h"
#include "mbtk_ril_api.h"
static bool call_Off = FALSE;
static bool nw_off = FALSE;
static bool sms_off = FALSE;
static bool data_off = FALSE;
static mbtk_ril_handle* whitelist_info_handle = NULL;
int qser_autosuspend_enable(char enable)
{
int ret = 0;
ret = mbtk_autosuspend_enable(enable);
if (ret == -1)
{
LOGE("qser_autosuspend_enable is error");
}
return ret;
}
int qser_wakelock_create(const char* name , size_t len)
{
int ret = 0;
ret = mbtk_wakelock_create(name, len);
if (ret == -1)
{
LOGE("qser_wakelock_create is error");
}
return ret;
}
int qser_wakelock_lock(int fd)
{
int ret = 0;
ret = mbtk_wakelock_lock(fd);
if (ret == -1)
{
LOGE("qser_wakelock_lock is error");
}
return ret;
}
int qser_wakelock_unlock(int fd)
{
int ret = 0;
ret = mbtk_wakelock_unlock(fd);
if (ret == -1)
{
LOGE("qser_wakelock_unlock is error");
}
return ret;
}
int qser_wakelock_destroy(int fd)
{
int ret = 0;
ret = mbtk_wakelock_destroy(fd);
if (ret == -1)
{
LOGE("qser_wakelock_destroy is error");
}
return ret;
}
int qser_lpm_init(qser_lpm_Handler_t qser_lpm_handler, qser_pm_cfg_t *qser_lpm_cfg)
{
UNUSED(qser_lpm_cfg);
if(mbtk_lpm_init((mbtk_lpm_handler_t)qser_lpm_handler))
{
LOGE("qser_lpm_init fail");
return -1;
}
return 0;
}
int qser_lpm_deinit(void)
{
mbtk_lpm_deinit();
return 0;
}
/*
例如AT*POWERIND=31,就相当于设置NETWORK、SIM、SMS、CS CALL、PS DATA变化时都不主动上报,
其中PS DATA目前暂时不支持,只是保留了这个标志位;
AP power state: 1~31 means suspend, bitmap: bit0 - NETWORK;bit1 - SIM;bit2 - SMS;bit3 - CS CALL;bit4 - PS DATA
0 means resume all.
目标文件"/system/etc/powerind"
如果bit0-bit3都配置可以采用的值是1-15,如果是当前采用NETWORK SMS CALL 则值的取值是 1 4 8 5 9 12 13
*/
int qser_whitelist_set(char* whitelish)
{
//UNUSED(whitelish);
uint32 on = 0;
int call_t, nw_t, data_t, sms_t, tmp;
int len = strlen(whitelish);
if (len != 4)
{
LOGE("whitelish num error num=[%d]",len);
return -1;
}
tmp = atoi(whitelish);
call_t = tmp/1000;
nw_t = tmp%1000/100;
data_t = tmp%1000%100/10;
sms_t = tmp%1000%100%10;
if (call_t == 1)
call_Off = TRUE;
else
call_Off = FALSE;
if (nw_t == 1)
nw_off = TRUE;
else
nw_off = FALSE;
if (data_t == 1)
data_off = TRUE;
else
data_off = FALSE;
if (sms_t == 1)
sms_off = TRUE;
else
sms_off = FALSE;
if (call_Off == FALSE && nw_off == FALSE && data_off == FALSE && sms_off == FALSE)
{
on = 29;//0000的情况,所有上报源都屏蔽,SIM的上报会一直被包含在内
}
else
{
if (call_Off == TRUE)
call_t = 8;
else
call_t = 0;
if (nw_off == TRUE)
nw_t = 1;
else
nw_t = 0;
if (data_off == TRUE)
data_t = 16;
else
data_t = 0;
if (sms_off == TRUE)
sms_t = 4;
else
sms_t = 0;
on = 29 - (call_t + nw_t + data_t + sms_t);//SIM的上报会一直被包含在内
}
if(whitelist_info_handle == NULL)
{
whitelist_info_handle = mbtk_ril_open(MBTK_AT_PORT_DEF);
if(whitelist_info_handle)
{
LOGI("creat whitelist_info_handle is success");
}
else
{
LOGE("creat whitelist_info_handle is fail");
return -1;
}
}
int err = mbtk_wakeup_state_set(whitelist_info_handle, on);
if(err)
{
LOGE("whitelist_info_handle Error : %d", err);
return -1;
}
if(whitelist_info_handle != NULL)
{
int ret_ril = mbtk_ril_close(MBTK_AT_PORT_DEF);
if (ret_ril == MBTK_RIL_ERR_SUCCESS)
{
LOGI("deinit whitelist_info_handle is succuess");
whitelist_info_handle = NULL;
}
else
{
LOGE("deinit whitelist_info_handle is error(%d)",ret_ril);
return -1;
}
}
return 0;
}
int qser_whitelist_get(char* whitelish)
{
//UNUSED(whitelish);
char list[10] = {0};
int get_tmp;
get_tmp = mbtk_powerrind_get();
LOGI(">>>powerrind_get: %d",get_tmp);
//call 8 nw 1 data 16 sms 4 SIM的上报会一直被包含在内
switch(get_tmp)
{
case 0:
sprintf(list, "%d%d%d%d", 1, 1, 1, 1);
break;
case 8:
sprintf(list, "%d%d%d%d", 0, 1, 1, 1);
break;
case 1:
sprintf(list, "%d%d%d%d", 1, 0, 1, 1);
break;
case 16:
sprintf(list, "%d%d%d%d", 1, 1, 0, 1);
break;
case 4:
sprintf(list, "%d%d%d%d", 1, 1, 1, 0);
break;
case 9:
sprintf(list, "%d%d%d%d", 0, 0, 1, 1);
break;
case 24:
sprintf(list, "%d%d%d%d", 0, 1, 0, 1);
break;
case 12:
sprintf(list, "%d%d%d%d", 0, 1, 1, 0);
break;
case 17:
sprintf(list, "%d%d%d%d", 1, 0, 0, 1);
break;
case 5:
sprintf(list, "%d%d%d%d", 1, 0, 1, 0);
break;
case 20:
sprintf(list, "%d%d%d%d", 1, 1, 0, 0);
break;
case 25:
sprintf(list, "%d%d%d%d", 0, 0, 0, 1);
break;
case 13:
sprintf(list, "%d%d%d%d", 0, 0, 1, 0);
break;
case 28:
sprintf(list, "%d%d%d%d", 0, 1, 0, 0);
break;
case 21:
sprintf(list, "%d%d%d%d", 1, 0, 0, 0);
break;
case 29:
sprintf(list, "%d%d%d%d", 0, 0, 0, 0);
break;
default :
LOGE("qser_whitelist_get is error");
return -1;
}
LOGI("whitelist list: %s",list);
strncpy(whitelish, list, strlen(list));
return 0;
}
int qser_suspend_timer_set(int time, mbtk_sleep_callback_func cb)
{
int ret = 0;
ret = mbtk_suspend_timer_set(time, cb);
if(0 > ret)
{
LOGE("qser_suspend_timer_set failed");
}
return ret;
}