summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqimengp <qimengp@codeaurora.org>2016-07-22 14:15:58 +0800
committerSteve Kondik <steve@cyngn.com>2016-08-25 21:55:20 -0700
commit5dfb8fb98c0ea10a32fb32059f55f706e8fe5d3b (patch)
tree303f91e3fc99435e053925c5e4fe12989f0b73da
parent5c0697e389cb5f9c9d63ceb53e917169a4716cb2 (diff)
downloadandroid_packages_apps_Snap-5dfb8fb98c0ea10a32fb32059f55f706e8fe5d3b.zip
android_packages_apps_Snap-5dfb8fb98c0ea10a32fb32059f55f706e8fe5d3b.tar.gz
android_packages_apps_Snap-5dfb8fb98c0ea10a32fb32059f55f706e8fe5d3b.tar.bz2
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
-rwxr-xr-x[-rw-r--r--]src/com/android/camera/SDCard.java43
1 files changed, 34 insertions, 9 deletions
diff --git a/src/com/android/camera/SDCard.java b/src/com/android/camera/SDCard.java
index fa532f8..595e9c8 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();
+ }
+ };
}