|
|
@@ -3,6 +3,7 @@ package com.example.modifier.ui.utils
|
|
|
import android.content.Intent
|
|
|
import android.net.Uri
|
|
|
import android.os.Bundle
|
|
|
+import android.os.Environment
|
|
|
import android.util.Log
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
@@ -62,6 +63,7 @@ import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.flow.StateFlow
|
|
|
import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.withContext
|
|
|
+import org.apache.commons.lang3.RandomStringUtils
|
|
|
import java.io.File
|
|
|
|
|
|
class UtilsFragment : Fragment() {
|
|
|
@@ -407,8 +409,11 @@ class UtilsFragment : Fragment() {
|
|
|
|
|
|
job = CoroutineScope(Dispatchers.IO).launch {
|
|
|
try {
|
|
|
- val file = File.createTempFile("files", ".apk")
|
|
|
-
|
|
|
+ val file = File.createTempFile(
|
|
|
+ "temp",
|
|
|
+ ".apk",
|
|
|
+ Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
|
|
+ )
|
|
|
ktorClient.prepareGet(url)
|
|
|
.execute { httpResponse ->
|
|
|
val channel: ByteReadChannel = httpResponse.body()
|
|
|
@@ -428,7 +433,12 @@ class UtilsFragment : Fragment() {
|
|
|
}
|
|
|
}
|
|
|
Log.i(TAG, "A file saved to ${file.path}")
|
|
|
- shellRun("pm install -d -r ${file.path}")
|
|
|
+ val installPath = "/data/local/tmp/${RandomStringUtils.randomAlphabetic(8)}.apk"
|
|
|
+ shellRun(
|
|
|
+ "cp ${file.path} $installPath",
|
|
|
+ "pm install -d -r $installPath",
|
|
|
+ "rm -f $installPath"
|
|
|
+ )
|
|
|
} catch (e: Exception) {
|
|
|
Log.e(TAG, "Failed to download apk", e)
|
|
|
|