Methods Summary |
---|
public java.lang.String[] | databaseList()
return mDatabaseNames.toArray(new String[]{});
|
public boolean | deleteDatabase(java.lang.String name)
if (mDatabaseNames.contains(name)) {
mDatabaseNames.remove(name);
return mFileContext.deleteDatabase(renamedFileName(name));
} else {
return false;
}
|
public boolean | deleteFile(java.lang.String name)
if (mFileNames.contains(name)) {
mFileNames.remove(name);
return mFileContext.deleteFile(renamedFileName(name));
} else {
return false;
}
|
public java.lang.String[] | fileList()
return mFileNames.toArray(new String[]{});
|
public java.io.File | getCacheDir()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.
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;
|
public java.io.File | getDatabasePath(java.lang.String name)
return mFileContext.getDatabasePath(renamedFileName(name));
|
public java.lang.String | getDatabasePrefix()
return mFilePrefix;
|
public java.io.File | getFileStreamPath(java.lang.String name)
return mFileContext.getFileStreamPath(renamedFileName(name));
|
public void | makeExistingFilesAndDbsAccessible()Makes accessible all files and databases whose names match the filePrefix that was passed to
the constructor. Normally only files and databases that were created through this context are
accessible.
String[] databaseList = mFileContext.databaseList();
for (String diskName : databaseList) {
if (shouldDiskNameBeVisible(diskName)) {
mDatabaseNames.add(publicNameFromDiskName(diskName));
}
}
String[] fileList = mFileContext.fileList();
for (String diskName : fileList) {
if (shouldDiskNameBeVisible(diskName)) {
mFileNames.add(publicNameFromDiskName(diskName));
}
}
|
public java.io.FileInputStream | openFileInput(java.lang.String name)
final String internalName = renamedFileName(name);
if (mFileNames.contains(name)) {
return mFileContext.openFileInput(internalName);
} else {
throw new FileNotFoundException(internalName);
}
|
public java.io.FileOutputStream | openFileOutput(java.lang.String name, int mode)
mFileNames.add(name);
return mFileContext.openFileOutput(renamedFileName(name), mode);
|
public android.database.sqlite.SQLiteDatabase | openOrCreateDatabase(java.lang.String name, int mode, SQLiteDatabase.CursorFactory factory)
final String internalName = renamedFileName(name);
if (!mDatabaseNames.contains(name)) {
mDatabaseNames.add(name);
mFileContext.deleteDatabase(internalName);
}
return mFileContext.openOrCreateDatabase(internalName, mode, factory);
|
public android.database.sqlite.SQLiteDatabase | openOrCreateDatabase(java.lang.String name, int mode, SQLiteDatabase.CursorFactory factory, android.database.DatabaseErrorHandler errorHandler)
final String internalName = renamedFileName(name);
if (!mDatabaseNames.contains(name)) {
mDatabaseNames.add(name);
mFileContext.deleteDatabase(internalName);
}
return mFileContext.openOrCreateDatabase(internalName, mode, factory, errorHandler);
|
public static T | providerWithRenamedContext(java.lang.Class contentProvider, android.content.Context c, java.lang.String filePrefix)
return providerWithRenamedContext(contentProvider, c, filePrefix, false);
|
public static T | providerWithRenamedContext(java.lang.Class contentProvider, android.content.Context c, java.lang.String filePrefix, boolean allowAccessToExistingFilesAndDbs)
Class<T> mProviderClass = contentProvider;
T mProvider = mProviderClass.newInstance();
RenamingDelegatingContext mContext = new RenamingDelegatingContext(c, filePrefix);
if (allowAccessToExistingFilesAndDbs) {
mContext.makeExistingFilesAndDbsAccessible();
}
mProvider.attachInfoForTesting(mContext, null);
return mProvider;
|
java.lang.String | publicNameFromDiskName(java.lang.String diskName)Returns the public name (everything following the prefix) of the given diskName.
if (!shouldDiskNameBeVisible(diskName)) {
throw new IllegalArgumentException("disk file should not be visible: " + diskName);
}
return diskName.substring(mFilePrefix.length(), diskName.length());
|
private java.lang.String | renamedFileName(java.lang.String name)
return mFilePrefix + name;
|
boolean | shouldDiskNameBeVisible(java.lang.String diskName)Returns if the given diskName starts with the given prefix or not.
return diskName.startsWith(mFilePrefix);
|