diff options
author | qimengp <qimengp@codeaurora.org> | 2016-07-22 14:15:58 +0800 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2016-08-21 18:46:32 -0700 |
commit | 0cabc90c2e117dfe2ab1552b562cc2ef046524ab (patch) | |
tree | ffbc397747c0df1344ed8872b794c63c7bf702ee /src/com/android | |
parent | 6cb7210f56897248fad69807277a93e8d4345163 (diff) | |
download | android_packages_apps_Snap-0cabc90c2e117dfe2ab1552b562cc2ef046524ab.tar.gz android_packages_apps_Snap-0cabc90c2e117dfe2ab1552b562cc2ef046524ab.tar.bz2 android_packages_apps_Snap-0cabc90c2e117dfe2ab1552b562cc2ef046524ab.zip |
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
Diffstat (limited to 'src/com/android')
-rwxr-xr-x[-rw-r--r--] | src/com/android/camera/SDCard.java | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/com/android/camera/SDCard.java b/src/com/android/camera/SDCard.java index fa532f820..595e9c884 100644..100755 --- 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(); + } + }; } |