Skip to content

Commit c26c10c

Browse files
committed
Upload file
1 parent d531217 commit c26c10c

2 files changed

Lines changed: 17 additions & 378 deletions

File tree

pio/src/main/java/com/projectkr/shell/SplashActivity.kt

Lines changed: 17 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class SplashActivity : AppCompatActivity() {
223223
fun onLogOutput(log: String) {
224224
handler.post {
225225
synchronized(rows) {
226-
if (rows.size > 6) {
226+
if (rows.size > 4) {
227227
rows.removeAt(0)
228228
ignored = true
229229
}
@@ -243,75 +243,30 @@ class SplashActivity : AppCompatActivity() {
243243
}
244244
}
245245

246-
private class BeforeStartThread(
247-
private var context: Context,
248-
private val config: KrScriptConfig,
249-
private var updateLogViewHandler: UpdateLogViewHandler
250-
) : Thread() {
246+
private class BeforeStartThread(private var context: Context, private val config: KrScriptConfig, private val hasRoot: Boolean, private var updateLogViewHandler: UpdateLogViewHandler) : Thread() {
247+
val params = config.getVariables();
251248

252-
private val params = config.getVariables()
249+
override fun run() {
250+
try {
251+
val process = if (hasRoot) ShellExecutor.getSuperUserRuntime() else ShellExecutor.getRuntime()
252+
if (process != null) {
253+
val outputStream = DataOutputStream(process.outputStream)
253254

254-
override fun run() {
255-
var process: Process? = null
256-
var stdoutThread: Thread? = null
257-
var stderrThread: Thread? = null
255+
ScriptEnvironmen.executeShell(context, outputStream, config.beforeStartSh, params, null, "pio-splash")
258256

259-
try {
260-
process = if (CheckRootStatus.lastCheckResult)
261-
ShellExecutor.getSuperUserRuntime()
262-
else
263-
ShellExecutor.getRuntime()
257+
StreamReadThread(process.inputStream.bufferedReader(), updateLogViewHandler).start()
258+
StreamReadThread(process.errorStream.bufferedReader(), updateLogViewHandler).start()
264259

265-
if (process == null) {
260+
process.waitFor()
261+
updateLogViewHandler.onExit()
262+
} else {
263+
updateLogViewHandler.onExit()
264+
}
265+
} catch (ex: Exception) {
266266
updateLogViewHandler.onExit()
267-
return
268267
}
269-
270-
val outputStream = DataOutputStream(process.outputStream)
271-
272-
// Gửi script vào shell
273-
ScriptEnvironmen.executeShell(
274-
context,
275-
outputStream,
276-
config.beforeStartSh,
277-
params,
278-
null,
279-
"pio-splash"
280-
)
281-
282-
// QUAN TRỌNG: đóng output để tránh treo
283-
outputStream.flush()
284-
outputStream.close()
285-
286-
// Đọc stdout + stderr
287-
stdoutThread = StreamReadThread(
288-
process.inputStream.bufferedReader(),
289-
updateLogViewHandler
290-
).apply { start() }
291-
292-
stderrThread = StreamReadThread(
293-
process.errorStream.bufferedReader(),
294-
updateLogViewHandler
295-
).apply { start() }
296-
297-
// Chờ process kết thúc
298-
process.waitFor()
299-
300-
// Chờ đọc hết log (fix mất 2 dòng cuối)
301-
stdoutThread.join()
302-
stderrThread.join()
303-
304-
} catch (e: Exception) {
305-
e.printStackTrace()
306-
} finally {
307-
try {
308-
process?.destroy()
309-
} catch (_: Exception) {}
310-
311-
updateLogViewHandler.onExit()
312268
}
313269
}
314-
}
315270

316271
private class StreamReadThread(
317272
private val reader: BufferedReader,

0 commit comments

Comments
 (0)