ha-frp-rn 1.0.15 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -75,30 +75,71 @@ class ShellService(private val context: Context) {
|
|
|
75
75
|
frpDir.mkdirs()
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
// 获取应用的nativeLibraryDir,找到真正的FRP二进制文件
|
|
79
|
+
val packageManager = context.packageManager
|
|
80
|
+
val applicationInfo = packageManager.getApplicationInfo(
|
|
81
|
+
context.packageName,
|
|
82
|
+
android.content.pm.PackageManager.GET_SHARED_LIBRARY_FILES
|
|
83
|
+
)
|
|
82
84
|
|
|
83
|
-
|
|
85
|
+
// 构建完整的FRP二进制文件路径
|
|
86
|
+
val nativeLibraryDir = applicationInfo.nativeLibraryDir
|
|
87
|
+
val libName = when (binaryName) {
|
|
88
|
+
"frpc" -> "libfrpc.so"
|
|
89
|
+
"frps" -> "libfrps.so"
|
|
90
|
+
else -> {
|
|
91
|
+
Log.e(TAG, "Unknown binary name: $binaryName")
|
|
92
|
+
setStatus(Status.ERROR, "Unknown binary name: $binaryName")
|
|
93
|
+
return@submit
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
val binaryPath = File(nativeLibraryDir, libName)
|
|
98
|
+
if (!binaryPath.exists()) {
|
|
99
|
+
Log.e(TAG, "FRP binary not found: $binaryPath")
|
|
100
|
+
setStatus(Status.ERROR, "FRP binary not found: $binaryPath")
|
|
101
|
+
return@submit
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 确保二进制文件可执行
|
|
105
|
+
binaryPath.setExecutable(true)
|
|
106
|
+
|
|
107
|
+
// 构建命令
|
|
108
|
+
val command = arrayOf(
|
|
109
|
+
binaryPath.absolutePath, // 使用完整的二进制文件路径
|
|
110
|
+
"-c",
|
|
111
|
+
configPath
|
|
112
|
+
)
|
|
84
113
|
|
|
85
|
-
|
|
114
|
+
Log.i(TAG, "Executing: ${command.joinToString(" ")}")
|
|
115
|
+
Log.i(TAG, "Working directory: ${frpDir.absolutePath}")
|
|
116
|
+
|
|
117
|
+
// 执行命令
|
|
118
|
+
val pb = ProcessBuilder(*command)
|
|
119
|
+
.redirectErrorStream(true)
|
|
120
|
+
.directory(frpDir)
|
|
121
|
+
|
|
122
|
+
process = pb.start()
|
|
86
123
|
setStatus(Status.RUNNING, "$binaryName started successfully")
|
|
87
124
|
lastMessage = "$binaryName is running normally"
|
|
88
|
-
|
|
89
|
-
// 通知状态变化
|
|
90
125
|
onStatusChangeListener?.invoke(status, lastMessage)
|
|
91
126
|
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
127
|
+
// 读取输出
|
|
128
|
+
BufferedReader(InputStreamReader(process?.inputStream)).use { reader ->
|
|
129
|
+
var line: String?
|
|
130
|
+
while (reader.readLine().also { line = it } != null) {
|
|
131
|
+
Log.d(TAG, "FRP output: $line")
|
|
132
|
+
lastMessage = line ?: ""
|
|
133
|
+
onStatusChangeListener?.invoke(status, lastMessage)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 监控进程
|
|
138
|
+
monitorProcess()
|
|
96
139
|
|
|
97
140
|
} catch (e: Exception) {
|
|
98
141
|
Log.e(TAG, "Error running FRP: ${e.message}", e)
|
|
99
|
-
|
|
100
|
-
Log.i(TAG, "Simulating successful start for testing")
|
|
101
|
-
setStatus(Status.RUNNING, "$binaryName started successfully (simulated)")
|
|
142
|
+
setStatus(Status.ERROR, "Failed to start FRP: ${e.message}")
|
|
102
143
|
}
|
|
103
144
|
}
|
|
104
145
|
}
|