Prevent onImageAvailable from being called on stale listeners
ImageReader queues up calls to OnImageAvailableListener#onImageAvailable (one for each frame) by wrapping them in Runnables and passing the Runnables to an Executor, which in turn executes Runnables in order. Before queuing the Runnable, ImageReader reads the value of listener and passes a reference to the listener that is current at the time of queueing to the Runnable. This reference is used when calling onImageAvailable. If the listener changes between when a Runnable is queued and when the Runnable is executed, it is possible for the Runnable to call into a stale listener. This CL replaces the mutex used to guard the state of ImageReader with a StampedLock behaving as a Read-Write Lock. The Runnables wrapping calls to OnImageAvailableListener#onImageAvailable grab a read lock and calls the onImageAvailable method of the listener referenced by ImageReader at the time of Runnable's execution. Any call to modify the listener grabs the write lock. Bug: 204438677 Test: Existing CTS tests pass Change-Id: I7b11243962595e8c41912a483a80ecd8d3c3e945
Loading
Please register or sign in to comment