aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaliy Tomin <highwaystar.ru@gmail.com>2016-10-10 22:44:06 +0800
committerAnik1199 <anik9280@gmail.com>2016-10-12 13:23:04 +0600
commit369dd6e3d0db5429140bc3ca3e524f09f31f38e7 (patch)
treec11bb7f2f1ae3720b77b92a3b77ece88f4bcaf16
parent847571555507be8c0034349fad62e60f6a645b2e (diff)
ido: fpc: Use blocking poll to prevent unneeded wakelocksHEADmm6.0
* Now authentication thread stays in poll until finger pressed to scanner * To cancel blocking poll special control pipe mechanism used, it is implemented in cancel_poll() and called on fingerprint_cancel() * This changes reduce wakelock number from thousands (1 per/second) to 1-2 per unlock. This should lead to less battery consume. Change-Id: Id0bfa13491621afa2327900046f96ceb01fce660
-rw-r--r--fingerprint/fingerprint.c19
-rw-r--r--fingerprint/fpc_imp.c72
-rw-r--r--fingerprint/fpc_imp.h1
3 files changed, 77 insertions, 15 deletions
diff --git a/fingerprint/fingerprint.c b/fingerprint/fingerprint.c
index 7246dad..ad5d067 100644
--- a/fingerprint/fingerprint.c
+++ b/fingerprint/fingerprint.c
@@ -75,11 +75,6 @@ void *enroll_thread_loop()
callback(&msg);
remaining_touches--;
- while (fpc_capture_image() == 6 ) {
- //wait finger up (not working good, maybe need state machine)
- usleep(5000);
- }
-
}
@@ -127,6 +122,7 @@ void *enroll_thread_loop()
fpc_enroll_end();
ALOGI("%s : finishing",__func__);
+
pthread_mutex_lock(&lock);
auth_thread_running = false;
pthread_mutex_unlock(&lock);
@@ -201,10 +197,9 @@ void *auth_thread_loop()
}
pthread_mutex_unlock(&lock);
}
-
fpc_auth_end();
ALOGI("%s : finishing",__func__);
-
+
pthread_mutex_lock(&lock);
auth_thread_running = false;
pthread_mutex_unlock(&lock);
@@ -213,6 +208,7 @@ void *auth_thread_loop()
static int fingerprint_close(hw_device_t *dev)
{
+ ALOGI("%s",__func__);
fpc_close();
if (dev) {
free(dev);
@@ -238,12 +234,11 @@ static int fingerprint_enroll(struct fingerprint_device __unused *dev,
uint32_t __unused gid,
uint32_t __unused timeout_sec)
{
-
-
+
pthread_mutex_lock(&lock);
bool thread_running = auth_thread_running;
pthread_mutex_unlock(&lock);
-
+
if (thread_running) {
ALOGE("%s : Error, thread already running\n", __func__);
return -1;
@@ -288,7 +283,6 @@ static uint64_t fingerprint_get_auth_id(struct fingerprint_device __unused *dev)
static int fingerprint_cancel(struct fingerprint_device __unused *dev)
{
ALOGI("%s : +",__func__);
-
pthread_mutex_lock(&lock);
bool thread_running = auth_thread_running;
pthread_mutex_unlock(&lock);
@@ -299,10 +293,11 @@ static int fingerprint_cancel(struct fingerprint_device __unused *dev)
return 0;
}
+
pthread_mutex_lock(&lock);
auth_thread_running = false;
pthread_mutex_unlock(&lock);
-
+ cancel_poll();
ALOGI("%s : join running thread",__func__);
pthread_join(thread, NULL);
diff --git a/fingerprint/fpc_imp.c b/fingerprint/fpc_imp.c
index 2ddd064..52413f2 100644
--- a/fingerprint/fpc_imp.c
+++ b/fingerprint/fpc_imp.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
+#include <pthread.h>
#define LOG_TAG "FPC IMP"
#define LOG_NDEBUG 0
@@ -31,6 +32,10 @@
#define SPI_WAKE_FILE "/sys/devices/soc.0/fpc1020.70/wakeup_enable"
#define SPI_IRQ_FILE "/sys/devices/soc.0/fpc1020.70/irq"
+int control_pipe[2];
+bool do_not_poll = false;
+pthread_mutex_t lock_pipe;
+
static int qsee_load_trustlet(struct QSEECom_handle **clnt_handle,
const char *path, const char *fname,
uint32_t sb_size)
@@ -95,7 +100,45 @@ int sys_fs_irq_poll(char *path)
read(pollfds[0].fd, &dummybuf, 1);
pollfds[0].events = POLLPRI;
- result = poll(pollfds, 1, 1000);
+
+ pthread_mutex_lock(&lock_pipe);
+
+ if (do_not_poll) {
+ ALOGE("Flag to skip next poll set\n");
+ do_not_poll = false;
+ pthread_mutex_unlock(&lock_pipe);
+ return -1 ;
+ }
+ if(pipe(control_pipe) == -1 ) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGE("Error opening control pipe %s\n", buf);
+ pthread_mutex_unlock(&lock_pipe);
+ return -1 ;
+ }
+ pthread_mutex_unlock(&lock_pipe);
+
+ pollfds[1].fd=control_pipe[0];
+ pollfds[1].events = POLLIN;
+
+ result = poll(pollfds, 2, -1);
+ if (pollfds[1].revents & POLLIN && result > 0) {
+ read(pollfds[1].fd, &dummybuf, 1);
+ ALOGE("Poll canceled trough pipe%s\n", buf);
+ close(control_pipe[0]);
+ close(control_pipe[1]);
+ pthread_mutex_lock(&lock_pipe);
+ control_pipe[0] = -1;
+ control_pipe[1] = -1;
+ pthread_mutex_unlock(&lock_pipe);
+ close(pollfds[0].fd);
+ return -1;
+ }
+ pthread_mutex_lock(&lock_pipe);
+ close(control_pipe[0]);
+ close(control_pipe[1]);
+ control_pipe[0] = -1;
+ control_pipe[1] = -1;
+ pthread_mutex_unlock(&lock_pipe);
switch (result) {
case 0:
@@ -223,6 +266,26 @@ uint64_t get_int64_command(uint32_t cmd, uint32_t param, struct QSEECom_handle *
}
+void cancel_poll()
+{
+
+ ALOGE("Enter to cancel polling\n");
+ char* cancel_buf[1];
+ memset(cancel_buf, 0xFA, 1);
+
+
+ pthread_mutex_lock(&lock_pipe);
+ do_not_poll = true;
+ if (control_pipe[1] >= 0 ){
+ ALOGE("Trying to cancel polling\n");
+ write(control_pipe[1], cancel_buf, 1);
+ } else {
+
+ ALOGE("Control pipe not inialised\n");
+ }
+ pthread_mutex_unlock(&lock_pipe);
+}
+
uint64_t fpc_load_db_id()
{
return 0;
@@ -269,7 +332,7 @@ int fpc_wait_for_finger()
ALOGD("%s : SPI_IRQ_FILE poll\n", __func__);
if (sys_fs_irq_poll(SPI_IRQ_FILE) < 0) {
sysfs_write(SPI_CLK_FILE,"1");
-// sysfs_write(SPI_WAKE_FILE,"disable");
+ sysfs_write(SPI_WAKE_FILE,"disable");
return 1;
}
@@ -278,7 +341,7 @@ int fpc_wait_for_finger()
if (finger_state == 6)
{
- return finger_state;
+ return 1;
}
@@ -666,6 +729,9 @@ int fpc_close()
int fpc_init()
{
int ret = 0;
+ control_pipe[0] = -1;
+ control_pipe[1] = -1;
+
ALOGE("INIT FPC TZ APP\n");
diff --git a/fingerprint/fpc_imp.h b/fingerprint/fpc_imp.h
index 6b025aa..5d14e61 100644
--- a/fingerprint/fpc_imp.h
+++ b/fingerprint/fpc_imp.h
@@ -45,4 +45,5 @@ uint32_t fpc_load_user_db(char* path); //load user DB into TZ app from storage
uint32_t fpc_store_user_db(uint32_t length, char* path); //store running TZ db
int fpc_close(); //close this implementation
int fpc_init(); //init sensor
+void cancel_poll();
#endif