summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/SDCard.java
diff options
context:
space:
mode:
authorqimengp <qimengp@codeaurora.org>2016-07-22 14:15:58 +0800
committerqimengp <qimengp@codeaurora.org>2016-07-26 12:57:33 +0800
commit22b337406e2c947fecc53a67aaeb6e2e343cfb14 (patch)
tree37796baf0d5e6e6e1abe5c66421863050f37fcea /src/com/android/camera/SDCard.java
parent0b4a800fc0736681e19a6b2dd48174569e0451dc (diff)
downloadandroid_packages_apps_Snap-22b337406e2c947fecc53a67aaeb6e2e343cfb14.tar.gz
android_packages_apps_Snap-22b337406e2c947fecc53a67aaeb6e2e343cfb14.tar.bz2
android_packages_apps_Snap-22b337406e2c947fecc53a67aaeb6e2e343cfb14.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/camera/SDCard.java')
-rwxr-xr-x[-rw-r--r--]src/com/android/camera/SDCard.java47
1 files changed, 34 insertions, 13 deletions
diff --git a/src/com/android/camera/SDCard.java b/src/com/android/camera/SDCard.java
index 8fda17c67..b88e32245 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) {
@@ -92,13 +94,32 @@ public class SDCard {
private SDCard(Context context) {
try {
mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
- final StorageVolume[] volumes = mStorageManager.getVolumeList();
- if (volumes.length > VOLUME_SDCARD_INDEX) {
- mVolume = volumes[VOLUME_SDCARD_INDEX];
- }
+ 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();
+ }
+ };
}