From 0cabc90c2e117dfe2ab1552b562cc2ef046524ab Mon Sep 17 00:00:00 2001 From: qimengp Date: Fri, 22 Jul 2016 14:15:58 +0800 Subject: SnapdragonCamera: Fix the SDCard can not access after format SDCard. Camera app hold SDCard state(SDCard ID). in some case, such as format SDCard, will caues SDCard remounted and SDCard ID changed in system. But camera app does not sync the ID with System, so can not access SDCard. By adding observer and sync SDCard state with system, can fix this issue. CRs-Fixed: 1006496 Change-Id: Id35564ae77944546a26332a412744e9735780560 --- src/com/android/camera/SDCard.java | 43 ++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 9 deletions(-) mode change 100644 => 100755 src/com/android/camera/SDCard.java diff --git a/src/com/android/camera/SDCard.java b/src/com/android/camera/SDCard.java old mode 100644 new mode 100755 index fa532f820..595e9c884 --- a/src/com/android/camera/SDCard.java +++ b/src/com/android/camera/SDCard.java @@ -28,8 +28,10 @@ package com.android.camera; +import android.content.BroadcastReceiver; import android.content.Context; -import android.os.UserHandle; +import android.content.Intent; +import android.content.IntentFilter; import android.os.Environment; import android.os.storage.StorageVolume; import android.os.storage.StorageManager; @@ -42,8 +44,8 @@ public class SDCard { private StorageManager mStorageManager = null; private StorageVolume mVolume = null; - private String path = null; - private String rawpath = null; + private String mPath = null; + private String mRawpath = null; private static SDCard sSDCard; public boolean isWriteable() { @@ -59,20 +61,20 @@ public class SDCard { if (mVolume == null) { return null; } - if (path == null) { - path = mVolume.getPath() + "/DCIM/Camera"; + if (mPath == null) { + mPath = mVolume.getPath() + "/DCIM/Camera"; } - return path; + return mPath; } public String getRawDirectory() { if (mVolume == null) { return null; } - if (rawpath == null) { - rawpath = mVolume.getPath() + "/DCIM/Camera/raw"; + if (mRawpath == null) { + mRawpath = mVolume.getPath() + "/DCIM/Camera/raw"; } - return rawpath; + return mRawpath; } public static void initialize(Context context) { @@ -105,9 +107,32 @@ public class SDCard { try { mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); scanVolumes(); + initVolume(); + registerMediaBroadcastreceiver(context); } catch (Exception e) { Log.e(TAG, "couldn't talk to MountService", e); } } + private void initVolume() { + final StorageVolume[] volumes = mStorageManager.getVolumeList(); + mVolume = (volumes.length > VOLUME_SDCARD_INDEX) ? + volumes[VOLUME_SDCARD_INDEX] : null; + mPath = null; + mRawpath = null; + } + + private void registerMediaBroadcastreceiver(Context context) { + IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED); + filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); + filter.addDataScheme("file"); + context.registerReceiver(mMediaBroadcastReceiver , filter); + } + + private BroadcastReceiver mMediaBroadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + initVolume(); + } + }; } -- cgit v1.2.3