Check the updated Javadoc and the `example` app for details on how to use the remote file system in the new `nio` module.
### New Features
- Introduce a new module: `nio`
- Includes file system implementations for local and remote processes
- New `FileSystemManager` class to access either local or remote file system implementations
- New `ExtendedFile` class to extend functionality of the old Java `File` API
- [core] New API `Shell.isAppGrantedRoot()` returns a nullable `Boolean`:
-`true` if a root shell has been created
-`false` if it has been determined that root access is impossible to get
-`null` if the library has not, or could not determine the current root grant state. Future invocations of this method may return a non-null value if the library gained more information during shell creation.
- [core] New API `Shell.Builder.setContext(context)`: allow the developer to explicitly provide a `Context` object
- [io] `SuFile` is updated to also extend `ExtendedFile`, which adds some new features and APIs
### Deprecation
- Version `5.0.0` will be the final release of the `busybox` module. If you cannot remove the usage of the module, you can pin the `busybox` module to version `5.0.0`, as it is updated to be fully self contained, making it guaranteed to work with future `libsu` versions.
- Usage of `SuFile`/`SuFileOutputStream`/`SuFileInputStream`/`SuRandomAccessFile` is discouraged. Although these APIs will remain for the foreseeable future, please migrate to use `RootService` + the `nio` module for all root I/O operations.
-`Shell.rootAccess()` is deprecated. Please switch to use the more accurate `Shell.isAppGrantedRoot()` API
- [service] Add new APIs returning `Shell.Task` to allow launching root processes with your `Shell` instance of choice.
- [core] Prevent a possible deadlock
- [core] Support creating `Shell` instances with custom `Process`
- [io] Support setting a `Shell` instance to `SuFile`. This shell will also be used if the `SuFile` is passed to open `SuFileInputStream` and `SuFileOutputStream` streams.
### Behavior Changes
- [service] The way how "Daemon Mode" services work has changed. This change is required to work with multiuser. Please check the Javadoc of `RootService` for instructions on how to launch daemon services and more information about its behavior.
- [core] `Shell.rootAccess()` no longer requires the main shell, so it is now non-blocking. Replaced with a best-effort heuristic that guarantees no false negatives. Please check its Javadoc for more details.
### Breaking Changes
- [core] The core module now requires at least API level 19
- [io] The I/O module now requires at least API level 21
- [io] `SuFileOutputStream.openNoCopy(...)` APIs removed as those are irrelevant on API 21+
- [io] `SuFileInputStream` and `SuFileOutputStream` constructors removed. Please use the corresponding `open(...)` static methods.
- [service] `RootService.attachBaseContext(Context)` is made `final` to prevent breakage. `onAttach(Context)` is provided as an alternative.
### Deprecation
- [core] I have received too many feedback that the `Shell.su/sh(...)` APIs are extremely confusing. Those APIs are now all deprecated, replaced with `Shell.cmd(...)`. `Shell.cmd(...)` is 100% the same as the original `Shell.sh(...)`; the API is just renamed to a less misleading name.
- [service] `RootService.createBindTask(...)`. Replaced with `RootService.bindOrTask(...)`. Will be removed in the next release.
- [service] All `RootService`s of a single app now run in the same root process. Each root service no longer runs in its own separate process.
- [service] The `BroadcastReceiver` used internally for receiving the `IBinder` reference now uses random UUID as action, effectively making it private and unique per-session. This prevents malicious external apps from injecting its own services into your app.
- [busybox] Update the prebuilt BusyBox executable to 1.34.1
- On Android 5.0 and higher (API 21+), both `SuFileInputStream.open(...)` and `SuFileOutputStream.open(...)` return I/O streams backed by FIFO (named pipes). This provides 100% native file I/O stream performance and stability.
- On Android 4.4 and lower, `SuFileInputStream.open(...)` uses the old shell command backed `InputStream` as it was stress tested and proven reliable.
- On Android 4.4 and lower, `SuFileOutputStream.open(...)` will write all data to a temporary file in the application's cache folder, and will only actually output the data to the target location when the stream is closed. Please refer to Javadocs for more detail.
- If the internal copying of `SuFileOutputStream.open(...)` is unacceptable, `SuFileOutputStream.openNoCopy(...)` can be used to force the old implementation (shell command backed `OutputStream`) on Android 4.4 and lower. **However, according to stress test results, this implementation is error prone and I strongly recommend against using it.**
- If your `minSdkVersion` is 21 or higher (which most apps now are), these I/O stream changes basically improve performance and reliability for free without any complexities mentioned above.
- Creating instances of `SuFileInputStream` and `SuFileOutputStream` is deprecated. Please use the static `SuFileInputStream.open(...)` and `SuFileOutputStream.open(...)` methods instead.
-`SuFile` will now follow symbolic links (as it always should)
-`SuFile.length()` will no longer report block total size on block devices (as it shouldn't in the first place)
-`SuFileInputStream` and `SuFileOutputStream` now supports I/O on all file formats, including character files (e.g. files in `/sys` and `/proc`), and also outputs to block devices correctly
-`SuFile` is no longer a wrapper class around `File`. Calling the constructor directly will directly open a shell backed `File` instance. This change is due to the fact that `File` wrapper class causes some issues in methods like `File.renameTo(File)`.
- Introduce new helper methods: `SuFile.open(...)`: depending on whether the global shell has root access or not, these methods will return either a normal `File` instance or `SuFile`. This is the same behavior as the previous `SuFile` constructor (the only difference is that `SuFile` used to wrap around the instance).
- When using high level APIs (`Shell.su`, `Shell.sh`, `Shell.rootAccess()`), `NoShellException` is now silently suppressed to prevent unexpected crashes. Should no shell is possible to be created, `Shell.su/sh` will immediately return a `Shell.Result` with no output and show failure; `Shell.rootAccess()` will simply return `false`.
Starting from this release, `libsu` is modularized into 3 parts: `core`, `io`, and `busybox`.
If you only use the shell implementation, you just need `com.github.topjohnwu.libsu:core`. `com.github.topjohnwu.libsu:io` and `com.github.topjohnwu.libsu:busybox` are optional: include the former to use the I/O wrapper classes, and the latter to bundle the prebuilt busybox binaries with your app. The old `com.github.topjohnwu:libsu` can still be used, but all 3 components will be pulled in.
- Add support for multiple `Shell.Initializer`s: new methods `void Shell.Config.setInitializers(...)` and `void Shell.Config.addInitializers(...)` are added; `void Shell.Config.setInitializer(Initializer.class)` is deprecated.
- Remove the class `BusyBox`. To install the prebuilt busybox, add `com.github.topjohnwu.libsu:busybox` as a dependency, and register `BusyBoxInstaller` as an initializer (`Shell.Config.addInitializers(BusyBoxInstaller.class);`)
- Introduce a new flag: `Shell.FLAG_USE_MAGISK_BUSYBOX`. With this flag set, `/sbin/.magisk/busybox` will be prepended to `PATH`, so the shell will use Magisk's internal busybox.
- When creating `SuFileInputStream`/`SuFileOutputStream`/`SuRandomAccessFile` with a character file, it will throw `FileNotFoundException` instead of failing silently. Character file I/O is not possible with shells, use `Shell.su("cat <chr_file>").exec().getOut()` instead.
- Add `boolean Shell.waitAndClose(long, TimeUnit)` and `void Shell.waitAndClose()`. You can now wait for all tasks to finish before closing the shell instance.
- Add `Shell.Config.setTimeout(long)`. Use it to set the maximum time for waiting a new shell construction. The default value is 20 seconds.
-`Shell.isAlive()` method is updated to get process status directly via reflection rather than the traditional `Process.exitValue()` exception handling. This optimization significantly reduces the overhead when switching between Shell tasks.
- Calling `submit` in `PendingJob` used to end up calling the overridden `exec` instead of `exec` in `JobImpl`. Proxy through a private method in `JobImpl` to prevent changed behavior of `JobImpl` subclasses.
- Even though the parameters of `Shell.Job.add(...)` is labeled `@NonNull`, it is still possible that developers still pass in `null` and cause NPE. Check `null` before proceed any further.
- Fix a bug that constructed shell instances weren't cached in the container when created using fallback methods (e.g. no root -> fallback to non-root shell). This would cause infinite loop when no root is available.