MTP + external SD fixes

Squashed commit of the following:

commit 1e3c46ef15b9fa2f072bc7da6dcdfdf7aae1e08b
Merge: e6c6523 4564f44
Author: nuclearmistake <nuclearmistake@gmail.com>
Date:   Tue Jun 25 12:59:11 2013 -0400

    Merge remote-tracking branch 'cm/cm-10.1' into squishme

commit 4564f442456615af434d92523ad5cc82ae2aec01
Merge: 5c18164 0ac6e4e
Author: Steve Kondik <shade@chemlab.org>
Date:   Sun Nov 18 22:33:31 2012 -0800

    Merge branch 'jb-mr1-release' of https://android.googlesource.com/platform/packages/providers/MediaProvider into HEAD

commit 5c181640b6bf16abaec1badf292b1913f3a5b7cb
Author: Pawit Pornkitprasan <p.pawit@gmail.com>
Date:   Sat Jan 21 23:51:55 2012 +0700

    MediaScanner: Don't delete entries of secondary storage on shutdown

    MediaScanner deletes the entries of secondary storage whenever it
    is ejected by the user. However, a shutdown also sends this eject
    events. This patch ignores the eject event if the system is being
    shutdown.

    Patch Set 2: Fix compile error

    Change-Id: I0dfe4bd750c563e99b59ad6e9155b241c3228e0d

commit ef9779b0e3339733c086a758a562581744da8dad
Author: Mike Kasick <mike@kasick.org>
Date:   Sun Mar 4 15:00:04 2012 -0500

    Fix deletion of least-recently-used external databases.

    The present external database LRU garbage collector mistakenly includes
    SQLite temporary files, including those associated with the internal
    database, as distinct external databases.  This leads to a number of
    problems, including partial deletion of databases and/or their temporary
    files and early deletion of databases before the MAX_EXTERNAL_DATABASES
    limit is reached.  In short, the present code works only, and
    coincidentally, in a single circumstance: when there is an internal
    database and _exactly one_ external database.

    This fixes the above problem by removing SQLite temporary files from the
    list of candidate databases.

    Note, the actual bug here is in the android.app.ContextImpl::databaseList
    method, which return SQLite temporary files as part of a context's
    "database list" instead of hiding them and handling their deletion
    internally.  However, since these methods are part of the Android public
    API and used by third-party apps, the present fix is implemented in
    MediaProvider only.  Should the Context database API be altered, this fix
    will be made redundant but remain unharmful.

    Change-Id: I222255babf02b437d9ab7109a5fb1396bd38a9dd

commit 185447a244717dbe9df236f8cef71b43df50ac4b
Author: Mike Kasick <mike@kasick.org>
Date:   Sat Mar 3 23:23:08 2012 -0500

    Check external storage volume ID to ensure media is actually mounted.

    Programs may request to media scan files (via MediaScannerConnection::scanFile)
    before external storage is mounted.  If that happens, MediaProvider creates
    an external-ffffffff.db (volume ID -1) database once external storage is
    mounted, instead of the one with the expected volume ID.

    Later, if android.process.media is killed and respawned, the real external
    database (that is, the one corresponding to the actual external storage
    volume ID) is attached.  At best, that database contains stale records.
    However, in conjunction with another bug (where the LRU database garbage
    collector prunes all but one external database), most often a new, empty
    database is created.  This results in the sudden disappearance of all
    ringtones and media from programs that depend on the media database.

    Change-Id: Ie0bf72f700430a2744ad20669aed91e22c6d5d07

Change-Id: Icdb72a9f55405cb0dfe01f5db8318efdc539979f