AppDataFileSource


public final class AppDataFileSource
extends OperationSource

java.lang.Object
   ↳ android.os.storage.operations.sources.OperationSource
     ↳ android.os.storage.operations.sources.AppDataFileSource


A source representing a file within the calling application's private app data directory.

This source is restricted to files located inside the application's internal data directory (as returned by Context.getDataDir()).

Operation Rejection

To ensure system security and integrity, operations using an AppDataFileSource will be rejected with FileOperationResult.ERROR_UNSUPPORTED_SOURCE or FileOperationResult.ERROR_INVALID_REQUEST if:

  • The provided path is not absolute.
  • The path contains path traversal elements (e.g., "..") or redundant segments.
  • The path contains unsafe control characters (e.g., null, newline).
  • The file is outside the application's internal data directory (CE or DE storage). Locations such as external storage or system directories are strictly prohibited.

Example Usage:

// Obtain the application's data directory using Context
 Context context = getApplicationContext();
 File myDataFile = new File(context.getDataDir(), "subfolder/my_data.txt");

 // Construct the AppDataFileSource with the File object
 AppDataFileSource source = new AppDataFileSource(myDataFile);

 // The source can now be used in storage operations
 

Summary

Public constructors

AppDataFileSource(File file)

Creates a new source for the specified file.

Public methods

File getFile()

Returns the file associated with this source.

String toString()

Returns a string representation of this source for debugging.

Inherited methods

Public constructors

AppDataFileSource

Added in API level 37
public AppDataFileSource (File file)

Creates a new source for the specified file.

Parameters
file File: The file to be used as a source. Must be within the application's data directory.
This value cannot be null.

Public methods

getFile

Added in API level 37
public File getFile ()

Returns the file associated with this source.

Returns
File This value cannot be null.

toString

Added in API level 37
public String toString ()

Returns a string representation of this source for debugging.

Returns
String A string containing the source type and path.
This value cannot be null.