Android->providers:fix when restore factory settings,explorer directory is empty
This commit is contained in:
@ -120,6 +120,7 @@ public class MediaProvider extends ContentProvider {
|
||||
private static final Uri ALBUMART_URI = Uri.parse("content://media/external/audio/albumart");
|
||||
private static final int ALBUM_THUMB = 1;
|
||||
private static final int IMAGE_THUMB = 2;
|
||||
private static final int CREATE_DEFAULT_FOLDER = 3;
|
||||
private static class AlbumObj{
|
||||
|
||||
public String match;
|
||||
@ -346,6 +347,7 @@ public class MediaProvider extends ContentProvider {
|
||||
// do nothing if the operation originated from MTP
|
||||
if (mDisableMtpObjectCallbacks) return;
|
||||
|
||||
|
||||
Log.d(TAG, "object removed " + args[0]);
|
||||
IMtpService mtpService = mMtpService;
|
||||
if (mtpService != null) {
|
||||
@ -560,18 +562,38 @@ public class MediaProvider extends ContentProvider {
|
||||
// after she has deleted them.
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
if (prefs.getInt("created_default_folders", 0) == 0) {
|
||||
File f = Environment.getExternalStorageDirectory();
|
||||
Log.v(TAG,"createDefaultFolders 2:"+ f.getAbsolutePath()+","+Environment.getExternalStorageState() +","+f.exists()+","+f.canRead()+","+f.canWrite());
|
||||
boolean createSuccess = true;
|
||||
for (String folderName : sDefaultFolderNames) {
|
||||
File file = Environment.getExternalStoragePublicDirectory(folderName);
|
||||
if (!file.exists()) {
|
||||
Log.v(TAG,"createDefaultFolders 3:"+ file.getAbsolutePath());
|
||||
file.mkdirs();
|
||||
insertDirectory(helper, db, file.getAbsolutePath());
|
||||
|
||||
File file2 = Environment.getExternalStoragePublicDirectory(folderName);
|
||||
createSuccess = createSuccess && file2.exists();
|
||||
Log.v(TAG,"createDefaultFolders 3:"+ file2.exists());
|
||||
}else{
|
||||
Log.v(TAG,"createDefaultFolders 4");
|
||||
}
|
||||
}
|
||||
Log.v(TAG,"createSuccess:"+createSuccess);
|
||||
if(!createSuccess)
|
||||
{
|
||||
detachVolume(Uri.parse("content://media/external"));
|
||||
mHandler.sendEmptyMessageDelayed(CREATE_DEFAULT_FOLDER, 1000);
|
||||
Log.v(TAG,"create fail,delay 1s and try again");
|
||||
}
|
||||
else{
|
||||
Log.v(TAG,"create success");
|
||||
SharedPreferences.Editor e = prefs.edit();
|
||||
e.clear();
|
||||
e.putInt("created_default_folders", 1);
|
||||
e.commit();
|
||||
}
|
||||
|
||||
SharedPreferences.Editor e = prefs.edit();
|
||||
e.clear();
|
||||
e.putInt("created_default_folders", 1);
|
||||
e.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@ -584,6 +606,25 @@ public class MediaProvider extends ContentProvider {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Handler mHandler = new Handler(){
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
// TODO Auto-generated method stub
|
||||
super.handleMessage(msg);
|
||||
if(msg.what == CREATE_DEFAULT_FOLDER){
|
||||
Log.v(TAG," attachVolume(EXTERNAL_VOLUME again");
|
||||
String state = Environment.getExternalStorageState();
|
||||
if (Environment.MEDIA_MOUNTED.equals(state) ||
|
||||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
|
||||
//detachVolume(Uri.parse("content://media/external"));
|
||||
attachVolume(EXTERNAL_VOLUME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
final Context context = getContext();
|
||||
@ -624,6 +665,7 @@ public class MediaProvider extends ContentProvider {
|
||||
|
||||
// open external database if external storage is mounted
|
||||
String state = Environment.getExternalStorageState();
|
||||
Log.v(TAG,"state:"+state);
|
||||
if (Environment.MEDIA_MOUNTED.equals(state) ||
|
||||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
|
||||
attachVolume(EXTERNAL_VOLUME);
|
||||
@ -3555,7 +3597,7 @@ public class MediaProvider extends ContentProvider {
|
||||
|
||||
long rowId;
|
||||
|
||||
if (LOCAL_LOGV) Log.v(TAG, "insertInternal: "+uri+", initValues="+initialValues);
|
||||
//Log.v(TAG, "insertInternal: "+uri+", initValues="+initialValues+",match:"+match);
|
||||
// handle MEDIA_SCANNER before calling getDatabaseForUri()
|
||||
if (match == MEDIA_SCANNER) {
|
||||
mMediaScannerVolume = initialValues.getAsString(MediaStore.MEDIA_SCANNER_VOLUME);
|
||||
@ -5489,6 +5531,7 @@ public class MediaProvider extends ContentProvider {
|
||||
synchronized (sFolderArtMap) {
|
||||
sFolderArtMap.clear();
|
||||
}
|
||||
Log.v(TAG,"attachVolume volume:"+volume);
|
||||
if (Binder.getCallingPid() != Process.myPid()) {
|
||||
throw new SecurityException(
|
||||
"Opening and closing databases not allowed.");
|
||||
@ -5511,9 +5554,9 @@ public class MediaProvider extends ContentProvider {
|
||||
int volumeID = -1;
|
||||
if (LOCAL_LOGV) Log.v(TAG, path + " volume ID: " + volumeID);
|
||||
|
||||
String enableUms= SystemProperties.get("ro.factory.hasUMS","false");
|
||||
String enableUms= SystemProperties.get("ro.factory.hasUMS","false");
|
||||
if ("true".equals(enableUms)) //has UMS,flash partition is the primary storage
|
||||
{
|
||||
{
|
||||
final StorageVolume actualVolume = mStorageManager.getPrimaryVolume();
|
||||
volumeID = -1;//actualVolume.getFatVolumeId();
|
||||
|
||||
@ -5533,15 +5576,14 @@ public class MediaProvider extends ContentProvider {
|
||||
// (missing ioctl), which is also impossible to disambiguate.
|
||||
Log.e(TAG, "Can't obtain external volume ID even though it's mounted,Maybe Ntfs accept it");
|
||||
} else {
|
||||
Log.i(TAG, "External volume is not (yet) mounted, cannot attach.throw exception");
|
||||
Log.i(TAG, "External volume is not (yet) mounted, cannot attach.throw exception");
|
||||
throw new IllegalArgumentException("Can't obtain external volume ID for " +
|
||||
volume + " volume.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else//disable UMS,must be emulated storage
|
||||
{
|
||||
}else//disable UMS,must be emulated storage
|
||||
{
|
||||
//do not check this if merge data and flash partition
|
||||
Log.d(TAG,"----disable UMS,must be emulated storage,do not check volumeID---");
|
||||
|
||||
@ -5622,7 +5664,7 @@ public class MediaProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
mDatabases.put(volume, helper);
|
||||
|
||||
Log.v(TAG,"helper.mInternal:"+helper.mInternal);
|
||||
if (!helper.mInternal) {
|
||||
// create default directories (only happens on first boot)
|
||||
createDefaultFolders(helper, helper.getWritableDatabase());
|
||||
|
||||
Reference in New Issue
Block a user