to top
Android APIs
public class

RenamingDelegatingContext

extends ContextWrapper
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.test.RenamingDelegatingContext

Class Overview

This is a class which delegates to the given context, but performs database and file operations with a renamed database/file name (prefixes default names with a given prefix).

Summary

[Expand]
Inherited Constants
From class android.content.Context
Public Constructors
RenamingDelegatingContext(Context context, String filePrefix)
RenamingDelegatingContext(Context context, Context fileContext, String filePrefix)
Public Methods
String[] databaseList()
Returns an array of strings naming the private databases associated with this Context's application package.
boolean deleteDatabase(String name)
Delete an existing private SQLiteDatabase associated with this Context's application package.
boolean deleteFile(String name)
Delete the given private file associated with this Context's application package.
String[] fileList()
Returns an array of strings naming the private files associated with this Context's application package.
File getCacheDir()
In order to support calls to getCacheDir(), we create a temp cache dir (inside the real one) and return it instead.
File getDatabasePath(String name)
Returns the absolute path on the filesystem where a database created with openOrCreateDatabase(String, int, SQLiteDatabase.CursorFactory) is stored.
String getDatabasePrefix()
File getFileStreamPath(String name)
Returns the absolute path on the filesystem where a file created with openFileOutput(String, int) is stored.
void makeExistingFilesAndDbsAccessible()
Makes accessible all files and databases whose names match the filePrefix that was passed to the constructor.
FileInputStream openFileInput(String name)
Open a private file associated with this Context's application package for reading.
FileOutputStream openFileOutput(String name, int mode)
Open a private file associated with this Context's application package for writing.
SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory)
Open a new private SQLiteDatabase associated with this Context's application package.
SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler)
Open a new private SQLiteDatabase associated with this Context's application package.
static <T extends ContentProvider> T providerWithRenamedContext(Class<T> contentProvider, Context c, String filePrefix, boolean allowAccessToExistingFilesAndDbs)
static <T extends ContentProvider> T providerWithRenamedContext(Class<T> contentProvider, Context c, String filePrefix)
[Expand]
Inherited Methods
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object

Public Constructors

public RenamingDelegatingContext (Context context, String filePrefix)

Added in API level 1

Parameters
context : the context that will be delagated.
filePrefix : a prefix with which database and file names will be prefixed.

public RenamingDelegatingContext (Context context, Context fileContext, String filePrefix)

Added in API level 1

Parameters
context : the context that will be delagated.
fileContext : the context that file and db methods will be delgated to
filePrefix : a prefix with which database and file names will be prefixed.

Public Methods

public String[] databaseList ()

Added in API level 1

Returns an array of strings naming the private databases associated with this Context's application package.

Returns
  • Array of strings naming the private databases.

public boolean deleteDatabase (String name)

Added in API level 1

Delete an existing private SQLiteDatabase associated with this Context's application package.

Parameters
name The name (unique in the application package) of the database.
Returns
  • True if the database was successfully deleted; else false.

public boolean deleteFile (String name)

Added in API level 1

Delete the given private file associated with this Context's application package.

Parameters
name The name of the file to delete; can not contain path separators.
Returns
  • True if the file was successfully deleted; else false.

public String[] fileList ()

Added in API level 1

Returns an array of strings naming the private files associated with this Context's application package.

Returns
  • Array of strings naming the private files.

public File getCacheDir ()

Added in API level 1

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.

Returns
  • Returns the path of the directory holding application cache files.

public File getDatabasePath (String name)

Added in API level 1

Returns the absolute path on the filesystem where a database created with openOrCreateDatabase(String, int, SQLiteDatabase.CursorFactory) is stored.

Parameters
name The name of the database for which you would like to get its path.
Returns
  • Returns an absolute path to the given database.

public String getDatabasePrefix ()

Added in API level 1

public File getFileStreamPath (String name)

Added in API level 1

Returns the absolute path on the filesystem where a file created with openFileOutput(String, int) is stored.

Parameters
name The name of the file for which you would like to get its path.
Returns
  • Returns an absolute path to the given file.

public void makeExistingFilesAndDbsAccessible ()

Added in API level 1

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.

public FileInputStream openFileInput (String name)

Added in API level 1

Open a private file associated with this Context's application package for reading.

Parameters
name The name of the file to open; can not contain path separators.
Returns
  • FileInputStream Resulting input stream.

public FileOutputStream openFileOutput (String name, int mode)

Added in API level 1

Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.

Parameters
name The name of the file to open; can not contain path separators.
mode Operating mode. Use 0 or MODE_PRIVATE for the default operation, MODE_APPEND to append to an existing file, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to control permissions.
Returns
  • FileOutputStream Resulting output stream.

public SQLiteDatabase openOrCreateDatabase (String name, int mode, SQLiteDatabase.CursorFactory factory)

Added in API level 1

Open a new private SQLiteDatabase associated with this Context's application package. Create the database file if it doesn't exist.

Parameters
name The name (unique in the application package) of the database.
mode Operating mode. Use 0 or MODE_PRIVATE for the default operation, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to control permissions. Use MODE_ENABLE_WRITE_AHEAD_LOGGING to enable write-ahead logging by default.
factory An optional factory class that is called to instantiate a cursor when query is called.
Returns
  • The contents of a newly created database with the given name.

public SQLiteDatabase openOrCreateDatabase (String name, int mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler)

Added in API level 11

Open a new private SQLiteDatabase associated with this Context's application package. Creates the database file if it doesn't exist.

Accepts input param: a concrete instance of DatabaseErrorHandler to be used to handle corruption when sqlite reports database corruption.

Parameters
name The name (unique in the application package) of the database.
mode Operating mode. Use 0 or MODE_PRIVATE for the default operation, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to control permissions. Use MODE_ENABLE_WRITE_AHEAD_LOGGING to enable write-ahead logging by default.
factory An optional factory class that is called to instantiate a cursor when query is called.
errorHandler the DatabaseErrorHandler to be used when sqlite reports database corruption. if null, DefaultDatabaseErrorHandler is assumed.
Returns
  • The contents of a newly created database with the given name.

public static T providerWithRenamedContext (Class<T> contentProvider, Context c, String filePrefix, boolean allowAccessToExistingFilesAndDbs)

Added in API level 1

public static T providerWithRenamedContext (Class<T> contentProvider, Context c, String filePrefix)

Added in API level 1