Build 1.0_r1(from source)

android.test
Class RenamingDelegatingContext

java.lang.Object
  extended by android.content.Context
      extended by android.content.ContextWrapper
          extended by android.test.RenamingDelegatingContext

public class RenamingDelegatingContext
extends ContextWrapper

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).


Field Summary
 
Fields inherited from class android.content.Context
ACTIVITY_SERVICE, ALARM_SERVICE, AUDIO_SERVICE, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BLUETOOTH_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MODE_APPEND, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NOTIFICATION_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, STATUS_BAR_SERVICE, TELEPHONY_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
 
Constructor Summary
RenamingDelegatingContext(Context context, Context fileContext, String filePrefix)
           
RenamingDelegatingContext(Context context, String filePrefix)
           
 
Method Summary
 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.
 String getDatabasePrefix()
           
 File getFileStreamPath(String name)
          Returns the absolute path on the filesystem where a file created with Context.openFileOutput(java.lang.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.
static
<T extends ContentProvider>
T
providerWithRenamedContext(Class<T> contentProvider, Context c, String filePrefix)
           
static
<T extends ContentProvider>
T
providerWithRenamedContext(Class<T> contentProvider, Context c, String filePrefix, boolean allowAccessToExistingFilesAndDbs)
           
(package private)  String publicNameFromDiskName(String diskName)
          Returns the public name (everything following the prefix) of the given diskName.
(package private)  boolean shouldDiskNameBeVisible(String diskName)
          Returns if the given diskName starts with the given prefix or not.
 
Methods inherited from class android.content.ContextWrapper
attachBaseContext, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createPackageContext, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, getApplicationContext, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getFilesDir, getMainLooper, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSystemService, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, revokeUriPermission, sendBroadcast, sendBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendStickyBroadcast, setTheme, setWallpaper, setWallpaper, startActivity, startInstrumentation, startService, stopService, unbindService, unregisterReceiver
 
Methods inherited from class android.content.Context
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RenamingDelegatingContext

public RenamingDelegatingContext(Context context,
                                 String filePrefix)
Parameters:
context - : the context that will be delagated.
filePrefix - : a prefix with which database and file names will be prefixed.

RenamingDelegatingContext

public RenamingDelegatingContext(Context context,
                                 Context fileContext,
                                 String filePrefix)
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.
Method Detail

providerWithRenamedContext

public static <T extends ContentProvider> T providerWithRenamedContext(Class<T> contentProvider,
                                                                       Context c,
                                                                       String filePrefix)
                                                            throws IllegalAccessException,
                                                                   InstantiationException
Throws:
IllegalAccessException
InstantiationException

providerWithRenamedContext

public static <T extends ContentProvider> T providerWithRenamedContext(Class<T> contentProvider,
                                                                       Context c,
                                                                       String filePrefix,
                                                                       boolean allowAccessToExistingFilesAndDbs)
                                                            throws IllegalAccessException,
                                                                   InstantiationException
Throws:
IllegalAccessException
InstantiationException

makeExistingFilesAndDbsAccessible

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.


shouldDiskNameBeVisible

boolean shouldDiskNameBeVisible(String diskName)
Returns if the given diskName starts with the given prefix or not.

Parameters:
diskName - name of the database/file.

publicNameFromDiskName

String publicNameFromDiskName(String diskName)
Returns the public name (everything following the prefix) of the given diskName.

Parameters:
diskName - name of the database/file.

getDatabasePrefix

public String getDatabasePrefix()

openOrCreateDatabase

public SQLiteDatabase openOrCreateDatabase(String name,
                                           int mode,
                                           SQLiteDatabase.CursorFactory factory)
Description copied from class: Context
Open a new private SQLiteDatabase associated with this Context's application package. Create the database file if it doesn't exist.

Overrides:
openOrCreateDatabase in class ContextWrapper
Parameters:
name - The name (unique in the application package) of the database.
mode - Operating mode. Use 0 or Context.MODE_PRIVATE for the default operation, Context.MODE_WORLD_READABLE and Context.MODE_WORLD_WRITEABLE to control permissions.
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.
See Also:
Context.MODE_PRIVATE, Context.MODE_WORLD_READABLE, Context.MODE_WORLD_WRITEABLE, Context.deleteDatabase(java.lang.String)

deleteDatabase

public boolean deleteDatabase(String name)
Description copied from class: Context
Delete an existing private SQLiteDatabase associated with this Context's application package.

Overrides:
deleteDatabase in class ContextWrapper
Parameters:
name - The name (unique in the application package) of the database.
Returns:
True if the database was successfully deleted; else false.
See Also:
Context.openOrCreateDatabase(java.lang.String, int, android.database.sqlite.SQLiteDatabase.CursorFactory)

databaseList

public String[] databaseList()
Description copied from class: Context
Returns an array of strings naming the private databases associated with this Context's application package.

Overrides:
databaseList in class ContextWrapper
Returns:
Array of strings naming the private databases.
See Also:
Context.openOrCreateDatabase(java.lang.String, int, android.database.sqlite.SQLiteDatabase.CursorFactory), Context.deleteDatabase(java.lang.String)

openFileInput

public FileInputStream openFileInput(String name)
                              throws FileNotFoundException
Description copied from class: Context
Open a private file associated with this Context's application package for reading.

Overrides:
openFileInput in class ContextWrapper
Parameters:
name - The name of the file to open; can not contain path separators.
Returns:
FileInputStream Resulting input stream.
Throws:
FileNotFoundException
See Also:
Context.openFileOutput(java.lang.String, int), Context.fileList(), Context.deleteFile(java.lang.String), FileInputStream.FileInputStream(String)

openFileOutput

public FileOutputStream openFileOutput(String name,
                                       int mode)
                                throws FileNotFoundException
Description copied from class: Context
Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.

Overrides:
openFileOutput in class ContextWrapper
Parameters:
name - The name of the file to open; can not contain path separators.
mode - Operating mode. Use 0 or Context.MODE_PRIVATE for the default operation, Context.MODE_APPEND to append to an existing file, Context.MODE_WORLD_READABLE and Context.MODE_WORLD_WRITEABLE to control permissions.
Returns:
FileOutputStream Resulting output stream.
Throws:
FileNotFoundException
See Also:
Context.MODE_APPEND, Context.MODE_PRIVATE, Context.MODE_WORLD_READABLE, Context.MODE_WORLD_WRITEABLE, Context.openFileInput(java.lang.String), Context.fileList(), Context.deleteFile(java.lang.String), FileOutputStream.FileOutputStream(String)

getFileStreamPath

public File getFileStreamPath(String name)
Description copied from class: Context
Returns the absolute path on the filesystem where a file created with Context.openFileOutput(java.lang.String, int) is stored.

Overrides:
getFileStreamPath in class ContextWrapper
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.
See Also:
Context.openFileOutput(java.lang.String, int), Context.getFilesDir(), Context.getDir(java.lang.String, int)

deleteFile

public boolean deleteFile(String name)
Description copied from class: Context
Delete the given private file associated with this Context's application package.

Overrides:
deleteFile in class ContextWrapper
Parameters:
name - The name of the file to delete; can not contain path separators.
Returns:
True if the file was successfully deleted; else false.
See Also:
Context.openFileInput(java.lang.String), Context.openFileOutput(java.lang.String, int), Context.fileList(), File.delete()

fileList

public String[] fileList()
Description copied from class: Context
Returns an array of strings naming the private files associated with this Context's application package.

Overrides:
fileList in class ContextWrapper
Returns:
Array of strings naming the private files.
See Also:
Context.openFileInput(java.lang.String), Context.openFileOutput(java.lang.String, int), Context.deleteFile(java.lang.String)

Build 1.0_r1(from source)

Please submit a feedback, bug or feature