要实现的功能:在android Framework层被裁剪掉的情况下,实现监听长按的物理power按键,实现长按3秒后关机功能;
思路:使用event epoll,非阻塞式IO操作,同时避免无差别轮询,做到避免忙轮和无差别轮询提高效率;
要用到的epoll函数:epoll_create(EPOLL_SIZE_HINT);
epoll_wait(mEpollFd, mPendingEventItems, 8, -1);
epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, &eventItem)
epoll_ctl(mEpollFd, EPOLL_CTL_DEL, fd, &eventItem);
下面是实现的过程:int main(int argc, char *argv[])
{
ALOGI("robot test robot power");
struct itimerval old_value;
int tap_power_time = 0;
int tap_power_type = 0;
int tap_power_code = 0;
int tap_power_value = 0;
struct itimerval tick;
int mEpollFd;
const int EPOLL_SIZE_HINT = 8;
const char* DEV_INPUT = "/dev/input/event1";
struct epoll_event mPendingEventItems[8];