• Sangkyu Lee's avatar
    Fix possible deadlock in media provider · 6f520752
    Sangkyu Lee authored
    
    
    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: default avatarSangkyu Lee <sk82.lee@lge.com>
    6f520752
MediaProvider.java 245 KB