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
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
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
Merge branch 'jb-mr1-release' of https://android.googlesource.com/platform/packages/providers/MediaProvider into HEAD
MediaProvider: get UUID of removable volumes for non-FAT filesystems

Change-Id: I0a66d6c169f3da8fb69af09e543d56df2d84e347
MediaProvider: Allow scan for directories

Patchset 2: Allow only directories of external volumes

Change-Id: I5694f75896749d84b163a1213730eaa4c1e776e6
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Merge "MediaProvider: get UUID of removable volumes for non-FAT filesystems" into cm-10.1
Merge tag 'android-4.3_r2.1' into cm-10.2

Android 4.3 release 2.1
Merge tag 'android-4.4_r1' into cm-11.0

Android 4.4 Release 1.0
Merge tag 'android-4.4.1_r1' into HEAD

Android 4.4.1 Release 1

Conflicts:
	src/com/android/providers/media/MediaProvider.java

Change-Id: I553023304307168e6e6e0cb5a98372cc068659e3
MediaProvider: allow write access to external SD

Without this, Gallery cannot delete photos on external SD.

Change-Id: Ifbebcdb167cca92a5a05158fa4c8b81512b77ba6
mediaprovider: Add theme support to Ringtone activity

Usage:

Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DIALOG_THEME, R.style.CustomDialogTheme); <<< Add your custom dialog theme here
startActivityForResult(intent, 0);

Style Usage:

Define an style that inherits from an android base theme

<style name="CustomDialogThemeDark" parent="@*android:style/Theme.Holo.Dialog.Alert">

or

<style name="CustomDialogThemeLight" parent="@*android:style/Theme.Holo.Light.Dialog.Alert">

or define your own dialog style

Depends on http://review.cyanogenmod.org/#/c/61392

Change-Id: I409eba2674f68386cdd20b74fc3ea42b8e81d111
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Add dummy strings to prevent aapt warnings

Change-Id: I14abbfa886fb5bedb8d03b29c1fe32a7eaf34722
Fix mounting of ext4 formated sdcards

FileUtils.getVolumeUUID(path) doesn't return a uuid for ext4 formated
sdcards. 

Using actualVolume.getUuid()and parsing the returned value works for all
file systems.

Change-Id: I77fe9e09b523bcba68dd2409def68acb715ca33c
Signed-off-by: Dirk Rettschlag <dirk.rettschlag@gmail.com>
Merge "Fix mounting of ext4 formated sdcards" into cm-11.0
Automatic translation import

Change-Id: I2d0a7f37f6e517e57bef12fc42804cc3c774cc8f
Merge tag 'android-4.4.3_r1' into HEAD

Android 4.4.3 release 1
Clean up cursors in try/finally

Make sure we release cursor resources.

Change-Id: Ia122100b1350ae5db4804f8f0e95c49785ab645b
Deactivate the MiniThumbFile when it is not needed.

Issue description:
Unable to use camera after deleting all files in internal storage from PC
with MTP. The toast message "Connect USB storage before using the camera"
is poped up when we launch camera after deleting all files in internal storage
from PC with MTP.

Steps to reproduce the issue:
1. Launch Camera and take a picture.
2. Connect device to PC with MTP mode.
3. Delete all files on Internal stoage from PC.
4. Launch Camera after step 3 finished.
Then we find that we are unable to use camera and the toast message is poped
up.

Root cause:
The .thumbdata3--xxxxx in /sdcard/DCIM/.thumbnails/ is opened in
android.process.media process when we take picture in step 1. But the file is
never closed. So camera cannot create the directories(/sdcard/DCIM/Camera)
it needs to store captured pictures because "Device busy" error.

Solution:
Deactivate the MiniThumbFile when it is not needed.

Change-Id: I0faab5ffd95c5626f7f9ef1bc02b2ae56e2eb19b
Signed-off-by: hanpengx <pengfeix.han@intel.com>
Automatic translation import

Change-Id: I9edf5b5a8cfc2cc35942603b23f48415fde7c6d4