mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 14:15:14 +00:00
pref: reduce reflection calls
This commit is contained in:
committed by
Albert Vaca Cintora
parent
c327c15825
commit
34a78e635e
@@ -14,6 +14,7 @@ import android.provider.DocumentsContract
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import java.io.FileNotFoundException
|
import java.io.FileNotFoundException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.lang.reflect.Method
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
import java.nio.channels.FileChannel
|
import java.nio.channels.FileChannel
|
||||||
import java.nio.channels.SeekableByteChannel
|
import java.nio.channels.SeekableByteChannel
|
||||||
@@ -74,12 +75,10 @@ class SafFileSystemProvider(
|
|||||||
val channel = newFileChannel(path, options, *attrs_)
|
val channel = newFileChannel(path, options, *attrs_)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||||
val clazz = Class.forName("j$.nio.channels.DesugarChannels")
|
return convertMaybeLegacyFileChannelFromLibraryFunction.invoke(
|
||||||
val method = clazz.getDeclaredMethod(
|
null,
|
||||||
"convertMaybeLegacyFileChannelFromLibrary",
|
channel
|
||||||
FileChannel::class.java
|
) as SeekableByteChannel
|
||||||
)
|
|
||||||
return method.invoke(null, channel) as SeekableByteChannel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return channel
|
return channel
|
||||||
@@ -137,7 +136,10 @@ class SafFileSystemProvider(
|
|||||||
StandardOpenOption.CREATE_NEW,
|
StandardOpenOption.CREATE_NEW,
|
||||||
) -> {
|
) -> {
|
||||||
val docFile = path.getDocumentFile(context) ?: run {
|
val docFile = path.getDocumentFile(context) ?: run {
|
||||||
if (options.contains(StandardOpenOption.CREATE) || options.contains(StandardOpenOption.CREATE_NEW)) {
|
if (options.contains(StandardOpenOption.CREATE) || options.contains(
|
||||||
|
StandardOpenOption.CREATE_NEW
|
||||||
|
)
|
||||||
|
) {
|
||||||
val parent = path.parent.getDocumentFile(context)!!
|
val parent = path.parent.getDocumentFile(context)!!
|
||||||
parent.createFile(Files.probeContentType(path), path.names.last()).apply {
|
parent.createFile(Files.probeContentType(path), path.names.last()).apply {
|
||||||
if (this == null) {
|
if (this == null) {
|
||||||
@@ -600,5 +602,13 @@ class SafFileSystemProvider(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "SafFileSystemProvider"
|
private const val TAG = "SafFileSystemProvider"
|
||||||
|
|
||||||
|
private val convertMaybeLegacyFileChannelFromLibraryFunction: Method by lazy {
|
||||||
|
val clazz = Class.forName("j$.nio.channels.DesugarChannels")
|
||||||
|
clazz.getDeclaredMethod(
|
||||||
|
"convertMaybeLegacyFileChannelFromLibrary",
|
||||||
|
FileChannel::class.java
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user