emulator-fingerprint: Exit listener thread on HAL close

Note: This CL comes from Yu Ning <yu.ning@intel.com>

The current fingerprint HAL module for the emulator cannot be closed,
because fingerprint_close() always gets stuck waiting for the listener
thread to finish execution. Meanwhile, the listener thread is blocked on
qemud_channel_recv(), which does not return unless the host (QEMU) sends
something through the qemud channel.

This leads to the following bug:


It is worth noting, though, that fingerprint_close() does try to unblock
qemud_channel_recv() by asynchronously closing the qemud channel, which
is backed by goldfish pipe. Unfortunately, that does not work, probably
because goldfish pipe does not automatically make pending I/O operations
return after closing a channel.

Any proper solution should probably poll the qemud channel before the
call to qemud_channel_recv(), and make sure the polling can be canceled,
allowing the listener thread to terminate gracefully.

Setting a timeout for poll() is straightforward to implement. Another
(slightly better) mechanism that enables instant interruption of the
polling of the qemud channel has also been implemented and tested, but
is more complicated and would add 200+ lines to fingerprint.c.

Therefore, take the simple, timeout-based approach for now, and maybe
revisit this issue in the future.

Change-Id: I02aa1f631d4ee651fe1ac7fb338076beaedddc40
1 file changed