Package com.topjohnwu.superuser.nio
Class FileSystemManager
java.lang.Object
com.topjohnwu.superuser.nio.FileSystemManager
Access file system APIs.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
For use withopenChannel(java.lang.String, int)
: append to end of file while writing.static final int
For use withopenChannel(java.lang.String, int)
: create the file if it doesn't already exist.static final int
For use withopenChannel(java.lang.String, int)
: open the file with read-only access.static final int
For use withopenChannel(java.lang.String, int)
: open the file with read and write access.static final int
For use withopenChannel(java.lang.String, int)
: erase contents of file when opening.static final int
For use withopenChannel(java.lang.String, int)
: open the file with write-only access. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal ExtendedFile
abstract ExtendedFile
abstract ExtendedFile
final ExtendedFile
static FileSystemManager
getLocal()
Get theFileSystemManager
to access the file system of the current local process.static FileSystemManager
getRemote
(IBinder binder) Create aFileSystemManager
to access the file system of a remote process.static Binder
Get the service that exports the file system of the current process over Binder IPC.abstract FileChannel
openChannel
(File file, int mode) Opens a file channel to access the file.final FileChannel
openChannel
(String pathname, int mode) Opens a file channel to access the file.
-
Field Details
-
MODE_READ_ONLY
public static final int MODE_READ_ONLYFor use withopenChannel(java.lang.String, int)
: open the file with read-only access. -
MODE_WRITE_ONLY
public static final int MODE_WRITE_ONLYFor use withopenChannel(java.lang.String, int)
: open the file with write-only access. -
MODE_READ_WRITE
public static final int MODE_READ_WRITEFor use withopenChannel(java.lang.String, int)
: open the file with read and write access. -
MODE_CREATE
public static final int MODE_CREATEFor use withopenChannel(java.lang.String, int)
: create the file if it doesn't already exist. -
MODE_TRUNCATE
public static final int MODE_TRUNCATEFor use withopenChannel(java.lang.String, int)
: erase contents of file when opening. -
MODE_APPEND
public static final int MODE_APPENDFor use withopenChannel(java.lang.String, int)
: append to end of file while writing.
-
-
Constructor Details
-
FileSystemManager
public FileSystemManager()
-
-
Method Details
-
getService
Get the service that exports the file system of the current process over Binder IPC.Sending the
Binder
obtained from this method to a client process enables the current process to perform file system operations on behalf of the client. This allows a client process to access files normally denied by its permissions. This method is usually called in a root process, and the Binder service returned will be send over to a non-root client process.You can pass this
Binder
object in multiple ways, such as returning it in theonBind()
method of root services, passing it around in aBundle
, or returning it in an AIDL interface method. The receiving end will get anIBinder
, which the developer should then pass togetRemote(IBinder)
for usage. -
getLocal
Get theFileSystemManager
to access the file system of the current local process. -
getRemote
Create aFileSystemManager
to access the file system of a remote process.Several APIs are not supported through a remote process:
File.deleteOnExit()
FileChannel.map(FileChannel.MapMode, long, long)
FileChannel.lock()
FileChannel.lock(long, long, boolean)
FileChannel.tryLock()
FileChannel.tryLock(long, long, boolean)
UnsupportedOperationException
.- Parameters:
binder
- a remote proxy of theBinder
obtained fromgetService()
- Throws:
RemoteException
- if the remote process has died.
-
getFile
- See Also:
-
getFile
- See Also:
-
getFile
- See Also:
-
getFile
- See Also:
-
openChannel
@NonNull public final FileChannel openChannel(@NonNull String pathname, int mode) throws IOException Opens a file channel to access the file.- Parameters:
pathname
- the file to be opened.mode
- the desired access mode.- Returns:
- a new FileChannel pointing to the given file.
- Throws:
IOException
- if the given file can not be opened with the requested mode.
-
openChannel
Opens a file channel to access the file.- Parameters:
file
- the file to be opened.mode
- the desired access mode.- Returns:
- a new FileChannel pointing to the given file.
- Throws:
IOException
- if the given file can not be opened with the requested mode.
-