This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
55 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
app/src/main/kotlin/com/neko/v2ray/service/ProcessService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.neko.v2ray.service | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import com.neko.v2ray.AppConfig.ANG_PACKAGE | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
class ProcessService { | ||
private val TAG = ANG_PACKAGE | ||
private lateinit var process: Process | ||
|
||
fun runProcess(context: Context, cmd: MutableList<String>) { | ||
Log.d(TAG, cmd.toString()) | ||
|
||
try { | ||
val proBuilder = ProcessBuilder(cmd) | ||
proBuilder.redirectErrorStream(true) | ||
process = proBuilder | ||
.directory(context.filesDir) | ||
.start() | ||
|
||
CoroutineScope(Dispatchers.IO).launch { | ||
Thread.sleep(50L) | ||
Log.d(TAG, "runProcess check") | ||
process.waitFor() | ||
Log.d(TAG, "runProcess exited") | ||
} | ||
Log.d(TAG, process.toString()) | ||
|
||
} catch (e: Exception) { | ||
Log.d(TAG, e.toString()) | ||
} | ||
} | ||
|
||
fun stopProcess() { | ||
try { | ||
Log.d(TAG, "runProcess destroy") | ||
process?.destroy() | ||
} catch (e: Exception) { | ||
Log.d(TAG, e.toString()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters