Commit 011ed722 authored by Mygod's avatar Mygod

Deprecate JniHelper.close

parent 3b614fc6
...@@ -70,7 +70,6 @@ public class JniHelper { ...@@ -70,7 +70,6 @@ public class JniHelper {
private static native Integer getExitValue(Process process); private static native Integer getExitValue(Process process);
private static native Object getExitValueMutex(Process process); private static native Object getExitValueMutex(Process process);
public static native int sendFd(int fd, @NonNull String path); public static native int sendFd(int fd, @NonNull String path);
public static native void close(int fd);
@Nullable @Nullable
public static native byte[] parseNumericAddress(@NonNull String str); public static native byte[] parseNumericAddress(@NonNull String str);
} }
...@@ -27,6 +27,8 @@ import android.content.pm.PackageManager ...@@ -27,6 +27,8 @@ import android.content.pm.PackageManager
import android.net.* import android.net.*
import android.os.Build import android.os.Build
import android.os.ParcelFileDescriptor import android.os.ParcelFileDescriptor
import android.system.ErrnoException
import android.system.Os
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import com.github.shadowsocks.Core import com.github.shadowsocks.Core
import com.github.shadowsocks.JniHelper import com.github.shadowsocks.JniHelper
...@@ -78,15 +80,18 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { ...@@ -78,15 +80,18 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
try { try {
socket.inputStream.read() socket.inputStream.read()
val fd = socket.ancillaryFileDescriptors!!.single()!! val fd = socket.ancillaryFileDescriptors!!.single()!!
val fdInt = getInt.invoke(fd) as Int
socket.outputStream.write(if (try { socket.outputStream.write(if (try {
val network = underlyingNetwork val network = underlyingNetwork
if (network != null && Build.VERSION.SDK_INT >= 23) { if (network != null && Build.VERSION.SDK_INT >= 23) {
network.bindSocket(fd) network.bindSocket(fd)
true true
} else protect(fdInt) } else protect(getInt.invoke(fd) as Int)
} finally { } finally {
JniHelper.close(fdInt) // Trick to close file decriptor try {
Os.close(fd)
} catch (e: ErrnoException) {
printLog(e)
}
}) 0 else 1) }) 0 else 1)
} catch (e: IOException) { } catch (e: IOException) {
printLog(e) printLog(e)
......
...@@ -68,10 +68,6 @@ JNIEXPORT jobject JNICALL ...@@ -68,10 +68,6 @@ JNIEXPORT jobject JNICALL
return env->GetObjectField(process, ProcessImpl_exitValueMutex); return env->GetObjectField(process, ProcessImpl_exitValueMutex);
} }
JNIEXPORT void JNICALL Java_com_github_shadowsocks_JniHelper_close(JNIEnv *env, jobject thiz, jint fd) {
close(fd);
}
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_com_github_shadowsocks_JniHelper_sendFd(JNIEnv *env, jobject thiz, jint tun_fd, jstring path) { Java_com_github_shadowsocks_JniHelper_sendFd(JNIEnv *env, jobject thiz, jint tun_fd, jstring path) {
int fd; int fd;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment