summaryrefslogtreecommitdiffstats
path: root/test-runner
diff options
context:
space:
mode:
authorAndrew Stadler <stadler@android.com>2009-07-23 20:00:08 -0700
committerAndrew Stadler <stadler@android.com>2009-07-24 10:52:21 -0700
commit54a16f059040d8680b71e2e962fb438c993b674b (patch)
tree4a468827b13e14ca3d9345a0f04dbe80aabee822 /test-runner
parent30b06eb8b98b6e6dc685cf65ad4faa25a85008c5 (diff)
downloadframeworks_base-54a16f059040d8680b71e2e962fb438c993b674b.zip
frameworks_base-54a16f059040d8680b71e2e962fb438c993b674b.tar.gz
frameworks_base-54a16f059040d8680b71e2e962fb438c993b674b.tar.bz2
Add getCacheDir() to RenamingDelegatingContext.
This allows providers under ProviderTestCase2 to access getCacheDir().
Diffstat (limited to 'test-runner')
-rw-r--r--test-runner/android/test/RenamingDelegatingContext.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/test-runner/android/test/RenamingDelegatingContext.java b/test-runner/android/test/RenamingDelegatingContext.java
index d780502..0ea43ab 100644
--- a/test-runner/android/test/RenamingDelegatingContext.java
+++ b/test-runner/android/test/RenamingDelegatingContext.java
@@ -6,6 +6,8 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.ContentProvider;
import android.database.sqlite.SQLiteDatabase;
+import android.os.FileUtils;
+import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
@@ -22,6 +24,8 @@ public class RenamingDelegatingContext extends ContextWrapper {
private Context mFileContext;
private String mFilePrefix = null;
+ private File mCacheDir;
+ private final Object mSync = new Object();
private Set<String> mDatabaseNames = Sets.newHashSet();
private Set<String> mFileNames = Sets.newHashSet();
@@ -184,6 +188,32 @@ public class RenamingDelegatingContext extends ContextWrapper {
public String[] fileList() {
return mFileNames.toArray(new String[]{});
}
+
+ /**
+ * In order to support calls to getCacheDir(), we create a temp cache dir (inside the real
+ * one) and return it instead. This code is basically getCacheDir(), except it uses the real
+ * cache dir as the parent directory and creates a test cache dir inside that.
+ */
+ @Override
+ public File getCacheDir() {
+ synchronized (mSync) {
+ if (mCacheDir == null) {
+ mCacheDir = new File(mFileContext.getCacheDir(), renamedFileName("cache"));
+ }
+ if (!mCacheDir.exists()) {
+ if(!mCacheDir.mkdirs()) {
+ Log.w("RenamingDelegatingContext", "Unable to create cache directory");
+ return null;
+ }
+ FileUtils.setPermissions(
+ mCacheDir.getPath(),
+ FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
+ -1, -1);
+ }
+ }
+ return mCacheDir;
+ }
+
// /**
// * Given an array of files returns only those whose names indicate that they belong to this