summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers
diff options
context:
space:
mode:
authorZheng Fu <zhengfu@google.com>2014-09-16 14:38:01 -0700
committerZheng Fu <zhengfu@google.com>2014-09-16 16:07:45 -0700
commit240d10d677b4acfeda5aa6e66c2cdea9ae02769b (patch)
treea8a5152486c62cb3f4784b5c54131082f3597faf /src/com/android/providers
parentffe88f9dac723d44107a633a5a36eca18fc7ee5f (diff)
downloadpackages_providers_ContactsProvider-240d10d677b4acfeda5aa6e66c2cdea9ae02769b.zip
packages_providers_ContactsProvider-240d10d677b4acfeda5aa6e66c2cdea9ae02769b.tar.gz
packages_providers_ContactsProvider-240d10d677b4acfeda5aa6e66c2cdea9ae02769b.tar.bz2
synchronize photo storage creation for race conditions.
Several exceptions were reported regarding "Unable to create photo storage directory /data/user/0/com.android.providers.contacts/files/photos". It might caused by the fact that File.makeDirs() is not thread safe. So make it syncrhonized to resolve this issue. Bug:17505392 Bug:17449819 Change-Id: I494204424c024c2166340af609423a669e741761
Diffstat (limited to 'src/com/android/providers')
-rw-r--r--src/com/android/providers/contacts/PhotoStore.java12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/com/android/providers/contacts/PhotoStore.java b/src/com/android/providers/contacts/PhotoStore.java
index e7be48c..79042c4 100644
--- a/src/com/android/providers/contacts/PhotoStore.java
+++ b/src/com/android/providers/contacts/PhotoStore.java
@@ -39,6 +39,8 @@ import java.util.Set;
*/
public class PhotoStore {
+ private static final Object MKDIRS_LOCK = new Object();
+
private final String TAG = PhotoStore.class.getSimpleName();
// Directory name under the root directory for photo storage.
@@ -66,10 +68,12 @@ public class PhotoStore {
*/
public PhotoStore(File rootDirectory, ContactsDatabaseHelper databaseHelper) {
mStorePath = new File(rootDirectory, DIRECTORY);
- if (!mStorePath.exists()) {
- if(!mStorePath.mkdirs()) {
- throw new RuntimeException("Unable to create photo storage directory "
- + mStorePath.getPath());
+ synchronized (MKDIRS_LOCK) {
+ if (!mStorePath.exists()) {
+ if (!mStorePath.mkdirs()) {
+ throw new RuntimeException("Unable to create photo storage directory "
+ + mStorePath.getPath());
+ }
}
}
mDatabaseHelper = databaseHelper;