# Print output for @column tags ?>
public
class
RenamingDelegatingContext
extends ContextWrapper
java.lang.Object | |||
↳ | android.content.Context | ||
↳ | android.content.ContextWrapper | ||
↳ | android.test.RenamingDelegatingContext |
This class is deprecated.
New tests should be written using the
Android Testing Support Library.
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).
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
|
String
|
getDatabasePrefix()
|
File
|
getFileStreamPath(String name)
Returns the absolute path on the filesystem where a file created with
|
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)
|
Inherited methods | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.content.ContextWrapper
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
android.content.Context
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
java.lang.Object
|
public RenamingDelegatingContext (Context context, String filePrefix)
Parameters | |
---|---|
context |
Context : : the context that will be delegated. |
filePrefix |
String : : a prefix with which database and file names will be
prefixed. |
public RenamingDelegatingContext (Context context, Context fileContext, String filePrefix)
Parameters | |
---|---|
context |
Context : : the context that will be delegated. |
fileContext |
Context : : the context that file and db methods will be delegated to |
filePrefix |
String : : a prefix with which database and file names will be
prefixed. |
public String[] databaseList ()
Returns an array of strings naming the private databases associated with this Context's application package.
Returns | |
---|---|
String[] |
Array of strings naming the private databases. |
public boolean deleteDatabase (String name)
Delete an existing private SQLiteDatabase associated with this Context's application package.
Parameters | |
---|---|
name |
String : The name (unique in the application package) of the
database. |
Returns | |
---|---|
boolean |
true if the database was successfully deleted; else false . |
public boolean deleteFile (String name)
Delete the given private file associated with this Context's application package.
Parameters | |
---|---|
name |
String : The name of the file to delete; can not contain path
separators. |
Returns | |
---|---|
boolean |
true if the file was successfully deleted; else
false . |
public String[] fileList ()
Returns an array of strings naming the private files associated with this Context's application package.
Returns | |
---|---|
String[] |
Array of strings naming the private files. |
public 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.
Returns | |
---|---|
File |
The path of the directory holding application cache files. |
public File getDatabasePath (String name)
Returns the absolute path on the filesystem where a database created with
openOrCreateDatabase(String, int, SQLiteDatabase.CursorFactory)
is stored.
The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.
Parameters | |
---|---|
name |
String : The name of the database for which you would like to get
its path. |
Returns | |
---|---|
File |
An absolute path to the given database. |
public File getFileStreamPath (String name)
Returns the absolute path on the filesystem where a file created with
openFileOutput(String, int)
is stored.
The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.
Parameters | |
---|---|
name |
String : The name of the file for which you would like to get
its path. |
Returns | |
---|---|
File |
An absolute path to the given file. |
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.
public FileInputStream openFileInput (String name)
Open a private file associated with this Context's application package for reading.
Parameters | |
---|---|
name |
String : The name of the file to open; can not contain path
separators. |
Returns | |
---|---|
FileInputStream |
The resulting FileInputStream . |
Throws | |
---|---|
FileNotFoundException |
public FileOutputStream openFileOutput (String name, int mode)
Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.
No additional permissions are required for the calling app to read or write the returned file.
Parameters | |
---|---|
name |
String : The name of the file to open; can not contain path
separators. |
mode |
int : Operating mode.
Value is either 0 or a combination of Context.MODE_PRIVATE , Context.MODE_WORLD_READABLE , Context.MODE_WORLD_WRITEABLE , and Context.MODE_APPEND |
Returns | |
---|---|
FileOutputStream |
The resulting FileOutputStream . |
Throws | |
---|---|
FileNotFoundException |
public SQLiteDatabase openOrCreateDatabase (String name, int mode, SQLiteDatabase.CursorFactory factory)
Open a new private SQLiteDatabase associated with this Context's application package. Create the database file if it doesn't exist.
Parameters | |
---|---|
name |
String : The name (unique in the application package) of the database. |
mode |
int : Operating mode.
Value is either 0 or a combination of Context.MODE_PRIVATE , Context.MODE_WORLD_READABLE , Context.MODE_WORLD_WRITEABLE , Context.MODE_ENABLE_WRITE_AHEAD_LOGGING , and Context.MODE_NO_LOCALIZED_COLLATORS |
factory |
SQLiteDatabase.CursorFactory : An optional factory class that is called to instantiate a
cursor when query is called. |
Returns | |
---|---|
SQLiteDatabase |
The contents of a newly created database with the given name. |
public SQLiteDatabase openOrCreateDatabase (String name, int mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler)
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 |
String : The name (unique in the application package) of the database. |
mode |
int : Operating mode.
Value is either 0 or a combination of Context.MODE_PRIVATE , Context.MODE_WORLD_READABLE , Context.MODE_WORLD_WRITEABLE , Context.MODE_ENABLE_WRITE_AHEAD_LOGGING , and Context.MODE_NO_LOCALIZED_COLLATORS |
factory |
SQLiteDatabase.CursorFactory : An optional factory class that is called to instantiate a
cursor when query is called. |
errorHandler |
DatabaseErrorHandler : the DatabaseErrorHandler to be used when
sqlite reports database corruption. if null,
DefaultDatabaseErrorHandler is
assumed.
This value may be null . |
Returns | |
---|---|
SQLiteDatabase |
The contents of a newly created database with the given name. |
public static T providerWithRenamedContext (Class<T> contentProvider, Context c, String filePrefix, boolean allowAccessToExistingFilesAndDbs)
Parameters | |
---|---|
contentProvider |
Class |
c |
Context |
filePrefix |
String |
allowAccessToExistingFilesAndDbs |
boolean |
Returns | |
---|---|
T |
Throws | |
---|---|
IllegalAccessException |
|
InstantiationException |
public static T providerWithRenamedContext (Class<T> contentProvider, Context c, String filePrefix)
Parameters | |
---|---|
contentProvider |
Class |
c |
Context |
filePrefix |
String |
Returns | |
---|---|
T |
Throws | |
---|---|
IllegalAccessException |
|
InstantiationException |
Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.
Android 7.0 r1 —