Avoid multiple extraction of thumbnails

When inserting a new memory card containing images, or taking a camera
picture, several requests for a thumbnail for the same picture are made.
At the time the requests are made, no thumbnail exists, so each of the
requests result in the full image being decoded and encoded to a
thumbnail, an operation taking about 100ms per thumbnail. Fixing this
cuts times for image thumbnails in half. Also improves Camera
shot-to-shot times.

When a thumbnail request is completed, scan the queue for identical
requests, and update those requests to avoid having to decode the same
image several times.

Change-Id: I53d720779925de882b0e2f080b0b87ec318e08a9
Merge "Avoid multiple extraction of thumbnails"
Fix possible deadlock in media provider

Because of the execution sequences below,
receiving ACTION_MEDIA_EJECT intent during bulk inserting
can lead to media provider deadlock.

bulkInsert()
-> db.beginTransaction()
-> insertInternal()
-> getDatabaseForUri()
-> synchronized(mDatabases)

mUnmountReceiver.onReceive()
-> synchronized(mDatabases)
-> db.update()

beginTransaction() blocks any other operations on the database
until endTransaction() is called.
Therefore, db.update() method can be blocked in the synchronized block
and bulk inserting also can be blocked simultaneously to enter
the synchronized block.

This patch resolves the problem above by restricting the scope
of the synchronized block in mUnmountReceiver.

Change-Id: Ibb65ac82ea389145a6a3e44942928b7548c53b22
Signed-off-by: Sangkyu Lee <sk82.lee@lge.com>
Merge "Fix possible deadlock in media provider"
Merge remote-tracking branch 'upstream/master' into master-alt